@@ -50,6 +50,7 @@ import {
5050const AUTO_UPDATE_STARTUP_DELAY = "15 seconds" ;
5151const AUTO_UPDATE_POLL_INTERVAL = "4 minutes" ;
5252const PREPARED_INSTALL_CHECK_WAIT = Duration . seconds ( 90 ) ;
53+ const BACKGROUND_DOWNLOAD_START_WAIT = Duration . minutes ( 2 ) ;
5354
5455type UpdateAction = "check" | "download" | "install" | "install-recovery" | "channel" ;
5556
@@ -289,6 +290,7 @@ export const make = Effect.gen(function* () {
289290 const finishedUpdateActions = yield * PubSub . unbounded < UpdateAction > ( ) ;
290291 const updaterConfiguredRef = yield * Ref . make ( false ) ;
291292 const lastLoggedDownloadMilestoneRef = yield * Ref . make ( - 1 ) ;
293+ const lastCheckReasonRef = yield * Ref . make < string | null > ( null ) ;
292294 const updateStateRef = yield * Ref . make < DesktopUpdateState > (
293295 createInitialDesktopUpdateState (
294296 environment . appVersion ,
@@ -425,6 +427,7 @@ export const make = Effect.gen(function* () {
425427
426428 if ( actionReservation === "acquire" && ! ( yield * tryStartUpdateAction ( "check" ) ) ) return false ;
427429
430+ yield * Ref . set ( lastCheckReasonRef , reason ) ;
428431 const check = Effect . gen ( function * ( ) {
429432 const checkedAt = yield * currentIsoTimestamp ;
430433 yield * setState ( reduceDesktopUpdateStateOnCheckStart ( state , checkedAt ) ) ;
@@ -516,6 +519,28 @@ export const make = Effect.gen(function* () {
516519 ) ;
517520 } ) . pipe ( Effect . withSpan ( "desktop.updates.downloadAvailableUpdate" ) ) ;
518521
522+ // update-available fires inside the check that found it, so the download
523+ // waits for that check to release the updater. Installing stays gated: the
524+ // app's server relaunches into it when idle, and quitting installs it.
525+ const downloadInBackground = Effect . scoped (
526+ Effect . gen ( function * ( ) {
527+ const completions = yield * PubSub . subscribe ( finishedUpdateActions ) ;
528+ while ( Option . isSome ( yield * activeUpdateAction ) ) {
529+ yield * PubSub . take ( completions ) ;
530+ }
531+ if ( yield * Ref . get ( desktopState . quitting ) ) return ;
532+ yield * downloadAvailableUpdate ;
533+ } ) ,
534+ ) . pipe (
535+ Effect . timeout ( BACKGROUND_DOWNLOAD_START_WAIT ) ,
536+ Effect . catchCause ( ( cause ) =>
537+ Cause . hasInterruptsOnly ( cause )
538+ ? Effect . void
539+ : logUpdaterWarning ( "background update download did not start" ) ,
540+ ) ,
541+ Effect . withSpan ( "desktop.updates.downloadInBackground" ) ,
542+ ) ;
543+
519544 // Tells the primary backend that the coming stop is an update restart, so it
520545 // keeps its managed tunnel for the backend the updated app starts. Best
521546 // effort: without the marker the backend only re-provisions its tunnel.
@@ -773,6 +798,12 @@ export const make = Effect.gen(function* () {
773798 releaseNoteGroups : releaseNotes . length ,
774799 omittedReleaseCount,
775800 } ) ;
801+ // Updates found by the background pollers download on their own; a
802+ // check someone started keeps its Download button.
803+ const reason = yield * Ref . get ( lastCheckReasonRef ) ;
804+ if ( reason === "startup" || reason === "poll" ) {
805+ yield * Effect . forkDetach ( downloadInBackground ) ;
806+ }
776807 } ) ,
777808 ) ,
778809 Effect . catchCause ( ( cause ) => {
@@ -931,7 +962,8 @@ export const make = Effect.gen(function* () {
931962 yield * Ref . set ( updaterConfiguredRef , true ) ;
932963
933964 yield * electronUpdater . setAutoDownload ( false ) ;
934- yield * electronUpdater . setAutoInstallOnAppQuit ( false ) ;
965+ // A download that is never relaunched into installs when the user quits.
966+ yield * electronUpdater . setAutoInstallOnAppQuit ( true ) ;
935967 yield * applyAutoUpdaterChannel ( settings . updateChannel ) ;
936968 yield * electronUpdater . setDisableDifferentialDownload (
937969 isArm64HostRunningIntelBuild ( environment . runtimeInfo ) ,
0 commit comments