fix(desktop): restart prompt returns after relaunching with a downloaded update #18095
MergedRakshithBhat03(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/18095/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/updates/DesktopUpdates.ts line 793OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -736,0 +773,21 @@773+ .readFileString(environment.path.join(pendingDirectory.value, "update-info.json"))774+ .pipe(Effect.flatMap(decodeCachedDownloadInfo));775+ if (!info.fileName.endsWith(updatePackageExtension)) return Option.none<string>();776+ const fileExists = yield* fileSystem.exists(777+ environment.path.join(pendingDirectory.value, info.fileName),778+ );779+ return fileExists ? Option.some(info.sha512) : Option.none<string>();780+ }).pipe(Effect.orElseSucceed(() => Option.none<string>()));781+782+ // Update state lives in memory, but electron-updater keeps a finished download783+ // on disk across launches. When the release a check finds is the cached one,784+ // pick it back up so the restart prompt returns without another click. A newer785+ // release does not match and waits for the user like any other.786+ const resumeCachedDownload = Effect.fn("desktop.updates.resumeCachedDownload")(function* (787+ version: string,788+ files: unknown,789+ ) {790+ const cachedSha512 = yield* cachedDownloadSha512;791+ if (Option.isNone(cachedSha512)) return;792+ const releaseFiles = Option.getOrElse(decodeReleaseFiles(files), () => []);793+ if (!releaseFiles.some((file) => file.sha512 === cachedSha512.value)) return;
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
apps/desktop/src/updates/DesktopUpdates.ts line 371Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -275,0 +292,21 @@292+function selectUpdateFile(293+ files: ReadonlyArray<ReleaseFile>,294+ platform: NodeJS.Platform,295+ isDebPackage: boolean,296+ runtimeInfo: DesktopRuntimeInfo,297+): ReleaseFile | undefined {298+ let candidates = files;299+ if (platform === "darwin") {300+ const isArm64File = (file: ReleaseFile) => file.url.includes("arm64");301+ const preferArm64 = runtimeInfo.hostArch === "arm64" && files.some(isArm64File);302+ candidates = files.filter((file) => isArm64File(file) === preferArm64);303+ }304+ const extension =305+ platform === "darwin"306+ ? ".zip"307+ : platform === "win32"308+ ? ".exe"309+ : isDebPackage310+ ? ".deb"311+ : ".appimage";312+ const packageFiles = candidates.filter((file) => file.url.toLowerCase().endsWith(extension));apps/desktop/src/updates/DesktopUpdates.ts line 809OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -736,0 +789,21 @@789+ const info = yield* fileSystem790+ .readFileString(environment.path.join(pendingDirectory.value, "update-info.json"))791+ .pipe(Effect.flatMap(decodeCachedDownloadInfo));792+ const fileExists = yield* fileSystem.exists(793+ environment.path.join(pendingDirectory.value, info.fileName),794+ );795+ return fileExists ? Option.some(info.sha512) : Option.none<string>();796+ }).pipe(Effect.orElseSucceed(() => Option.none<string>()));797+798+ // Update state lives in memory, but electron-updater keeps a finished download799+ // on disk across launches. When the release a check finds is the cached one,800+ // pick it back up so the restart prompt returns without another click. A newer801+ // release does not match and waits for the user like any other.802+ const resumeCachedDownload = Effect.fn("desktop.updates.resumeCachedDownload")(function* (803+ version: string,804+ files: unknown,805+ ) {806+ const cachedSha512 = yield* cachedDownloadSha512;807+ if (Option.isNone(cachedSha512)) return;808+ const updateFile = selectUpdateFile(809+ Option.getOrElse(decodeReleaseFiles(files), () => []),coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge assignedjuliusmarminge
juliusmarminge merged thisd445fdb
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed