forked from mrwill84/DOClever
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
executable file
·34 lines (34 loc) · 1.3 KB
/
plugin.js
File metadata and controls
executable file
·34 lines (34 loc) · 1.3 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
var path=require("path");
var ipc=require("electron").ipcMain;
var fs=require("fs-extra");
function Plugin(electron) {
this.download=async function (id,userId,pluginId,url) {
let webContent=electron.mainWindow.webContents;
let mainWindow=electron.mainWindow;
let p=path.join(global.pathEnv,id,"plugin",userId,pluginId);
if(!(await fs.exists(p)))
{
await fs.mkdir(p)
}
return new Promise(function (resolve,reject) {
webContent.session.on('will-download', (e, item) => {
const totalBytes = item.getTotalBytes();
const filePath = path.join(global.pathEnv,id,"plugin",userId,pluginId,item.getFilename());
item.setSavePath(filePath);
item.on('done', (e, state) => {
if (!mainWindow.isDestroyed()) {
mainWindow.setProgressBar(-1);
}
if (state === 'interrupted') {
reject("下载没有完成!");
}
if (state === 'completed') {
resolve(filePath);
}
});
});
webContent.downloadURL(url);
})
}
}
module.exports=Plugin;