-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.js
80 lines (55 loc) · 2.2 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
74
75
76
77
78
79
80
const {autoUpdater} = require("electron-updater");
const {dialog, BrowserWindow, ipcMain} = require("electron");
autoUpdater.logger = require("electron-log");
autoUpdater.logger.transports.file.level = "info";
autoUpdater.autoDownload = false;
exports.check = () => {
console.log("checking for updaters");
autoUpdater.checkForUpdates();
autoUpdater.on("update-available", () => {
let downloadProgress = 0;
dialog.showMessageBox({
type:"info",
title:"Update Available",
message:"A New Version Of SyncMessage Is Available, Would You Like To Download It?",
buttons: ["Update", "No"]
}, (buttonIndex) => {
if (buttonIndex !== 0) {
return;
}
autoUpdater.downloadUpdate();
let progressWin = new BrowserWindow({
width: 300,
height: 200,
useContentSize: true,
autoHideMenuBar: true,
maximizable: false,
fullscreen: false,
fullscreenable: false,
resizable: false,
})
progressWin.loadURL(`file://${__dirname}/renderer/progress.html`)
progressWin.on("close", () => {
progressWin = null;
})
ipcMain.on("download-progress-request", (e) => {
e.returnValue = downloadProgress;
})
autoUpdater.on('download-progress', (progressObj) => {
autoUpdater.logger.info("percentage " + progressObj.percent);
})
// Listening for completion
autoUpdater.on("update-downloaded", () => {
if (progressWin) {progressWin.close()}
dialog.showMessageBox({
type:"info",
title:"Update Ready",
message:"Update Is Ready, Would You Like To Install And Restart SyncMesssage Now?",
buttons: ["Yes", "Later"]
}, (buttonIndex) => {
if (buttonIndex === 0) {autoUpdater.quitAndInstall()}
})
})
})
})
}