From 8771cbf44aa3df4260a1ab19f5a373a2b28fb6f5 Mon Sep 17 00:00:00 2001 From: pm9etfw54 <2983150050@qq.com> Date: Sat, 12 Oct 2024 23:37:53 +0800 Subject: [PATCH] ADD file via upload --- preload.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 preload.js diff --git a/preload.js b/preload.js new file mode 100644 index 0000000..01eb740 --- /dev/null +++ b/preload.js @@ -0,0 +1,39 @@ +//预加载脚本 +//绑定在主进程,跑在渲染进程 +//只能获取部分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为写入文件