diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-14 11:03:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 11:03:28 +0200 |
commit | 087113d8a1214ba4c7df03bfe66747d8d944280c (patch) | |
tree | 4d853a03057138dfa845cd6a7d91ccf63565a1a6 /src/electron/ipc-api/autoUpdate.js | |
parent | chore: codebase improvements (#1930) (diff) | |
download | ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.tar.gz ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.tar.zst ferdium-app-087113d8a1214ba4c7df03bfe66747d8d944280c.zip |
chore: convert JS to TS (#1934)
Diffstat (limited to 'src/electron/ipc-api/autoUpdate.js')
-rw-r--r-- | src/electron/ipc-api/autoUpdate.js | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/electron/ipc-api/autoUpdate.js b/src/electron/ipc-api/autoUpdate.js deleted file mode 100644 index 255595b9e..000000000 --- a/src/electron/ipc-api/autoUpdate.js +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | import { app, ipcMain } from 'electron'; | ||
2 | import { autoUpdater } from 'electron-updater'; | ||
3 | import { GITHUB_NIGHTLIES_REPO_NAME, GITHUB_ORG_NAME } from '../../config'; | ||
4 | import { isMac, isWindows } from '../../environment'; | ||
5 | |||
6 | const debug = require('debug')('Ferdi:ipcApi:autoUpdate'); | ||
7 | |||
8 | export default (params) => { | ||
9 | const enableUpdate = Boolean(params.settings.app.get('automaticUpdates')); | ||
10 | |||
11 | if (!enableUpdate) { | ||
12 | autoUpdater.autoInstallOnAppQuit = false; | ||
13 | autoUpdater.autoDownload = false; | ||
14 | } else if (isMac || isWindows || process.env.APPIMAGE) { | ||
15 | ipcMain.on('autoUpdate', (event, args) => { | ||
16 | if (enableUpdate) { | ||
17 | try { | ||
18 | autoUpdater.autoInstallOnAppQuit = false; | ||
19 | autoUpdater.allowPrerelease = Boolean(params.settings.app.get('beta')); | ||
20 | autoUpdater.channel = autoUpdater.allowPrerelease ? 'beta' : 'latest'; | ||
21 | |||
22 | if (params.settings.app.get('nightly')) { | ||
23 | autoUpdater.allowPrerelease = Boolean(params.settings.app.get('nightly')); | ||
24 | autoUpdater.channel = 'alpha'; | ||
25 | autoUpdater.setFeedURL({ | ||
26 | provider: 'github', | ||
27 | owner: GITHUB_ORG_NAME, | ||
28 | repo: GITHUB_NIGHTLIES_REPO_NAME, | ||
29 | }); | ||
30 | } | ||
31 | |||
32 | if (args.action === 'check') { | ||
33 | debug('checking for update'); | ||
34 | autoUpdater.checkForUpdates(); | ||
35 | } else if (args.action === 'install') { | ||
36 | debug('installing update'); | ||
37 | autoUpdater.quitAndInstall(); | ||
38 | // we need to send a quit event | ||
39 | setTimeout(() => { | ||
40 | app.quit(); | ||
41 | }, 20); | ||
42 | } | ||
43 | } catch (e) { | ||
44 | console.error(e); | ||
45 | event.sender.send('autoUpdate', { error: true }); | ||
46 | } | ||
47 | } | ||
48 | }); | ||
49 | |||
50 | autoUpdater.on('update-not-available', () => { | ||
51 | debug('update-not-available'); | ||
52 | params.mainWindow.webContents.send('autoUpdate', { available: false }); | ||
53 | }); | ||
54 | |||
55 | autoUpdater.on('update-available', (event) => { | ||
56 | debug('update-available'); | ||
57 | |||
58 | if (enableUpdate) { | ||
59 | params.mainWindow.webContents.send('autoUpdate', { | ||
60 | version: event.version, | ||
61 | available: true, | ||
62 | }); | ||
63 | } | ||
64 | }); | ||
65 | |||
66 | autoUpdater.on('download-progress', (progressObj) => { | ||
67 | let logMessage = `Download speed: ${progressObj.bytesPerSecond}`; | ||
68 | logMessage = `${logMessage} - Downloaded ${progressObj.percent}%`; | ||
69 | logMessage = `${logMessage} (${progressObj.transferred}/${progressObj.total})`; | ||
70 | |||
71 | debug(logMessage); | ||
72 | }); | ||
73 | |||
74 | autoUpdater.on('update-downloaded', () => { | ||
75 | debug('update-downloaded'); | ||
76 | params.mainWindow.webContents.send('autoUpdate', { downloaded: true }); | ||
77 | }); | ||
78 | |||
79 | autoUpdater.on('error', () => { | ||
80 | debug('update-error'); | ||
81 | params.mainWindow.webContents.send('autoUpdate', { error: true }); | ||
82 | }); | ||
83 | } | ||
84 | }; | ||