()
| 834 | const UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours |
| 835 | |
| 836 | const setupAutoUpdater = () => { |
| 837 | if (!app.isPackaged) return; |
| 838 | autoUpdater.logger = log; |
| 839 | autoUpdater.autoDownload = true; |
| 840 | autoUpdater.autoInstallOnAppQuit = false; |
| 841 | |
| 842 | autoUpdater.on("update-available", (info: UpdateInfo) => { |
| 843 | pendingUpdateVersion = info.version; |
| 844 | setUpdateStatus({ state: "available", version: info.version }); |
| 845 | }); |
| 846 | autoUpdater.on("download-progress", (progress: ProgressInfo) => { |
| 847 | if (pendingUpdateVersion) { |
| 848 | setUpdateStatus({ |
| 849 | state: "downloading", |
| 850 | version: pendingUpdateVersion, |
| 851 | percent: Math.round(progress.percent ?? 0), |
| 852 | }); |
| 853 | } |
| 854 | }); |
| 855 | autoUpdater.on("update-downloaded", (info: UpdateInfo) => { |
| 856 | downloadedUpdateVersion = info.version; |
| 857 | setUpdateStatus({ state: "downloaded", version: info.version }); |
| 858 | void promptInstallUpdate(info.version); |
| 859 | }); |
| 860 | autoUpdater.on("error", (err: Error) => { |
| 861 | log.warn("[updater] error", err); |
| 862 | }); |
| 863 | |
| 864 | setInterval(() => { |
| 865 | if (downloadedUpdateVersion) return; // already staged; waiting on the user |
| 866 | void runUpdateCheck({ alertOnFail: false }); |
| 867 | }, UPDATE_POLL_INTERVAL_MS); |
| 868 | }; |
| 869 | |
| 870 | interface UpdateCheckOptions { |
| 871 | readonly alertOnFail: boolean; |
no test coverage detected