Changeset View
Changeset View
Standalone View
Standalone View
desktop/src/auto-update.js
// @flow | // @flow | ||||||||
// eslint-disable-next-line import/extensions | // eslint-disable-next-line import/extensions | ||||||||
import { app, ipcMain, autoUpdater } from 'electron/main'; | import { app, ipcMain, autoUpdater } from 'electron/main'; | ||||||||
const getUpdateUrl = version => | const getUpdateUrl = version => | ||||||||
`https://electron-update.commtechnologies.org/update/${process.platform}/${version}`; | `https://electron-update.commtechnologies.org/update/${process.platform}/${version}`; | ||||||||
export function initAutoUpdate(): void { | export function initAutoUpdate(): void { | ||||||||
autoUpdater.setFeedURL({ url: getUpdateUrl(app.getVersion()) }); | autoUpdater.setFeedURL({ url: getUpdateUrl(app.getVersion()) }); | ||||||||
// Check for new updates every 10 minutes | // Check for new updates every 10 minutes | ||||||||
const updateIntervalMs = 10 * 60_000; | const updateIntervalMs = 10 * 60_000; | ||||||||
let updateCheckSchedule = null; | |||||||||
tomek: Is it beneficial to introduce a new term `schedule`? Maybe we can use `interval`? | |||||||||
const scheduleCheckForUpdates = () => { | const scheduleCheckForUpdates = () => { | ||||||||
setTimeout(() => autoUpdater.checkForUpdates(), updateIntervalMs); | if (updateCheckSchedule) { | ||||||||
clearInterval(updateCheckSchedule); | |||||||||
} | |||||||||
updateCheckSchedule = setInterval( | |||||||||
() => autoUpdater.checkForUpdates(), | |||||||||
tomekUnsubmitted Not Done Inline Actions
I'm not sure if I suggested something similar previously, but () => f() could be replaced by just f tomek: I'm not sure if I suggested something similar previously, but `() => f()` could be replaced by… | |||||||||
ashoatUnsubmitted Not Done Inline ActionsNote that this only works if autoUpdater.checkForUpdates is defined as an arrow function instead of a standard class function... otherwise this will be dropped unless you use bind ashoat: Note that this only works if `autoUpdater.checkForUpdates` is defined as an arrow function… | |||||||||
updateIntervalMs, | |||||||||
); | |||||||||
}; | }; | ||||||||
scheduleCheckForUpdates(); | scheduleCheckForUpdates(); | ||||||||
autoUpdater.on('update-not-available', scheduleCheckForUpdates); | autoUpdater.on('update-available', () => { | ||||||||
clearInterval(updateCheckSchedule); | |||||||||
updateCheckSchedule = null; | |||||||||
}); | |||||||||
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { | autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { | ||||||||
autoUpdater.setFeedURL({ url: getUpdateUrl(releaseName) }); | autoUpdater.setFeedURL({ url: getUpdateUrl(releaseName) }); | ||||||||
scheduleCheckForUpdates(); | scheduleCheckForUpdates(); | ||||||||
}); | }); | ||||||||
ipcMain.on('update-to-new-version', () => autoUpdater.quitAndInstall()); | ipcMain.on('update-to-new-version', () => autoUpdater.quitAndInstall()); | ||||||||
} | } |
Is it beneficial to introduce a new term schedule? Maybe we can use interval?