()
| 911 | const UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours |
| 912 | |
| 913 | const setupAutoUpdater = () => { |
| 914 | if (!app.isPackaged) return; |
| 915 | autoUpdater.logger = log; |
| 916 | autoUpdater.autoDownload = true; |
| 917 | autoUpdater.autoInstallOnAppQuit = false; |
| 918 | |
| 919 | autoUpdater.on("update-available", (info: UpdateInfo) => { |
| 920 | pendingUpdateVersion = info.version; |
| 921 | setUpdateStatus({ state: "available", version: info.version }); |
| 922 | }); |
| 923 | autoUpdater.on("download-progress", (progress: ProgressInfo) => { |
| 924 | if (pendingUpdateVersion) { |
| 925 | setUpdateStatus({ |
| 926 | state: "downloading", |
| 927 | version: pendingUpdateVersion, |
| 928 | percent: Math.round(progress.percent ?? 0), |
| 929 | }); |
| 930 | } |
| 931 | }); |
| 932 | autoUpdater.on("update-downloaded", (info: UpdateInfo) => { |
| 933 | const decision = planDownloadedUpdate({ |
| 934 | stagedVersion: downloadedUpdateVersion, |
| 935 | declinedVersion: declinedUpdateVersion, |
| 936 | incomingVersion: info.version, |
| 937 | trigger: "boot", |
| 938 | }); |
| 939 | downloadedUpdateVersion = decision.stagedVersion; |
| 940 | declinedUpdateVersion = decision.declinedVersion; |
| 941 | setUpdateStatus(decision.status); |
| 942 | if (decision.promptVersion) void promptInstallUpdate(decision.promptVersion); |
| 943 | }); |
| 944 | autoUpdater.on("error", (err: Error) => { |
| 945 | log.warn("[updater] error", err); |
| 946 | setUpdateStatus( |
| 947 | statusAfterUpdateError(updateStatus, "Update failed. Check again from the menu."), |
| 948 | ); |
| 949 | pendingUpdateVersion = null; |
| 950 | }); |
| 951 | |
| 952 | setInterval(() => { |
| 953 | void runUpdateCheck({ alertOnFail: false, trigger: "interval" }); |
| 954 | }, UPDATE_POLL_INTERVAL_MS); |
| 955 | }; |
| 956 | |
| 957 | interface UpdateCheckOptions { |
| 958 | readonly alertOnFail: boolean; |
no test coverage detected