Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
terkelg
GitHub Repository: terkelg/ramme
Path: blob/master/app/src/main/updater.js
106 views
1
const {autoUpdater, ipcMain} = require('electron')
2
const isDev = require('electron-is-dev')
3
const ms = require('ms')
4
const {version} = require('../../package')
5
const isPlatform = require('./../common/is-platform')
6
7
const FEED_URL = `https://nuts-serve-gapvnvvtee.now.sh/update/${process.platform}/${version}`
8
9
function createInterval () {
10
return setInterval(() => {
11
autoUpdater.checkForUpdates()
12
}, ms('30m'))
13
}
14
15
exports.init = window => {
16
if (isDev || isPlatform('linux')) {
17
return
18
}
19
20
autoUpdater.setFeedURL(FEED_URL)
21
22
// at this point the app is fully started and ready for updating
23
setTimeout(() => {
24
autoUpdater.checkForUpdates()
25
}, ms('5s'))
26
27
let intervalId = createInterval()
28
29
autoUpdater.on('update-available', () => {
30
clearInterval(intervalId)
31
intervalId = undefined
32
})
33
34
autoUpdater.on('update-downloaded', () => {
35
window.webContents.send('update-downloaded')
36
})
37
38
ipcMain.on('install-update', () => {
39
autoUpdater.quitAndInstall()
40
})
41
42
autoUpdater.on('error', err => {
43
if (intervalId === undefined) { // if the error occurred during the download
44
intervalId = createInterval()
45
}
46
47
console.log('Error fetching updates', err)
48
})
49
}
50
51