初始化

This commit is contained in:
24kycj
2026-05-22 19:56:22 +08:00
commit d0c3fd162a
77 changed files with 17058 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import { contextBridge, ipcRenderer } from 'electron'
const channels = {
invoke: [
'dll:init',
'dll:printer-info',
'dll:printer-reset',
'dll:printer-reject',
'dll:printer-error-str',
'dll:job-create',
'dll:job-cancel',
'dll:usb-copy',
'poll:job-start',
'poll:job-stop',
'poll:usb-start',
'poll:usb-stop',
'dialog:open-directory',
'dialog:open-file',
'fs:path-exists',
'config:get',
'config:set',
'shell:open-path',
'dll:reject-available'
] as const,
on: ['job:poll-tick', 'usb:poll-tick'] as const
}
const cardsoonApi = {
invoke(channel: (typeof channels.invoke)[number], ...args: unknown[]) {
if (!(channels.invoke as readonly string[]).includes(channel)) {
throw new Error(`IPC channel not allowed: ${channel}`)
}
return ipcRenderer.invoke(channel, ...args)
},
on(channel: (typeof channels.on)[number], listener: (...args: unknown[]) => void) {
if (!(channels.on as readonly string[]).includes(channel)) {
throw new Error(`IPC event not allowed: ${channel}`)
}
const subscription = (_event: unknown, payload: unknown) => listener(payload)
ipcRenderer.on(channel, subscription)
return () => ipcRenderer.removeListener(channel, subscription)
}
}
contextBridge.exposeInMainWorld('cardsoonApi', cardsoonApi)