-
Notifications
You must be signed in to change notification settings - Fork 5
/
appUpdater.js
77 lines (62 loc) · 2.1 KB
/
appUpdater.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
const electron = require('electron');
const os = require('os');
const autoUpdater = electron.autoUpdater;
const log = require('electron-log');
const isDev = require('electron-is-dev');
const UPDATE_SERVER_HOST = "trebuchet-test.appspot-preview.com"
function checkForUpdates(window) {
log.info('checking for updates!');
let app = electron.app;
let BrowserWindow = electron.BrowserWindow;
let ipcMain = electron.ipcMain;
let platform = os.platform();
if (isDev) {
log.info('in local dev mode');
return;
} else {
log.info('in remote mode');
}
if (platform === "linux") return;
const version = app.getVersion();
autoUpdater.addListener("update-available", (event) => {
log.info("A new update is available!");
});
autoUpdater.addListener("update-downloaded", (event, releaseNotes, releaseName, releaseDate, updateURL) => {
let windows = BrowserWindow.getAllWindows();
if (windows.length == 0) {
return;
}
log.info("An update is available.");
log.info("%s\n%s\n%s\n%s", releaseNotes, releaseName, releaseDate, updateURL);
// send a message to the main window, asking the user if they want to install the update
windows[0].webContents.send("updateAvailable", {
releaseName,
releaseDate,
releaseNotes
});
return true;
});
// raised when the renderer process tells us to install the update
electron.ipcMain.on('installUpdate', (event) => {
log.info("Installing update and quitting.");
autoUpdater.quitAndInstall();
});
autoUpdater.addListener("error", (err) => {
log.error(err);
});
autoUpdater.addListener("checking-for-update", (event) => {
log.info("checking-for-update");
});
autoUpdater.addListener("update-not-available", () => {
log.info("update-not-available");
});
window.webContents.once("did-frame-finish-load", (event) => {
log.info('checking for updates ...');
autoUpdater.checkForUpdates();
});
let url = `https://${UPDATE_SERVER_HOST}/update/${platform}_${os.arch()}/${version}`;
autoUpdater.setFeedURL(url);
}
module.exports = {
checkForUpdates: checkForUpdates
}