mirror of
https://github.com/Andre-Bzk/twitch4steamdeck.git
synced 2026-11-15 15:43:08 +01:00
Projektstart
- Phase 1 "Twitch Login" abgeschlossen
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'
|
||||
|
||||
const IPC = {
|
||||
authStatus: 'auth:get-status',
|
||||
authStart: 'auth:start-device-flow',
|
||||
authCancel: 'auth:cancel',
|
||||
authLogout: 'auth:logout',
|
||||
authConfigured: 'auth:is-configured',
|
||||
authEvent: 'auth:event'
|
||||
} as const
|
||||
|
||||
export type AuthStatus = 'logged-out' | 'logged-in'
|
||||
|
||||
export interface DeviceFlowStartInfo {
|
||||
userCode: string
|
||||
verificationUri: string
|
||||
expiresInSec: number
|
||||
}
|
||||
|
||||
export type AuthEvent =
|
||||
| { kind: 'authorized' }
|
||||
| { kind: 'denied' }
|
||||
| { kind: 'expired' }
|
||||
| { kind: 'cancelled' }
|
||||
| { kind: 'error'; message: string }
|
||||
|
||||
const api = {
|
||||
appVersion: process.env.npm_package_version ?? '0.0.0',
|
||||
auth: {
|
||||
isConfigured: (): Promise<boolean> => ipcRenderer.invoke(IPC.authConfigured),
|
||||
getStatus: (): Promise<AuthStatus> => ipcRenderer.invoke(IPC.authStatus),
|
||||
startDeviceFlow: (): Promise<DeviceFlowStartInfo> => ipcRenderer.invoke(IPC.authStart),
|
||||
cancel: (): Promise<void> => ipcRenderer.invoke(IPC.authCancel),
|
||||
logout: (): Promise<void> => ipcRenderer.invoke(IPC.authLogout),
|
||||
onEvent: (cb: (event: AuthEvent) => void): (() => void) => {
|
||||
const listener = (_e: IpcRendererEvent, event: AuthEvent): void => cb(event)
|
||||
ipcRenderer.on(IPC.authEvent, listener)
|
||||
return () => ipcRenderer.removeListener(IPC.authEvent, listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('t4sd', api)
|
||||
|
||||
export type T4sdApi = typeof api
|
||||
Reference in New Issue
Block a user