-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
33 lines (30 loc) · 1.83 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
30
31
32
33
const {contextBridge, ipcRenderer} = require("electron");
contextBridge.exposeInMainWorld(
"api", {
darkModeChanged : callback => ipcRenderer.on("Tasmocontrol::darkMode", (_, useDarkMode) => callback(useDarkMode)),
refreshSearch : () => {
ipcRenderer.send("DeviceStore::search");
},
searchUpdated : callback => ipcRenderer.on("DeviceStore::updated", (_, devices) => callback(devices)),
configUpdated : callback => ipcRenderer.on("ConfigService::changed", (_, config) => callback(config)),
configRequest : () => ipcRenderer.send("ConfigService::request"),
configSet : (key, value) => {
ipcRenderer.send("ConfigService::set", [key, value]);
},
discoveryComplete : callback => ipcRenderer.on("DeviceStore::discoveryComplete", () => callback()),
deviceRequestAll : () => ipcRenderer.send("DeviceStore::all"),
deviceRequest : ip => ipcRenderer.send("DeviceStore::single", ip),
deviceReceive : callback => ipcRenderer.on("DeviceStore::device", (_, device) => callback(device)),
commandSend : (ip, command, payload) => ipcRenderer.send("CommandService::send", [ip, command, payload]),
commandImmediate : async (ip, command) => ipcRenderer.invoke("CommandService::sendImmediate", [ip, command]),
windowMinMax : () => ipcRenderer.send("MainWindow::minMax")
}
);
contextBridge.exposeInMainWorld("devices", {
requestAll : () => ipcRenderer.send("DeviceStore::all"),
deployTheme : (devices, theme) => ipcRenderer.send("DeviceStore::themeUpdate", [devices, theme])
});
contextBridge.exposeInMainWorld("network", {
interfaces : () => ipcRenderer.send("NetworkService::interfaces"),
interfaceUpdate : callback => ipcRenderer.on("NetworkService::interfacesReply", (_, ifaces) => callback(ifaces))
});