-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
68 lines (62 loc) · 2.09 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
// Preload (Isolated World)
const { contextBridge, ipcRenderer, clipboard } = require('electron');
const { validateURL, getBasicInfo } = require("ytdl-core");
contextBridge.exposeInMainWorld(
'downloader',
{
validateURL,
getBasicInfo,
download: (...args) => ipcRenderer.send("download", ...args),
onPercent: (ev) => { ipcRenderer.on("percent", ev); },
doneDownload: (ev) => { ipcRenderer.on("doneDownload", ev); },
onClipboard: (ev) => { ipcRenderer.on("clipboardChange", ev); },
dialogResponse: (res) => ipcRenderer.send("doneDialogRes", res),
barDeterminate: (func) => { ipcRenderer.on("barIndeterminate", func); },
getFormats: (url) =>
{
return new Promise((resolve, reject) =>
{
ipcRenderer.send("getFormats", url);
ipcRenderer.on("vidFormats", (ev, formats) =>
{
resolve(formats);
});
});
}
}
);
contextBridge.exposeInMainWorld('clipboard', clipboard);
contextBridge.exposeInMainWorld('os', process.platform);
ipcRenderer.on("getHeight", ev =>
{
if (!document.body)
{
document.addEventListener("load", () =>
{
ev.sender.send("resize", document.body.clientHeight - 32);
}, { once: true });
} else
{
ev.sender.send("resize", document.body.clientHeight - 32);
}
});
contextBridge.exposeInMainWorld(
'converter',
{
openVideo: () => { ipcRenderer.send("openVideo"); },
openVideoDirect: (path) => { ipcRenderer.send("openVideo", path); },
onVideoData: (func) =>
{
ipcRenderer.on("gotVideo", (ev, file) =>
{
func(file);
});
},
convertVideo: (url, format) => { ipcRenderer.send("convertVideo", url, format); },
onProgress: (ev) => { ipcRenderer.on("convertProgress", ev); },
onDoneConvert: (ev) => { ipcRenderer.on("convertDone", ev); },
}
);
ipcRenderer.on("openVideo", (ev, data)=>{
ipcRenderer.send("openVideo", data)
})