You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.1 KiB

//预加载脚本
//绑定在主进程,跑在渲染进程
//只能获取部分Node的API
console.log('preload') //在日志里打印preload
const {contextBridge,ipcRenderer} = require('electron');
//引入electron且调用contextBridge桥梁模块
//ipcRenderer为调用通信模块(渲染进程)
contextBridge.exposeInMainWorld('myAPI',{
saveFile:(data)=>{
ipcRenderer.send('file-save',data) //发送参数 send<->on
},
readFile(){
return ipcRenderer.invoke('file-read') //读取并发送参数 invoke<->handle
},
closeWindow() {
ipcRenderer.send('close-main-window');
},
fullScreen() {
ipcRenderer.send('toggle-full-screen');
},
openTodolist() {
ipcRenderer.send('open-todolist')
},
minimizeWin() {
ipcRenderer.send('minimize-window')
},
newDiary() {
ipcRenderer.send('new-diary')
},
openClass() {
ipcRenderer.send('open-class-img')
}
})
//定义一个key并且调用node的version版本api
//saveFile为写入文件
//reaFile为写入文件