Files
tennis-book/src/preload/index.ts
2026-07-15 20:09:02 +08:00

46 lines
2.0 KiB
TypeScript

import { contextBridge, ipcRenderer } from 'electron'
import {
IPC_CHANNELS,
type AvailabilityQuery,
type CancelBookingInput,
type CreateBookingInput,
type CreateMonitorTaskInput,
type TennisBookApi,
type UpdateCourtSettingsInput
} from '../shared/contracts'
const api: TennisBookApi = {
listCourts: () => ipcRenderer.invoke(IPC_CHANNELS.listCourts),
getAvailability: (query: AvailabilityQuery) =>
ipcRenderer.invoke(IPC_CHANNELS.getAvailability, query),
getCourtSettings: (courtId: string) =>
ipcRenderer.invoke(IPC_CHANNELS.getCourtSettings, courtId),
updateCourtSettings: (input: UpdateCourtSettingsInput) =>
ipcRenderer.invoke(IPC_CHANNELS.updateCourtSettings, input),
createBooking: (input: CreateBookingInput) =>
ipcRenderer.invoke(IPC_CHANNELS.createBooking, input),
cancelBooking: (input: CancelBookingInput) =>
ipcRenderer.invoke(IPC_CHANNELS.cancelBooking, input),
getPendingBooking: (courtId: string) =>
ipcRenderer.invoke(IPC_CHANNELS.getPendingBooking, courtId),
listMonitorTasks: () => ipcRenderer.invoke(IPC_CHANNELS.listMonitorTasks),
getMonitorTaskDetail: (taskId: string) =>
ipcRenderer.invoke(IPC_CHANNELS.getMonitorTaskDetail, taskId),
createMonitorTask: (input: CreateMonitorTaskInput) =>
ipcRenderer.invoke(IPC_CHANNELS.createMonitorTask, input),
setMonitorTaskEnabled: (taskId: string, enabled: boolean) =>
ipcRenderer.invoke(IPC_CHANNELS.setMonitorTaskEnabled, taskId, enabled),
setMonitorTaskAutoBooking: (taskId: string, enabled: boolean) =>
ipcRenderer.invoke(IPC_CHANNELS.setMonitorTaskAutoBooking, taskId, enabled),
deleteMonitorTask: (taskId: string) =>
ipcRenderer.invoke(IPC_CHANNELS.deleteMonitorTask, taskId),
takeMonitorAlerts: () => ipcRenderer.invoke(IPC_CHANNELS.takeMonitorAlerts),
onMonitorAlert: (listener: () => void) => {
const handler = () => listener()
ipcRenderer.on(IPC_CHANNELS.monitorAlert, handler)
return () => ipcRenderer.removeListener(IPC_CHANNELS.monitorAlert, handler)
}
}
contextBridge.exposeInMainWorld('tennisBook', api)