@@ -45,7 +45,7 @@ import { |
45 | 45 | const AUTO_UPDATE_STARTUP_DELAY = "15 seconds"; |
46 | 46 | const AUTO_UPDATE_POLL_INTERVAL = "4 minutes"; |
47 | 47 |
|
48 | | -type UpdateAction = "check" | "download" | "install"; |
| 48 | +type UpdateAction = "check" | "download" | "install" | "channel"; |
49 | 49 |
|
50 | 50 | const AppUpdateYmlConfig = Schema.Record(Schema.String, Schema.String); |
51 | 51 | type AppUpdateYmlConfig = typeof AppUpdateYmlConfig.Type; |
@@ -70,7 +70,7 @@ const currentIsoTimestamp = DateTime.now.pipe(Effect.map(DateTime.formatIso)); |
70 | 70 | export class DesktopUpdateActionInProgressError extends Schema.TaggedErrorClass<DesktopUpdateActionInProgressError>()( |
71 | 71 | "DesktopUpdateActionInProgressError", |
72 | 72 | { |
73 | | - action: Schema.Literals(["check", "download", "install"]), |
| 73 | + action: Schema.Literals(["check", "download", "install", "channel"]), |
74 | 74 | requestedChannel: DesktopUpdateChannelSchema, |
75 | 75 | }, |
76 | 76 | ) { |
@@ -118,7 +118,7 @@ export class DesktopUpdateEventHandlingError extends Schema.TaggedErrorClass<Des |
118 | 118 | export class DesktopUpdaterReportedError extends Schema.TaggedErrorClass<DesktopUpdaterReportedError>()( |
119 | 119 | "DesktopUpdaterReportedError", |
120 | 120 | { |
121 | | - operation: Schema.Literals(["check", "download", "install", "background"]), |
| 121 | + operation: Schema.Literals(["check", "download", "install", "channel", "background"]), |
122 | 122 | cause: Schema.Defect(), |
123 | 123 | }, |
124 | 124 | ) { |
@@ -320,6 +320,12 @@ export const make = Effect.gen(function* () { |
320 | 320 | Option.isSome(activeAction) ? [false, activeAction] : [true, Option.some(action)], |
321 | 321 | ); |
322 | 322 |
|
| 323 | + const tryStartChannelChange = Ref.modify(activeUpdateActionRef, (activeAction) => |
| 324 | + Option.isSome(activeAction) |
| 325 | + ? [activeAction, activeAction] |
| 326 | + : [Option.none<UpdateAction>(), Option.some<UpdateAction>("channel")], |
| 327 | + ); |
| 328 | + |
323 | 329 | const finishUpdateAction = (action: UpdateAction): Effect.Effect<void> => |
324 | 330 | Ref.update(activeUpdateActionRef, (activeAction) => |
325 | 331 | Option.isSome(activeAction) && activeAction.value === action ? Option.none() : activeAction, |
@@ -344,7 +350,10 @@ export const make = Effect.gen(function* () { |
344 | 350 |
|
345 | 351 | const shouldEnableAutoUpdates = resolveDisabledReason.pipe(Effect.map(Option.isNone)); |
346 | 352 |
|
347 | | - const checkForUpdates = Effect.fn("desktop.updates.checkForUpdates")(function* (reason: string) { |
| 353 | + const checkForUpdates = Effect.fn("desktop.updates.checkForUpdates")(function* ( |
| 354 | + reason: string, |
| 355 | + actionReservation: "acquire" | "held" = "acquire", |
| 356 | + ) { |
348 | 357 | yield* Effect.annotateCurrentSpan({ reason }); |
349 | 358 | if (yield* Ref.get(desktopState.quitting)) return false; |
350 | 359 | if (!(yield* Ref.get(updaterConfiguredRef))) return false; |
@@ -358,9 +367,9 @@ export const make = Effect.gen(function* () { |
358 | 367 | return false; |
359 | 368 | } |
360 | 369 |
|
361 | | - if (!(yield* tryStartUpdateAction("check"))) return false; |
| 370 | + if (actionReservation === "acquire" && !(yield* tryStartUpdateAction("check"))) return false; |
362 | 371 |
|
363 | | - return yield* Effect.gen(function* () { |
| 372 | + const check = Effect.gen(function* () { |
364 | 373 | const checkedAt = yield* currentIsoTimestamp; |
365 | 374 | yield* setState(reduceDesktopUpdateStateOnCheckStart(state, checkedAt)); |
366 | 375 | yield* logUpdaterInfo("checking for updates", { reason }); |
@@ -383,7 +392,11 @@ export const make = Effect.gen(function* () { |
383 | 392 | }), |
384 | 393 | }), |
385 | 394 | ); |
386 | | - }).pipe(Effect.ensuring(finishUpdateAction("check"))); |
| 395 | + }); |
| 396 | + |
| 397 | + return yield* actionReservation === "held" |
| 398 | + ? check |
| 399 | + : check.pipe(Effect.ensuring(finishUpdateAction("check"))); |
387 | 400 | }); |
388 | 401 |
|
389 | 402 | const downloadAvailableUpdate = Effect.gen(function* () { |
@@ -778,41 +791,43 @@ export const make = Effect.gen(function* () { |
778 | 791 | nextChannel: DesktopUpdateChannel, |
779 | 792 | ) { |
780 | 793 | yield* Effect.annotateCurrentSpan({ channel: nextChannel }); |
781 | | - const activeAction = yield* activeUpdateAction; |
| 794 | + const activeAction = yield* tryStartChannelChange; |
782 | 795 | if (Option.isSome(activeAction)) { |
783 | 796 | return yield* new DesktopUpdateActionInProgressError({ |
784 | 797 | action: activeAction.value, |
785 | 798 | requestedChannel: nextChannel, |
786 | 799 | }); |
787 | 800 | } |
788 | 801 |
|
789 | | - const state = yield* Ref.get(updateStateRef); |
790 | | - if (nextChannel === state.channel) { |
791 | | - return state; |
792 | | - } |
| 802 | + return yield* Effect.gen(function* () { |
| 803 | + const state = yield* Ref.get(updateStateRef); |
| 804 | + if (nextChannel === state.channel) { |
| 805 | + return state; |
| 806 | + } |
793 | 807 |
|
794 | | - yield* desktopSettings |
795 | | - .setUpdateChannel(nextChannel) |
796 | | - .pipe( |
797 | | - Effect.mapError( |
798 | | - (cause) => new DesktopUpdateChannelPersistenceError({ channel: nextChannel, cause }), |
799 | | - ), |
800 | | - ); |
| 808 | + yield* desktopSettings |
| 809 | + .setUpdateChannel(nextChannel) |
| 810 | + .pipe( |
| 811 | + Effect.mapError( |
| 812 | + (cause) => new DesktopUpdateChannelPersistenceError({ channel: nextChannel, cause }), |
| 813 | + ), |
| 814 | + ); |
801 | 815 |
|
802 | | - const enabled = yield* shouldEnableAutoUpdates; |
803 | | - yield* setState(createBaseUpdateState(nextChannel, enabled, environment)); |
| 816 | + const enabled = yield* shouldEnableAutoUpdates; |
| 817 | + yield* setState(createBaseUpdateState(nextChannel, enabled, environment)); |
804 | 818 |
|
805 | | - if (!enabled || !(yield* Ref.get(updaterConfiguredRef))) { |
806 | | - return yield* Ref.get(updateStateRef); |
807 | | - } |
| 819 | + if (!enabled || !(yield* Ref.get(updaterConfiguredRef))) { |
| 820 | + return yield* Ref.get(updateStateRef); |
| 821 | + } |
808 | 822 |
|
809 | | - yield* applyAutoUpdaterChannel(nextChannel); |
810 | | - const allowDowngrade = yield* electronUpdater.allowDowngrade; |
811 | | - yield* electronUpdater.setAllowDowngrade(true); |
812 | | - yield* checkForUpdates("channel-change").pipe( |
813 | | - Effect.ensuring(electronUpdater.setAllowDowngrade(allowDowngrade).pipe(Effect.ignore)), |
814 | | - ); |
815 | | - return yield* Ref.get(updateStateRef); |
| 823 | + yield* applyAutoUpdaterChannel(nextChannel); |
| 824 | + const allowDowngrade = yield* electronUpdater.allowDowngrade; |
| 825 | + yield* electronUpdater.setAllowDowngrade(true); |
| 826 | + yield* checkForUpdates("channel-change", "held").pipe( |
| 827 | + Effect.ensuring(electronUpdater.setAllowDowngrade(allowDowngrade).pipe(Effect.ignore)), |
| 828 | + ); |
| 829 | + return yield* Ref.get(updateStateRef); |
| 830 | + }).pipe(Effect.ensuring(finishUpdateAction("channel"))); |
816 | 831 | }), |
817 | 832 | check: Effect.fn("desktop.updates.check")(function* (reason: string) { |
818 | 833 | yield* Effect.annotateCurrentSpan({ reason }); |
|