forked from lostdesign/linked
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.js
46 lines (41 loc) · 1.37 KB
/
updater.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
import { dialog, Notification } from 'electron'
import { autoUpdater } from 'electron-updater'
import { DAILY, WEEKLY } from '@/background'
autoUpdater.autoDownload = false
autoUpdater.on('update-available', async (updateInfo) => {
const { response } = await dialog.showMessageBox({
title: 'Update available',
message: `Version ${updateInfo.version} is available, would you like to update now?`,
detail: 'The app will download the update and restart once finished.',
type: 'question',
buttons: ['Remind me later', 'Install'],
defaultId: 1,
noLink: true
})
if (response === 1) {
global.storage.set('updateInterval', DAILY)
await autoUpdater.downloadUpdate()
} else {
global.storage.set('updateInterval', WEEKLY)
}
})
autoUpdater.on('update-not-available', async () => {
await new Notification({
title: 'No updates',
body: 'You are already on the latest version of linked'
}).show()
})
autoUpdater.on('update-downloaded', async () => {
autoUpdater.quitAndInstall()
})
const askForUpdates = async () => {
if (!global.storage.get('enableUpdates')) return
await autoUpdater.checkForUpdates()
}
const setupUpdates = () => {
if (parseInt(global.storage.get('updateInterval')) === DAILY) {
askForUpdates()
}
setInterval(() => askForUpdates(), global.storage.get('updateInterval'))
}
export default { setupUpdates, askForUpdates }