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

Function setupAutoUpdater

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

Source from the content-addressed store, hash-verified

953const UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours
954
955const 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
999interface UpdateCheckOptions {
1000 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