aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron/ipc-api/autoUpdate.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/electron/ipc-api/autoUpdate.js')
-rw-r--r--src/electron/ipc-api/autoUpdate.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/electron/ipc-api/autoUpdate.js b/src/electron/ipc-api/autoUpdate.js
new file mode 100644
index 000000000..7bc193e2d
--- /dev/null
+++ b/src/electron/ipc-api/autoUpdate.js
@@ -0,0 +1,54 @@
1import { app, ipcMain } from 'electron';
2import { autoUpdater } from 'electron-updater';
3
4export default (params) => {
5 if (process.platform === 'darwin' || process.platform === 'win32') {
6 // autoUpdater.setFeedURL(updateUrl);
7 ipcMain.on('autoUpdate', (event, args) => {
8 try {
9 autoUpdater.allowPrerelease = Boolean(params.settings.get('beta'));
10 if (args.action === 'check') {
11 autoUpdater.checkForUpdates();
12 } else if (args.action === 'install') {
13 console.log('install update');
14 autoUpdater.quitAndInstall();
15 // we need to send a quit event
16 setTimeout(() => {
17 app.quit();
18 }, 20);
19 }
20 } catch (e) {
21 console.error(e);
22 event.sender.send('autoUpdate', { error: true });
23 }
24 });
25
26 autoUpdater.on('update-not-available', () => {
27 console.log('update-not-available');
28 params.mainWindow.webContents.send('autoUpdate', { available: false });
29 });
30
31 autoUpdater.on('update-available', () => {
32 console.log('update-available');
33 params.mainWindow.webContents.send('autoUpdate', { available: true });
34 });
35
36 autoUpdater.on('download-progress', (progressObj) => {
37 let logMessage = `Download speed: ${progressObj.bytesPerSecond}`;
38 logMessage = `${logMessage} - Downloaded ${progressObj.percent}%`;
39 logMessage = `${logMessage} (${progressObj.transferred}/${progressObj.total})`;
40
41 console.log(logMessage);
42 });
43
44 autoUpdater.on('update-downloaded', () => {
45 console.log('update-downloaded');
46 params.mainWindow.webContents.send('autoUpdate', { downloaded: true });
47 });
48
49 autoUpdater.on('error', () => {
50 console.log('update-error');
51 params.mainWindow.webContents.send('autoUpdate', { error: true });
52 });
53 }
54};