Skip to content

Commit 366b85a

Browse files
committed
experimental auto-updating
1 parent 573e56d commit 366b85a

File tree

4 files changed

+4199
-62
lines changed

4 files changed

+4199
-62
lines changed

src/index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
11
'use strict';
22
const electron = require('electron');
3+
const {app, BrowserWindow, Menu, protocol, ipcMain} = require('electron');
34

4-
var fs = require('fs');
5+
const log = require('electron-log');
6+
const {autoUpdater} = require("electron-updater");
7+
8+
autoUpdater.logger = log;
9+
autoUpdater.logger.transports.file.level = 'info';
10+
log.info('App starting...');
11+
12+
function sendStatusToWindow(text) {
13+
log.info(text);
14+
mainWindow.webContents.send('message', text);
15+
}
16+
autoUpdater.on('checking-for-update', () => {
17+
sendStatusToWindow('Checking for update...');
18+
})
19+
autoUpdater.on('update-available', (info) => {
20+
sendStatusToWindow('Update available.');
21+
})
22+
autoUpdater.on('update-not-available', (info) => {
23+
sendStatusToWindow('Update not available.');
24+
})
25+
autoUpdater.on('error', (err) => {
26+
sendStatusToWindow('Error in auto-updater. ' + err);
27+
})
28+
autoUpdater.on('download-progress', (progressObj) => {
29+
let log_message = "Download speed: " + progressObj.bytesPerSecond;
30+
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%';
31+
log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')';
32+
sendStatusToWindow(log_message);
33+
})
34+
autoUpdater.on('update-downloaded', (info) => {
35+
sendStatusToWindow('Update downloaded');
36+
});
537

6-
const app = electron.app;
38+
var fs = require('fs');
739

840
// adds debug features like hotkeys for triggering dev tools and reload
941
require('electron-debug')();
@@ -43,6 +75,7 @@ app.on('activate', () => {
4375

4476
app.on('ready', () => {
4577
mainWindow = createMainWindow();
78+
autoUpdater.checkForUpdatesAndNotify();
4679
});
4780

4881
const ipc = require('electron').ipcMain;

0 commit comments

Comments
 (0)