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

Function setupAutoUpdater

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

Source from the content-addressed store, hash-verified

959const UPDATE_POLL_INTERVAL_MS = 4 * 60 * 60 * 1000; // 4 hours
960
961const 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
1005interface UpdateCheckOptions {
1006 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