|
| 1 | +import { app, autoUpdater, dialog } from "electron"; |
| 2 | + |
| 3 | +const SERVER = "https://hazel-khaki-seven.vercel.app"; |
| 4 | +const UPDATE_POLLING_INTERVAL_MS = 15 * 60 * 1000; // 15 minutes |
| 5 | + |
| 6 | +/** Checks for and downloads updates */ |
| 7 | +export function startUpdatePolling() { |
| 8 | + const url = `${SERVER}/update/${process.platform}/${app.getVersion()}`; |
| 9 | + autoUpdater.setFeedURL({ url }); |
| 10 | + // setInterval(() => { |
| 11 | + // TODO: Do NOT force users to install updates |
| 12 | + // See https://github.com/electron/electron/issues/16561 |
| 13 | + // However, in the meantime it is better to force update than never update... |
| 14 | + autoUpdater.checkForUpdates(); |
| 15 | + // }, UPDATE_POLLING_INTERVAL_MS); |
| 16 | +} |
| 17 | + |
| 18 | +export function registerUpdateHandlers() { |
| 19 | + autoUpdater.on("update-downloaded", (event, releaseNotes, releaseName) => { |
| 20 | + const dialogOpts = { |
| 21 | + type: "info", |
| 22 | + buttons: ["Restart", "Later"], |
| 23 | + title: "Application Update", |
| 24 | + message: process.platform === "win32" ? releaseNotes : releaseName, |
| 25 | + detail: |
| 26 | + "A new version has been downloaded. Restart the application to apply the updates.", |
| 27 | + }; |
| 28 | + |
| 29 | + dialog.showMessageBox(dialogOpts).then((returnValue) => { |
| 30 | + if (returnValue.response === 0) autoUpdater.quitAndInstall(); |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + autoUpdater.on("error", (message) => { |
| 35 | + console.error("There was a problem updating the application"); |
| 36 | + console.error(message); |
| 37 | + }); |
| 38 | +} |
0 commit comments