Skip to content

Commit 8ccb2b0

Browse files
fix(server): advertise desktop app updates only when the desktop can install them
A desktop-managed server advertised desktopAppUpdate (plus the channel switch and self-update progress capabilities) whenever it had a desktop control fd. Builds whose updater is disabled, such as an extracted AppImage run without $APPIMAGE, therefore offered remote updates that then failed. DesktopUpdates.configure now records whether the updater has a disabled reason in DesktopState. It runs before the first backend start. The primary backend bootstrap carries that as desktopAppUpdate, and ServerEnvironment advertises the capabilities only when it is true. A nightly channel blocked by policy still counts as updatable, because the user can switch back to stable. Fixes #30784 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent a7a81d9 commit 8ccb2b0

9 files changed

Lines changed: 51 additions & 7 deletions

File tree

‎apps/desktop/src/app/DesktopState.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ export class DesktopState extends Context.Service<
1717
{
1818
readonly backendReady: Ref.Ref<boolean>;
1919
readonly quitting: Ref.Ref<boolean>;
20+
// Set by DesktopUpdates.configure, which runs before the first backend start.
21+
readonly canInstallUpdates: Ref.Ref<boolean>;
2022
readonly primaryBackendStartup: SubscriptionRef.SubscriptionRef<PrimaryBackendStartup>;
2123
}
2224
>()("@t3tools/desktop/app/DesktopState") {}
2325

2426
const make = Effect.all({
2527
backendReady: Ref.make(false),
2628
quitting: Ref.make(false),
29+
canInstallUpdates: Ref.make(false),
2730
primaryBackendStartup: SubscriptionRef.make<PrimaryBackendStartup>({ _tag: "Starting" }),
2831
});
2932

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Layer from "effect/Layer";
99
import * as ManagedRuntime from "effect/ManagedRuntime";
1010
import * as Option from "effect/Option";
1111
import * as Path from "effect/Path";
12+
import * as Ref from "effect/Ref";
1213
import * as Stream from "effect/Stream";
1314
import { ChildProcessSpawner } from "effect/process";
1415

@@ -18,6 +19,7 @@ import * as DesktopBackendConfiguration from "./DesktopBackendConfiguration.ts";
1819
import * as DesktopShellEnvironment from "../shell/DesktopShellEnvironment.ts";
1920
import * as DesktopConfig from "../app/DesktopConfig.ts";
2021
import * as DesktopServerExposure from "./DesktopServerExposure.ts";
22+
import * as DesktopState from "../app/DesktopState.ts";
2123
import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
2224
import * as DesktopWslEnvironment from "../wsl/DesktopWslEnvironment.ts";
2325
import * as DesktopWslServerTree from "../wsl/DesktopWslServerTree.ts";
@@ -30,7 +32,10 @@ const layerShellEnvironment = (prepared = true) =>
3032
});
3133

3234
const layerBackendConfiguration = (prepared = true) =>
33-
DesktopBackendConfiguration.layer.pipe(Layer.provide(layerShellEnvironment(prepared)));
35+
DesktopBackendConfiguration.layer.pipe(
36+
Layer.provide(layerShellEnvironment(prepared)),
37+
Layer.provideMerge(DesktopState.layer),
38+
);
3439

3540
const layerServerExposure = Layer.succeed(DesktopServerExposure.DesktopServerExposure, {
3641
getState: Effect.die("unexpected getState"),
@@ -107,6 +112,7 @@ const withHarness = <A, E, R>(
107112
E,
108113
| R
109114
| DesktopEnvironment.DesktopEnvironment
115+
| DesktopState.DesktopState
110116
| FileSystem.FileSystem
111117
| DesktopBackendConfiguration.DesktopBackendConfiguration
112118
>,
@@ -275,6 +281,21 @@ describe("DesktopBackendConfiguration", () => {
275281
),
276282
);
277283

284+
it.effect.each([{ canInstallUpdates: false }, { canInstallUpdates: true }])(
285+
"resolvePrimary tells the backend whether the desktop can update (canInstallUpdates: $canInstallUpdates)",
286+
({ canInstallUpdates }) =>
287+
withHarness(
288+
Effect.gen(function* () {
289+
const desktopState = yield* DesktopState.DesktopState;
290+
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
291+
yield* Ref.set(desktopState.canInstallUpdates, canInstallUpdates);
292+
293+
const config = yield* configuration.resolvePrimary;
294+
assert.equal(config.bootstrap.desktopAppUpdate, canInstallUpdates);
295+
}),
296+
),
297+
);
298+
278299
it.effect("resolvePrimary starts from server.asar without materializing the WSL tree", () =>
279300
Effect.gen(function* () {
280301
const fileSystem = yield* FileSystem.FileSystem;

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as FileSystem from "effect/FileSystem";
1111
import * as Layer from "effect/Layer";
1212
import * as Option from "effect/Option";
1313
import * as PlatformError from "effect/PlatformError";
14+
import * as Ref from "effect/Ref";
1415
import * as Schema from "effect/Schema";
1516
import * as SynchronizedRef from "effect/SynchronizedRef";
1617

@@ -19,6 +20,7 @@ import serverPackageJson from "../../../server/package.json" with { type: "json"
1920
import * as DesktopBackendManager from "./DesktopBackendManager.ts";
2021
import * as DesktopCliShim from "../app/DesktopCliShim.ts";
2122
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
23+
import * as DesktopState from "../app/DesktopState.ts";
2224
import * as DesktopServerExposure from "./DesktopServerExposure.ts";
2325
import * as DesktopShellEnvironment from "../shell/DesktopShellEnvironment.ts";
2426
import * as DesktopAppSettings from "../settings/DesktopAppSettings.ts";
@@ -486,6 +488,7 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
486488
readonly resourceMonitorPath: Option.Option<string>;
487489
readonly cliPath: Option.Option<string>;
488490
readonly shellEnvironmentPrepared: boolean;
491+
readonly desktopAppUpdate: boolean;
489492
},
490493
): Effect.fn.Return<
491494
DesktopBackendManager.DesktopBackendStartConfig,
@@ -509,6 +512,7 @@ const resolvePrimaryStartConfig = Effect.fn("desktop.backendConfiguration.resolv
509512
tailscaleServePort: backendExposure.tailscaleServePort,
510513
desktopTelemetryFd: 4,
511514
desktopTelemetryControlFd: 5,
515+
desktopAppUpdate: input.desktopAppUpdate,
512516
desktopBrowserFd: 6,
513517
desktopBrowserControlFd: 7,
514518
...Option.match(input.resourceMonitorPath, {
@@ -723,6 +727,7 @@ export const make = Effect.gen(function* () {
723727
const wslEnvironment = yield* DesktopWslEnvironment.DesktopWslEnvironment;
724728
const wslServerTree = yield* DesktopWslServerTree.DesktopWslServerTree;
725729
const settings = yield* DesktopAppSettings.DesktopAppSettings;
730+
const desktopState = yield* DesktopState.DesktopState;
726731
const random = yield* SecureRandom.SecureRandom;
727732
// Random generation yields; serialize it so concurrent backends cannot capture distinct bootstrap secrets.
728733
const secretRef = yield* SynchronizedRef.make(Option.none<string>());
@@ -789,6 +794,7 @@ export const make = Effect.gen(function* () {
789794
resourceMonitorPath,
790795
cliPath,
791796
shellEnvironmentPrepared,
797+
desktopAppUpdate: yield* Ref.get(desktopState.canInstallUpdates),
792798
}).pipe(
793799
Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment),
794800
Effect.provideService(DesktopServerExposure.DesktopServerExposure, serverExposure),

‎apps/desktop/src/updates/DesktopUpdates.test.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,22 @@ describe("DesktopUpdates", () => {
2929
Effect.scoped(
3030
Effect.gen(function* () {
3131
const updates = yield* DesktopUpdates.DesktopUpdates;
32+
const desktopState = yield* DesktopState.DesktopState;
3233
yield* updates.configure;
33-
return yield* updates.getState;
34+
return {
35+
state: yield* updates.getState,
36+
canInstallUpdates: yield* Ref.get(desktopState.canInstallUpdates),
37+
};
3438
}),
3539
).pipe(Effect.provide(makeHarness({ platform: "linux", packageType }).layer));
3640

3741
const deb = yield* linuxState("deb\n");
38-
assert.equal(deb.status, "idle");
42+
assert.equal(deb.state.status, "idle");
43+
assert.isTrue(deb.canInstallUpdates);
3944

4045
const unmarked = yield* linuxState(undefined);
41-
assert.equal(unmarked.status, "disabled");
46+
assert.equal(unmarked.state.status, "disabled");
47+
assert.isFalse(unmarked.canInstallUpdates);
4248
}),
4349
);
4450

‎apps/desktop/src/updates/DesktopUpdates.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ export const make = Effect.gen(function* () {
11441144

11451145
const settings = yield* desktopSettings.get;
11461146
const disabledReason = yield* resolveDisabledReason;
1147+
// A blocked nightly channel still lets the user switch back to stable, so it stays updatable.
1148+
yield* Ref.set(desktopState.canInstallUpdates, Option.isNone(disabledReason));
11471149
yield* setState(
11481150
yield* baseUpdateState(
11491151
settings.updateChannel,

‎apps/server/src/cli/config.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
383383
const shellEnvironmentPrepared = bootstrap?.shellEnvironmentPrepared;
384384
const desktopTelemetryFd = bootstrap?.desktopTelemetryFd;
385385
const desktopTelemetryControlFd = bootstrap?.desktopTelemetryControlFd;
386+
const desktopAppUpdate = bootstrap?.desktopAppUpdate;
386387
const desktopBrowserFd = bootstrap?.desktopBrowserFd;
387388
const desktopBrowserControlFd = bootstrap?.desktopBrowserControlFd;
388389
const resourceMonitorPath = bootstrap?.resourceMonitorPath;
@@ -516,6 +517,7 @@ export const resolveServerConfig = Effect.fn("config.resolveServerConfig")(funct
516517
...(shellEnvironmentPrepared === undefined ? {} : { shellEnvironmentPrepared }),
517518
desktopTelemetryFd,
518519
desktopTelemetryControlFd,
520+
...(desktopAppUpdate === undefined ? {} : { desktopAppUpdate }),
519521
desktopBrowserFd,
520522
desktopBrowserControlFd,
521523
resourceMonitorPath,

‎apps/server/src/config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class ServerConfig extends Context.Service<
9999
readonly shellEnvironmentPrepared?: boolean | undefined;
100100
readonly desktopTelemetryFd?: number | undefined;
101101
readonly desktopTelemetryControlFd?: number | undefined;
102+
readonly desktopAppUpdate?: boolean | undefined;
102103
readonly desktopBrowserFd?: number | undefined;
103104
readonly desktopBrowserControlFd?: number | undefined;
104105
readonly resourceMonitorPath?: string | undefined;

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ export const make = Effect.gen(function* () {
199199
launcherManaged: launcher.managed,
200200
});
201201
const serverInstallation = serverSelfUpdate === null ? yield* resolveServerInstallation : null;
202-
// Desktop and server ship together; a control fd guarantees requestDesktopUpdate support.
203-
202+
// The desktop reports whether it can install updates; requests travel over its control fd.
204203
const desktopAppUpdate =
205-
serverSelfUpdate === "desktop-managed" && serverConfig.desktopTelemetryControlFd !== undefined;
204+
serverSelfUpdate === "desktop-managed" &&
205+
serverConfig.desktopAppUpdate === true &&
206+
serverConfig.desktopTelemetryControlFd !== undefined;
206207

207208
const databaseMigration = databaseMigrationHead(serverConfig.dbPath);
208209
const descriptor: ExecutionEnvironmentDescriptor = {

‎packages/contracts/src/desktopBootstrap.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export const DesktopBackendBootstrap = Schema.Struct({
2626
otlpLogsUrl: Schema.optional(Schema.String),
2727
desktopTelemetryFd: Schema.optionalKey(PositiveInt),
2828
desktopTelemetryControlFd: Schema.optionalKey(PositiveInt),
29+
// Whether the spawning desktop app can install updates when the server requests one.
30+
desktopAppUpdate: Schema.optionalKey(Schema.Boolean),
2931
desktopBrowserFd: Schema.optionalKey(PositiveInt),
3032
desktopBrowserControlFd: Schema.optionalKey(PositiveInt),
3133
resourceMonitorPath: Schema.optionalKey(TrimmedNonEmptyString),

0 commit comments

Comments
 (0)