forked from LINCnil/pia-app
-
Notifications
You must be signed in to change notification settings - Fork 3
/
updater.js
73 lines (59 loc) · 1.87 KB
/
updater.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
const {dialog, BrowserWindow, ipcMain} = require('electron');
const {autoUpdater} = require('electron-updater');
const path = require('path');
const url = require('url');
const log = require('electron-log');
log.transports.file.level = 'info';
autoUpdater.logger = log;
autoUpdater.autoDownload = false;
exports.check = () => {
autoUpdater.checkForUpdates();
autoUpdater.on('update-available', () => {
let downloadProgress = 0;
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of PIA is available. Do you want to update now?',
buttons: ['Update', 'No']
}, (buttonIndex) => {
if(buttonIndex !== 0) return;
autoUpdater.downloadUpdate();
let progressWin = new BrowserWindow({
width: 350,
height: 35,
useContentSize: true,
autoHideMenuBar: true,
maximizable: false,
fullscreen: false,
fullscreenable: false,
resizable: false
});
progressWin.loadURL(url.format({
pathname: path.join(__dirname, 'renderer', 'progress.html'),
protocol: 'file:',
slashes: true
}));
progressWin.on('closed', () => {
progressWin = null
});
ipcMain.on('download-progress-request', (e) => {
e.returnValue = downloadProgress
});
autoUpdater.on('download-progress', (d) => {
console.log(d.percent);
downloadProgress = d.percent
});
autoUpdater.on('update-downloaded', () => {
if (progressWin) progressWin.close();
dialog.showMessageBox({
type: 'info',
title: 'Update ready',
message: 'A new version of PIA is ready. Quit and install now?',
buttons: ['Yes', 'Later']
}, (buttonIndex) => {
if (buttonIndex === 0) autoUpdater.quitAndInstall()
})
})
})
})
};