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