-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpreload.js
65 lines (63 loc) · 2.29 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
const { contextBridge, ipcRenderer } = require("electron")
const path = require("path")
contextBridge.exposeInMainWorld("utils", {
path: {
join: (...args) => path.join(...args)
},
openExternal: (url) => ipcRenderer.invoke("openExternal", url)
})
contextBridge.exposeInMainWorld("ipc", {
debug: {on: (channel, listener) => {
ipcRenderer.on(`debug:${channel}`, listener)
}},
update: {onInfo: listener => {
ipcRenderer.on("update:info", listener)
}}
})
contextBridge.exposeInMainWorld("controls", {
minimize: callback => {
ipcRenderer.invoke("window:minimize").then(callback)
},
close: callback => {
ipcRenderer.invoke("window:close").then(callback)
},
setProgressBar: value => {
ipcRenderer.invoke("window:setProgressBar", value).then()
},
flashFrame: value => {
ipcRenderer.invoke("window:flashFrame", value).then()
}
})
contextBridge.exposeInMainWorld("dialog", {
on: (channel, listener) => {
ipcRenderer.on(`dialog:${channel}`, listener)
},
showDialog: (options, resp, callback=_ => {}) => {
let responder = `dialog:showDialogResponse:${resp}`
ipcRenderer.invoke("dialog:showDialog", responder, options).then(_ => {callback(responder)})
}
})
contextBridge.exposeInMainWorld("downloader", {
on: (channel, listener) => {
ipcRenderer.on(`downloader:${channel}`, listener)
},
getInfo: (url, callback=_ => {}) => {
let responder = "downloader:returnInfo"
ipcRenderer.invoke("downloader:getInfo", responder, url).then(_ => {callback(responder)})
},
startDownload: (playlist, url, format, container, target, fileType, metadata, thumbnail) => {
ipcRenderer.invoke("downloader:startDownload", playlist, url, format, container, target, fileType, metadata, thumbnail).then()
},
killDownload: _ => {
ipcRenderer.invoke("downloader:kill").then()
}
})
contextBridge.exposeInMainWorld("progressBar", {
on: (channel, listener) => {
ipcRenderer.on(`progress-bar:${channel}`, listener)
},
create: (title, max, min, options = {}) =>
ipcRenderer.invoke("progress-bar:create", title, max, min, options),
provide: (id, call, value) =>
ipcRenderer.invoke(`progress-bar:${call}:on-${id}`, value)
})