-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
29 lines (27 loc) · 1.04 KB
/
preload.js
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
"use strict";
const { contextBridge,ipcRenderer } = require("electron");
// 要發送渲染端的 js => preload => src\resource\plugin\render => mlc_main
// 要接收渲染端的 mlc_main => preload => src\core\index => 要處理的 js
contextBridge.exposeInMainWorld(
"api", {
// 後端傳送值所屬的頻道 (由前端瀏覽器傳送) - (渲染端 => 主程序)
send: (channel, data) => {
let validChannels = ["toMain"];
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data);
}
},
// 前端接收值所屬的頻道(主程序 => 渲染端)
receive: (channel, func) => {
let validChannels = [
"update_percent",
"update_status",
"software_version",
];
if (validChannels.includes(channel)) {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
}
}
}
);