-
Notifications
You must be signed in to change notification settings - Fork 3
/
preload.js
108 lines (106 loc) · 3.27 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const { contextBridge, ipcRenderer } = require("electron")
contextBridge.exposeInMainWorld("utils", {
log: (message) => ipcRenderer.send("log", message),
hashing: {
sha512: (string) => crypto.createHash("sha512").update(string).digest("hex")
},
getRAMAmount: () => ipcRenderer.invoke("get-ram-amount"),
checkForUpdates: () => ipcRenderer.invoke("check-for-updates"),
openInExplorer: (path) => ipcRenderer.invoke("open-in-explorer", path),
})
contextBridge.exposeInMainWorld("ipc", {
on: (channel, listener) => {
ipcRenderer.on(channel, listener)
},
off: (channel, listener=null) => {
if(listener !== null){
ipcRenderer.off(channel, listener)
}else{
ipcRenderer.removeAllListeners(channel)
}
}
})
contextBridge.exposeInMainWorld("controls", {
minimize: () => {
return ipcRenderer.invoke("window:minimize")
},
toggleSize: () => {
return ipcRenderer.invoke("window:toggleSize")
},
close: () => {
return ipcRenderer.invoke("window:close")
},
setProgressBar: value => {
return ipcRenderer.invoke("window:setProgressBar", value)
},
flashFrame: value => {
return ipcRenderer.invoke("window:flashFrame", value)
},
onResize: (callback) => {
return ipcRenderer.on("window:reSize", callback)
},
isMaximized: () => {
return ipcRenderer.invoke("window:isMaximized")
}
})
contextBridge.exposeInMainWorld("dialog", {
showDialog: (options) => {
return ipcRenderer.invoke("dialog:showDialog", options)
},
askLogin: () => {
return ipcRenderer.invoke("dialog:askLogin")
},
askValidate: () => {
return ipcRenderer.invoke("dialog:askValidate")
},
refreshLogin: () => {
return ipcRenderer.invoke("dialog:refreshLogin")
},
logout: () => {
return ipcRenderer.invoke("dialog:logout")
}
})
contextBridge.exposeInMainWorld("mc", {
launchVanilla: (version) => {
return ipcRenderer.invoke("mc:launchVanilla", version)
},
launchModded: (modPack) => {
return ipcRenderer.invoke("mc:launchModded", modPack)
},
sendRunningClients: () => {
return ipcRenderer.invoke("mc:sendRunningClients")
},
killClient: (clientUUID) => {
return ipcRenderer.invoke("mc:killClient", clientUUID)
},
on: (event, callback) => {
ipcRenderer.on(`mc:${event}`,(e, ...args) => callback(...args))
},
off: (event, callback=null) => {
if(callback !== null){
ipcRenderer.off(`mc:${event}`, callback)
}else{
ipcRenderer.removeAllListeners(`mc:${event}`)
}
},
cleanLogs: (modpack) => {
ipcRenderer.invoke("mc:cleanLogs", modpack)
},
uninstallModpack: (modpack) => {
ipcRenderer.invoke("mc:uninstallModpack", modpack)
}
})
contextBridge.exposeInMainWorld("settings", {
get: async (key) => {
return await ipcRenderer.invoke("settings:get", key)
},
set: (key, value) => {
ipcRenderer.invoke("settings:set", key, value)
},
getSync: (key) => {
return ipcRenderer.sendSync("settings:getSync", key)
},
getBulk: async (keys) => {
return await ipcRenderer.invoke("settings:getBulk", keys)
}
})