-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.js
74 lines (71 loc) · 2.1 KB
/
progress.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
const { sleep } = require("asyncbox");
const { screen, ipcMain } = require("electron");
const { BrowserWindow } = require('glasstron');
class Progress {
constructor() {
}
async init(app) {
this.app = app;
this.shown = false;
this.progressing = false;
this.window = new BrowserWindow({
width: 450,
height: 0,
minimizable: false,
maximizable: false,
alwaysOnTop: true,
movable: false,
resizable: false,
show: false,
titleBarStyle: 'hidden',
frame: false,
transparent: true,
backgroundColor: '#0000FFE0',
webPreferences: {
nodeIntegration: true,
experimentalFeatures: true
}
});
this.window.blurType = "acrylic";
this.window.setBlur(true);
this.window.setSkipTaskbar(true);
this.window.menuBarVisible = false;
ipcMain.on('progress', async (event, data) => {
if (data.type === 'resize') {
const size = data.size;
const contains = screen.getPrimaryDisplay().workAreaSize;
this.window.setBounds({ width: size.width, height: size.height, x: contains.width - size.width - 8, y: contains.height - size.height - 8 });
this.window.showInactive();
this.window.moveTop();
this.progressing = false;
}
})
await this.window.loadFile(`windows/progress.html`);
}
async show(title, tip) {
this.shown = true;
this.progressing = true;
this.title = title || '';
this.tip = tip || '';
this.window.setBounds({ height: 0 });
this.window.webContents.send('progress', { type: 'progress', title: this.title, progress: 0, tip: this.tip });
while(this.progressing) {
await sleep(100);
}
}
async update(progress, tip) {
if (this.shown) {
this.progressing = true;
this.tip = typeof tip === 'undefined' ? this.tip : tip;
this.window.webContents.send('progress', { type: 'progress', title: this.title, progress, tip: this.tip });
while(this.progressing) {
await sleep(100);
}
}
}
close() {
this.shown = false;
this.window.hide();
}
}
module.exports = Progress;