()
| 959 | const UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours |
| 960 | |
| 961 | const setupAutoUpdater = () => { |
| 962 | if (!app.isPackaged) return; |
| 963 | autoUpdater.logger = log; |
| 964 | autoUpdater.autoDownload = true; |
| 965 | autoUpdater.autoInstallOnAppQuit = false; |
| 966 | |
| 967 | autoUpdater.on("update-available", (info: UpdateInfo) => { |
| 968 | pendingUpdateVersion = info.version; |
| 969 | setUpdateStatus({ state: "available", version: info.version }); |
| 970 | }); |
| 971 | autoUpdater.on("download-progress", (progress: ProgressInfo) => { |
| 972 | if (pendingUpdateVersion) { |
| 973 | setUpdateStatus({ |
| 974 | state: "downloading", |
| 975 | version: pendingUpdateVersion, |
| 976 | percent: Math.round(progress.percent ?? 0), |
| 977 | }); |
| 978 | } |
| 979 | }); |
| 980 | autoUpdater.on("update-downloaded", (info: UpdateInfo) => { |
| 981 | const decision = planDownloadedUpdate({ |
| 982 | stagedVersion: downloadedUpdateVersion, |
| 983 | declinedVersion: declinedUpdateVersion, |
| 984 | incomingVersion: info.version, |
| 985 | trigger: "boot", |
| 986 | }); |
| 987 | downloadedUpdateVersion = decision.stagedVersion; |
| 988 | declinedUpdateVersion = decision.declinedVersion; |
| 989 | setUpdateStatus(decision.status); |
| 990 | if (decision.promptVersion) void promptInstallUpdate(decision.promptVersion); |
| 991 | }); |
| 992 | autoUpdater.on("error", (err: Error) => { |
| 993 | log.warn("[updater] error", err); |
| 994 | setUpdateStatus( |
| 995 | statusAfterUpdateError(updateStatus, "Update failed. Check again from the menu."), |
| 996 | ); |
| 997 | pendingUpdateVersion = null; |
| 998 | }); |
| 999 | |
| 1000 | setInterval(() => { |
| 1001 | void runUpdateCheck({ alertOnFail: false, trigger: "interval" }); |
| 1002 | }, UPDATE_POLL_INTERVAL_MS); |
| 1003 | }; |
| 1004 | |
| 1005 | interface UpdateCheckOptions { |
| 1006 | readonly alertOnFail: boolean; |
no test coverage detected