MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / setupAutoUpdater

Function setupAutoUpdater

apps/desktop/src/main/index.ts:913–955  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

911const UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours
912
913const 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
957interface UpdateCheckOptions {
958 readonly alertOnFail: boolean;

Callers 1

bootFunction · 0.85

Calls 6

planDownloadedUpdateFunction · 0.90
statusAfterUpdateErrorFunction · 0.90
setUpdateStatusFunction · 0.85
promptInstallUpdateFunction · 0.85
runUpdateCheckFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected