diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/electron/ipc-api/autoUpdate.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/electron/ipc-api/autoUpdate.js')
-rw-r--r-- | src/electron/ipc-api/autoUpdate.js | 54 |
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 @@ | |||
1 | import { app, ipcMain } from 'electron'; | ||
2 | import { autoUpdater } from 'electron-updater'; | ||
3 | |||
4 | export 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 | }; | ||