-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.js
50 lines (46 loc) · 1.59 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
const ProgressBar = require("electron-progressbar");
const { dialog, app } = require("electron");
const { BrowserWindow } = require("electron/main");
const {autoUpdater} = require("electron-updater")
autoUpdater.checkForUpdates()
autoUpdater.on('update-available', async (ev) =>
{
console.log(ev);
var msg = dialog.showMessageBoxSync(BrowserWindow.getAllWindows()[0], {
message: `Version: ${info.version}. You're running: ${app.getVersion()}`,
title: "An update is available! Do you want to download?",
buttons: ["Yes", "No"],
noLink: true
});
if (msg == 1)
{
autoUpdater.downloadUpdateFromRelease(await autoUpdater.getLatestRelease());
var progressBar = new ProgressBar({
indeterminate: false,
text: 'Preparing data...',
detail: 'Wait...'
});
autoUpdater.on('download-progress', (progressObj) =>
{
let log_message = `Downloaded ${progressObj.percent}%`;
progressBar.value += progressObj.transferred / progressObj.total * 100;
progressBar.detail = log_message;
});
autoUpdater.on('update-downloaded', (info) =>
{
progressBar.close();
autoUpdater.quitAndInstall();
});
autoUpdater.on('error', (err) =>
{
console.log(err);
progressBar.detail = 'Error in auto-updater. ' + err;
progressBar.setCompleted();
progressBar.value = 0;
});
}
});
autoUpdater.on('update-not-available', (info) =>
{
console.log('Update not available.');
});