@@ -69,8 +69,10 @@ const UpdateInfo = Schema.Struct({
6969 files : Schema . optional ( Schema . Unknown ) ,
7070} ) ;
7171
72- // Only the sha512s are read, to recognize a download an earlier launch finished.
73- const ReleaseFiles = Schema . Array ( Schema . Struct ( { sha512 : Schema . String } ) ) ;
72+ // Read to recognize a download an earlier launch finished.
73+ const ReleaseFile = Schema . Struct ( { url : Schema . String , sha512 : Schema . String } ) ;
74+ type ReleaseFile = typeof ReleaseFile . Type ;
75+ const ReleaseFiles = Schema . Array ( ReleaseFile ) ;
7476
7577// electron-updater's pending/update-info.json.
7678const CachedDownloadInfo = Schema . fromJsonString (
@@ -284,6 +286,33 @@ function isArm64HostRunningIntelBuild(runtimeInfo: DesktopRuntimeInfo): boolean
284286 return runtimeInfo . hostArch === "arm64" && runtimeInfo . appArch === "x64" ;
285287}
286288
289+ /** The release file electron-updater's platform updater will download, mirroring
290+ MacUpdater.filterFilesForArch and Provider.findFile. A cached download only
291+ counts if it is this file: the updater discards any other and fetches anew. */
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+ : isDebPackage
310+ ? ".deb"
311+ : ".appimage" ;
312+ const packageFiles = candidates . filter ( ( file ) => file . url . toLowerCase ( ) . endsWith ( extension ) ) ;
313+ return packageFiles . find ( ( file ) => file . url . includes ( runtimeInfo . appArch ) ) ?? packageFiles [ 0 ] ;
314+ }
315+
287316/** @public Service construction is part of the canonical Effect module API. */
288317export const make = Effect . gen ( function * ( ) {
289318 const config = yield * DesktopConfig . DesktopConfig ;
@@ -754,25 +783,12 @@ export const make = Effect.gen(function* () {
754783 ) ;
755784 } ) . pipe ( Effect . withSpan ( "desktop.updates.startPollers" ) ) ;
756785
757- // The package type this install's updater downloads. A cache left by another
758- // install type (an AppImage next to a .deb) would be discarded and replaced
759- // with a fresh network download, so it must not count as a match.
760- const updatePackageExtension =
761- environment . platform === "darwin"
762- ? ".zip"
763- : environment . platform === "win32"
764- ? ".exe"
765- : isDebPackage
766- ? ".deb"
767- : ".AppImage" ;
768-
769786 const cachedDownloadSha512 = Effect . gen ( function * ( ) {
770787 const pendingDirectory = yield * electronUpdater . pendingDownloadDirectory ;
771788 if ( Option . isNone ( pendingDirectory ) ) return Option . none < string > ( ) ;
772789 const info = yield * fileSystem
773790 . readFileString ( environment . path . join ( pendingDirectory . value , "update-info.json" ) )
774791 . pipe ( Effect . flatMap ( decodeCachedDownloadInfo ) ) ;
775- if ( ! info . fileName . endsWith ( updatePackageExtension ) ) return Option . none < string > ( ) ;
776792 const fileExists = yield * fileSystem . exists (
777793 environment . path . join ( pendingDirectory . value , info . fileName ) ,
778794 ) ;
@@ -789,8 +805,13 @@ export const make = Effect.gen(function* () {
789805 ) {
790806 const cachedSha512 = yield * cachedDownloadSha512 ;
791807 if ( Option . isNone ( cachedSha512 ) ) return ;
792- const releaseFiles = Option . getOrElse ( decodeReleaseFiles ( files ) , ( ) => [ ] ) ;
793- if ( ! releaseFiles . some ( ( file ) => file . sha512 === cachedSha512 . value ) ) return ;
808+ const updateFile = selectUpdateFile (
809+ Option . getOrElse ( decodeReleaseFiles ( files ) , ( ) => [ ] ) ,
810+ environment . platform ,
811+ isDebPackage ,
812+ environment . runtimeInfo ,
813+ ) ;
814+ if ( updateFile ?. sha512 !== cachedSha512 . value ) return ;
794815
795816 // update-available arrives while its check still holds the action reservation.
796817 yield * awaitIdleUpdateAction ;
0 commit comments