first commit
This commit is contained in:
1 parent
18d31d5dcf
commit
77a5f5248c
31 files changed
+6637
-30
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { contextBridge, ipcRenderer } from 'electron'
|
||||
import type { ReservationApi } from '../../src/type/reservation'
|
||||
|
||||
type IpcResult<T> = { ok: true; data: T } | { ok: false; error: string }
|
||||
|
||||
async function invoke<T>(channel: string, ...args: unknown[]): Promise<T> {
|
||||
const result = await ipcRenderer.invoke(channel, ...args) as IpcResult<T>
|
||||
if (!result.ok) throw new Error(result.error)
|
||||
return result.data
|
||||
}
|
||||
|
||||
const reservationApi: ReservationApi = {
|
||||
getBranches: () => invoke('reservation:get-branches'),
|
||||
getThemes: (branchNum) => invoke('reservation:get-themes', branchNum),
|
||||
getThemeDetail: (themeInfoNum) => invoke('reservation:get-theme-detail', themeInfoNum),
|
||||
getTimes: (selection) => invoke('reservation:get-times', selection),
|
||||
prepare: (selection) => invoke('reservation:prepare', selection),
|
||||
openCaptcha: (selection) => invoke('reservation:open-captcha', selection),
|
||||
submit: (request) => invoke('reservation:submit', request),
|
||||
startClockMonitor: () => invoke('reservation:clock-start'),
|
||||
stopClockMonitor: () => invoke('reservation:clock-stop'),
|
||||
getClockState: () => invoke('reservation:clock-get'),
|
||||
configureClock: (settings) => invoke('reservation:clock-configure', settings),
|
||||
subscribeClock: (listener) => {
|
||||
const wrapped = (_event: Electron.IpcRendererEvent, estimate: Parameters<typeof listener>[0]) => listener(estimate)
|
||||
ipcRenderer.on('reservation:clock-state', wrapped)
|
||||
return () => ipcRenderer.off('reservation:clock-state', wrapped)
|
||||
},
|
||||
runTimingTest: (request) => invoke('reservation:clock-test', request),
|
||||
armAutoReservation: (config) => invoke('reservation:auto-arm', config),
|
||||
disarmAutoReservation: () => invoke('reservation:auto-disarm'),
|
||||
getAutoReservationState: () => invoke('reservation:auto-get'),
|
||||
subscribeAutoState: (listener) => {
|
||||
const wrapped = (_event: Electron.IpcRendererEvent, state: Parameters<typeof listener>[0]) => listener(state)
|
||||
ipcRenderer.on('reservation:auto-state', wrapped)
|
||||
return () => ipcRenderer.off('reservation:auto-state', wrapped)
|
||||
},
|
||||
}
|
||||
|
||||
contextBridge.exposeInMainWorld('reservationApi', reservationApi)
|
||||
|
||||
window.addEventListener('beforeunload', () => {
|
||||
ipcRenderer.send('reservation:renderer-unload')
|
||||
})
|
||||
Reference in new issue
Block a user