forked from CringeStudios/element-desktop
Compare commits
1 Commits
develop
...
t3chguy/fi
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0acb44d696 |
@ -32,8 +32,7 @@ const CHANNELS = [
|
|||||||
"seshatReply",
|
"seshatReply",
|
||||||
"setBadgeCount",
|
"setBadgeCount",
|
||||||
"update-downloaded",
|
"update-downloaded",
|
||||||
"userDownloadCompleted",
|
"userDownload",
|
||||||
"userDownloadOpen",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld(
|
contextBridge.exposeInMainWorld(
|
||||||
@ -46,6 +45,13 @@ contextBridge.exposeInMainWorld(
|
|||||||
}
|
}
|
||||||
ipcRenderer.on(channel, listener);
|
ipcRenderer.on(channel, listener);
|
||||||
},
|
},
|
||||||
|
removeListener(channel, listener) {
|
||||||
|
if (!CHANNELS.includes(channel)) {
|
||||||
|
console.error(`Unknown IPC channel ${channel} ignored`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ipcRenderer.removeListener(channel, listener);
|
||||||
|
},
|
||||||
send(channel, ...args) {
|
send(channel, ...args) {
|
||||||
if (!CHANNELS.includes(channel)) {
|
if (!CHANNELS.includes(channel)) {
|
||||||
console.error(`Unknown IPC channel ${channel} ignored`);
|
console.error(`Unknown IPC channel ${channel} ignored`);
|
||||||
|
@ -206,10 +206,6 @@ function onEditableContextMenu(ev, params) {
|
|||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('userDownloadOpen', function(ev, {path}) {
|
|
||||||
shell.openPath(path);
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = (webContents) => {
|
module.exports = (webContents) => {
|
||||||
webContents.on('new-window', onWindowOrNavigate);
|
webContents.on('new-window', onWindowOrNavigate);
|
||||||
webContents.on('will-navigate', (ev, target) => {
|
webContents.on('will-navigate', (ev, target) => {
|
||||||
@ -228,13 +224,60 @@ module.exports = (webContents) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
webContents.session.on('will-download', (event, item) => {
|
webContents.session.on('will-download', (event, item) => {
|
||||||
item.once('done', (event, state) => {
|
let started = false;
|
||||||
if (state === 'completed') {
|
|
||||||
const savePath = item.getSavePath();
|
const ipcHandler = function(ev, {action, path}) {
|
||||||
webContents.send('userDownloadCompleted', {
|
if (path !== item.savePath) return;
|
||||||
path: savePath,
|
|
||||||
name: path.basename(savePath),
|
switch (action) {
|
||||||
|
case "download":
|
||||||
|
shell.openPath(path);
|
||||||
|
ipcMain.off("userDownload", ipcHandler);
|
||||||
|
break;
|
||||||
|
case "pause":
|
||||||
|
item.pause();
|
||||||
|
break;
|
||||||
|
case "resume":
|
||||||
|
item.resume();
|
||||||
|
break;
|
||||||
|
case "cancel":
|
||||||
|
item.cancel();
|
||||||
|
ipcMain.off("userDownload", ipcHandler);
|
||||||
|
break;
|
||||||
|
case "done":
|
||||||
|
ipcMain.off("userDownload", ipcHandler);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ipcMain.on("userDownload", ipcHandler);
|
||||||
|
|
||||||
|
item.on("updated", (event, state) => {
|
||||||
|
if (!item.savePath) return;
|
||||||
|
webContents.send("userDownload", {
|
||||||
|
state,
|
||||||
|
path: item.savePath,
|
||||||
|
name: path.basename(item.savePath),
|
||||||
|
totalBytes: item.getTotalBytes(),
|
||||||
|
receivedBytes: item.getReceivedBytes(),
|
||||||
|
begin: !started,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!started) started = true;
|
||||||
|
});
|
||||||
|
item.once("done", (event, state) => {
|
||||||
|
if (!item.savePath) return;
|
||||||
|
webContents.send("userDownload", {
|
||||||
|
state,
|
||||||
|
path: item.savePath,
|
||||||
|
name: path.basename(item.savePath),
|
||||||
|
totalBytes: item.getTotalBytes(),
|
||||||
|
receivedBytes: item.getReceivedBytes(),
|
||||||
|
terminal: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (state === "interrupted") {
|
||||||
|
ipcMain.off("userDownload", ipcHandler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user