forked from LLOneBot/LLOneBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.ts
40 lines (37 loc) · 1.11 KB
/
preload.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { CheckVersion, Config } from './common/types'
import {
CHANNEL_ERROR,
CHANNEL_GET_CONFIG,
CHANNEL_LOG,
CHANNEL_CHECK_VERSION,
CHANNEL_SELECT_FILE,
CHANNEL_SET_CONFIG,
CHANNEL_UPDATE,
} from './common/channels'
import { contextBridge, ipcRenderer } from 'electron'
const llonebot = {
log: (data: unknown) => {
ipcRenderer.send(CHANNEL_LOG, data)
},
checkVersion: async (): Promise<CheckVersion> => {
return ipcRenderer.invoke(CHANNEL_CHECK_VERSION)
},
updateLLOneBot: async (): Promise<boolean> => {
return ipcRenderer.invoke(CHANNEL_UPDATE)
},
setConfig: async (ask: boolean, config: Config) => {
return ipcRenderer.invoke(CHANNEL_SET_CONFIG, ask, config)
},
getConfig: async (): Promise<Config> => {
return ipcRenderer.invoke(CHANNEL_GET_CONFIG)
},
getError: async (): Promise<string> => {
return ipcRenderer.invoke(CHANNEL_ERROR)
},
selectFile: (): Promise<string> => {
return ipcRenderer.invoke(CHANNEL_SELECT_FILE)
},
}
export type LLOneBot = typeof llonebot
// 在window对象下导出只读对象
contextBridge.exposeInMainWorld('llonebot', llonebot)