forked from LINCnil/pia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.js
72 lines (64 loc) · 1.93 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
const { dialog, BrowserWindow } = require("electron");
const { autoUpdater } = require("electron-updater");
const path = require("path");
const url = require("url");
autoUpdater.logger = require("electron-log");
autoUpdater.logger.transports.file.level = "info";
autoUpdater.autoDownload = false;
exports.check = () => {
autoUpdater.checkForUpdates();
autoUpdater.on("update-available", () => {
dialog
.showMessageBox({
type: "info",
title: "Update Available",
message:
"A new version of PIA is available. Do you want to update now?",
buttons: ["Update", "No"]
})
.then(result => {
console.log(result.response);
if (result.response !== 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;
});
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"]
})
.then(result => {
if (result.response === 0) autoUpdater.quitAndInstall();
})
.catch(err => {
console.log(err);
});
});
})
.catch(err => {
console.log(err);
});
});
};