Repository navigation
Expand file tree
/
Copy pathpreload.js
More file actions
46 lines (43 loc) · 2.22 KB
/
Copy pathpreload.js
File metadata and controls
46 lines (43 loc) · 2.22 KB
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
41
42
43
44
45
46
const { contextBridge, ipcRenderer, webUtils } = require("electron");
const launcherAPI = {
minimizeWindow: () => ipcRenderer.invoke("window:minimize"),
maximizeWindow: () => ipcRenderer.invoke("window:maximize"),
closeWindow: () => ipcRenderer.invoke("window:close"),
setCloseToTray: (enabled) => ipcRenderer.invoke("window:setCloseToTray", enabled),
getStartupOnBoot: () => ipcRenderer.invoke("app:getStartupOnBoot"),
setStartupOnBoot: (enabled) => ipcRenderer.invoke("app:setStartupOnBoot", enabled),
setGlobalHotkey: (accelerator) => ipcRenderer.invoke("app:setGlobalHotkey", accelerator),
quitApp: () => ipcRenderer.invoke("app:quit"),
openTarget: (target) => ipcRenderer.invoke("target:open", target),
validateLocalPath: (targetPath) => ipcRenderer.invoke("target:validateLocalPath", targetPath),
browseExecutable: () => ipcRenderer.invoke("target:browseExecutable"),
browseFolder: () => ipcRenderer.invoke("target:browseFolder"),
extractIcon: (exePath) => ipcRenderer.invoke("icon:extract", exePath),
getDroppedFilePath: (file) => {
try {
if (!file) {
return "";
}
return webUtils.getPathForFile(file) || "";
} catch {
return "";
}
},
registerHotkey: (appData) => ipcRenderer.invoke("hotkey:register", appData),
unregisterHotkey: (hotkey) => ipcRenderer.invoke("hotkey:unregister", hotkey),
onLaunchAppByHotkey: (callback) => {
if (typeof callback !== "function") {
return () => {};
}
const listener = (_event, appData) => callback(appData);
ipcRenderer.on("launch-app-by-hotkey", listener);
return () => ipcRenderer.removeListener("launch-app-by-hotkey", listener);
},
loadConfig: () => ipcRenderer.invoke("config:load"),
saveConfig: (json) => ipcRenderer.invoke("config:save", json),
exportConfig: (json) => ipcRenderer.invoke("config:export", json),
importConfig: () => ipcRenderer.invoke("config:import"),
listConfigBackups: () => ipcRenderer.invoke("config:listBackups"),
loadConfigBackup: (filename) => ipcRenderer.invoke("config:loadBackup", filename)
};
contextBridge.exposeInMainWorld("launcherAPI", launcherAPI);