Skip to content

Commit 824474a

Browse files
t3dotggclaude
andcommitted
fix(desktop): explain how package installs get updates
On Linux deb, rpm, and AUR installs, APPIMAGE is unset, so automatic updates are off. The only reason said the AppImage was required, and the sidebar and settings tooltips still said "Up to date" or "Check for updates". The updater now reads the electron-builder package-type marker in resourcesPath and picks a reason that names the package manager and the upgrade command. The disabled state carries that reason in message, and the sidebar tooltip and aria-label show it. The AUR PKGBUILDs write the pacman marker. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent e40fec5 commit 824474a

8 files changed

Lines changed: 170 additions & 14 deletions

File tree

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
12
import { assert, describe, it } from "@effect/vitest";
23
import * as Cause from "effect/Cause";
34
import * as Deferred from "effect/Deferred";
45
import * as Duration from "effect/Duration";
56
import * as Effect from "effect/Effect";
67
import * as Fiber from "effect/Fiber";
8+
import * as FileSystem from "effect/FileSystem";
79
import * as Layer from "effect/Layer";
810
import * as Logger from "effect/Logger";
911
import * as Option from "effect/Option";
@@ -58,6 +60,91 @@ describe("DesktopUpdates", () => {
5860
);
5961
});
6062

63+
describe("getAutoUpdateDisabledReason", () => {
64+
const linuxPackaged = {
65+
isDevelopment: false,
66+
isPackaged: true,
67+
platform: "linux" as const,
68+
disabledByEnv: false,
69+
hasUpdateFeedConfig: true,
70+
};
71+
72+
it("tells Linux package installs how to update by package-type marker", () => {
73+
const reasonFor = (linuxPackageType: string | null) =>
74+
DesktopUpdates.getAutoUpdateDisabledReason({ ...linuxPackaged, linuxPackageType });
75+
76+
assert.equal(
77+
reasonFor("deb"),
78+
"T3 Code was installed with apt. Update it with: sudo apt update && sudo apt upgrade",
79+
);
80+
assert.equal(
81+
reasonFor("rpm"),
82+
"T3 Code was installed with dnf. Update it with: sudo dnf upgrade",
83+
);
84+
assert.equal(
85+
reasonFor("pacman"),
86+
"T3 Code was installed from the AUR. Update it with your AUR helper, for example: yay -Syu",
87+
);
88+
assert.equal(
89+
reasonFor("snap"),
90+
"T3 Code was installed by your system package manager. Update it with that package manager.",
91+
);
92+
assert.equal(
93+
reasonFor(null),
94+
"Automatic updates on Linux require running the AppImage build.",
95+
);
96+
});
97+
98+
it("ignores the marker when running as an AppImage or when an earlier reason applies", () => {
99+
assert.isNull(
100+
DesktopUpdates.getAutoUpdateDisabledReason({
101+
...linuxPackaged,
102+
linuxPackageType: "deb",
103+
appImage: "/tmp/T3-Code.AppImage",
104+
}),
105+
);
106+
assert.equal(
107+
DesktopUpdates.getAutoUpdateDisabledReason({
108+
...linuxPackaged,
109+
linuxPackageType: "deb",
110+
disabledByEnv: true,
111+
}),
112+
"Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting.",
113+
);
114+
});
115+
});
116+
117+
it.effect("reads the package-type marker and exposes the reason in the disabled state", () =>
118+
Effect.gen(function* () {
119+
const fileSystem = yield* FileSystem.FileSystem;
120+
const resourcesPath = yield* fileSystem.makeTempDirectoryScoped();
121+
yield* fileSystem.writeFileString(`${resourcesPath}/package-type`, "deb\n");
122+
const harness = makeHarness({ platform: "linux", resourcesPath });
123+
124+
yield* Effect.scoped(
125+
Effect.gen(function* () {
126+
const updates = yield* DesktopUpdates.DesktopUpdates;
127+
yield* updates.configure;
128+
129+
const expected =
130+
"T3 Code was installed with apt. Update it with: sudo apt update && sudo apt upgrade";
131+
const state = yield* updates.getState;
132+
assert.equal(state.enabled, false);
133+
assert.equal(state.status, "disabled");
134+
assert.equal(state.message, expected);
135+
assert.equal(harness.sentStates.at(-1)?.message, expected);
136+
// Remote requests and the app menu read this instead of the state.
137+
assert.equal(Option.getOrNull(yield* updates.disabledReason), expected);
138+
assert.equal(harness.listenerCount(), 0);
139+
140+
const nightly = yield* updates.setChannel("nightly");
141+
assert.equal(nightly.status, "disabled");
142+
assert.equal(nightly.message, expected);
143+
}),
144+
).pipe(Effect.provide(Layer.merge(TestClock.layer(), harness.layer)));
145+
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
146+
);
147+
61148
it.effect("configures the updater and runs startup checks on the test clock", () => {
62149
const harness = makeHarness();
63150

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

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,19 @@ function parseAppUpdateYml(raw: string): Effect.Effect<Option.Option<AppUpdateYm
210210
);
211211
}
212212

213+
/** Idle state when updates run, or a disabled state that carries the reason
214+
in `message` so clients can show it instead of "up to date". */
213215
function createBaseUpdateState(
214216
channel: DesktopUpdateChannel,
215-
enabled: boolean,
217+
disabledReason: Option.Option<string>,
216218
environment: DesktopEnvironment.DesktopEnvironment["Service"],
217219
): DesktopUpdateState {
220+
const enabled = Option.isNone(disabledReason);
218221
return {
219222
...createInitialDesktopUpdateState(environment.appVersion, environment.runtimeInfo, channel),
220223
enabled,
221224
status: enabled ? "idle" : "disabled",
225+
message: Option.getOrNull(disabledReason),
222226
};
223227
}
224228

@@ -244,11 +248,36 @@ function shouldBroadcastDownloadProgress(
244248
return nextStep !== previousStep || nextPercent === 100;
245249
}
246250

247-
function getAutoUpdateDisabledReason(args: {
251+
/**
252+
* How a Linux install that is not running as an AppImage gets updates. The
253+
* marker is the electron-builder `package-type` file next to the app
254+
* resources; the deb and rpm builds write it, and the AUR PKGBUILDs write
255+
* `pacman`. No marker means an extracted AppImage or an unknown layout.
256+
*/
257+
function getLinuxPackageUpdateReason(packageType: string | null): string {
258+
switch (packageType) {
259+
case null:
260+
return "Automatic updates on Linux require running the AppImage build.";
261+
case "deb":
262+
return "T3 Code was installed with apt. Update it with: sudo apt update && sudo apt upgrade";
263+
case "rpm":
264+
return "T3 Code was installed with dnf. Update it with: sudo dnf upgrade";
265+
case "pacman":
266+
return "T3 Code was installed from the AUR. Update it with your AUR helper, for example: yay -Syu";
267+
default:
268+
return "T3 Code was installed by your system package manager. Update it with that package manager.";
269+
}
270+
}
271+
272+
/** Why automatic updates are off, or null when they can run. Reasons are
273+
checked in priority order; `linuxPackageType` only matters on Linux
274+
without `APPIMAGE`. Exported for tests. */
275+
export function getAutoUpdateDisabledReason(args: {
248276
isDevelopment: boolean;
249277
isPackaged: boolean;
250278
platform: NodeJS.Platform;
251279
appImage?: string | undefined;
280+
linuxPackageType: string | null;
252281
disabledByEnv: boolean;
253282
hasUpdateFeedConfig: boolean;
254283
}): string | null {
@@ -262,7 +291,7 @@ function getAutoUpdateDisabledReason(args: {
262291
return "Automatic updates are disabled by the T3CODE_DISABLE_AUTO_UPDATE setting.";
263292
}
264293
if (args.platform === "linux" && !args.appImage) {
265-
return "Automatic updates on Linux require running the AppImage build.";
294+
return getLinuxPackageUpdateReason(args.linuxPackageType);
266295
}
267296
return null;
268297
}
@@ -335,14 +364,29 @@ export const make = Effect.gen(function* () {
335364
Effect.map((appUpdateYmlConfig) => Option.isSome(appUpdateYmlConfig) || config.mockUpdates),
336365
);
337366

367+
// Only Linux package installs carry the marker. A missing, unreadable, or
368+
// blank file means no marker.
369+
const readLinuxPackageType: Effect.Effect<Option.Option<string>> =
370+
environment.platform === "linux" && environment.isPackaged
371+
? fileSystem
372+
.readFileString(environment.path.join(environment.resourcesPath, "package-type"))
373+
.pipe(
374+
Effect.map((raw) => raw.trim()),
375+
Effect.option,
376+
Effect.map(Option.filter((packageType) => packageType.length > 0)),
377+
)
378+
: Effect.succeedNone;
379+
338380
const resolveDisabledReason = Effect.gen(function* () {
339381
const hasFeedConfig = yield* hasUpdateFeedConfig;
382+
const linuxPackageType = yield* readLinuxPackageType;
340383
return Option.fromNullishOr(
341384
getAutoUpdateDisabledReason({
342385
isDevelopment: environment.isDevelopment,
343386
isPackaged: environment.isPackaged,
344387
platform: environment.platform,
345388
appImage: Option.getOrUndefined(config.appImagePath),
389+
linuxPackageType: Option.getOrNull(linuxPackageType),
346390
disabledByEnv: config.disableAutoUpdate,
347391
hasUpdateFeedConfig: hasFeedConfig,
348392
}),
@@ -389,8 +433,6 @@ export const make = Effect.gen(function* () {
389433
});
390434
});
391435

392-
const shouldEnableAutoUpdates = resolveDisabledReason.pipe(Effect.map(Option.isNone));
393-
394436
const checkForUpdates = Effect.fn("desktop.updates.checkForUpdates")(function* (
395437
reason: string,
396438
actionReservation: "acquire" | "held" = "acquire",
@@ -878,9 +920,9 @@ export const make = Effect.gen(function* () {
878920
}
879921

880922
const settings = yield* desktopSettings.get;
881-
const enabled = yield* shouldEnableAutoUpdates;
882-
yield* setState(createBaseUpdateState(settings.updateChannel, enabled, environment));
883-
if (!enabled) {
923+
const disabledReason = yield* resolveDisabledReason;
924+
yield* setState(createBaseUpdateState(settings.updateChannel, disabledReason, environment));
925+
if (Option.isSome(disabledReason)) {
884926
return;
885927
}
886928
yield* Ref.set(updaterConfiguredRef, true);
@@ -949,10 +991,10 @@ export const make = Effect.gen(function* () {
949991
),
950992
);
951993

952-
const enabled = yield* shouldEnableAutoUpdates;
953-
yield* setState(createBaseUpdateState(nextChannel, enabled, environment));
994+
const disabledReason = yield* resolveDisabledReason;
995+
yield* setState(createBaseUpdateState(nextChannel, disabledReason, environment));
954996

955-
if (!enabled || !(yield* Ref.get(updaterConfiguredRef))) {
997+
if (Option.isSome(disabledReason) || !(yield* Ref.get(updaterConfiguredRef))) {
956998
return yield* Ref.get(updateStateRef);
957999
}
9581000

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export interface UpdatesHarnessOptions {
3232
readonly stopBackend?: Effect.Effect<void>;
3333
readonly startBackend?: Effect.Effect<void>;
3434
readonly env?: Record<string, string | undefined>;
35+
readonly platform?: NodeJS.Platform;
36+
/** Directory the updater reads `package-type` from on Linux. */
37+
readonly resourcesPath?: string;
3538
}
3639

3740
export function makeHarness(options: UpdatesHarnessOptions = {}) {
@@ -145,12 +148,12 @@ export function makeHarness(options: UpdatesHarnessOptions = {}) {
145148
const environmentLayer = DesktopEnvironment.layer({
146149
dirname: "/repo/apps/desktop/src",
147150
homeDirectory: `/tmp/t3-desktop-updates-home-${process.pid}`,
148-
platform: "darwin",
151+
platform: options.platform ?? "darwin",
149152
processArch: "x64",
150153
appVersion: "1.2.3",
151154
appPath: "/repo",
152155
isPackaged: true,
153-
resourcesPath: "/missing/resources",
156+
resourcesPath: options.resourcesPath ?? "/missing/resources",
154157
runningUnderArm64Translation: false,
155158
}).pipe(
156159
Layer.provide(

‎apps/web/src/components/desktopUpdate.logic.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,15 @@ describe("getDesktopUpdateButtonTooltip", () => {
346346
"Up to date",
347347
);
348348
});
349+
350+
it("shows the disabled reason instead of 'Up to date' when updates are off", () => {
351+
const disabled: DesktopUpdateState = { ...baseState, enabled: false, status: "disabled" };
352+
expect(
353+
getDesktopUpdateButtonTooltip({
354+
...disabled,
355+
message: "T3 Code was installed with dnf. Update it with: sudo dnf upgrade",
356+
}),
357+
).toBe("T3 Code was installed with dnf. Update it with: sudo dnf upgrade");
358+
expect(getDesktopUpdateButtonTooltip(disabled)).toBe("Automatic updates are off.");
359+
});
349360
});

‎apps/web/src/components/desktopUpdate.logic.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export function getDesktopUpdateButtonTooltip(state: DesktopUpdateState): string
9494
}
9595
return state.message ?? "Update failed";
9696
}
97+
if (state.status === "disabled") {
98+
// The main process puts the disabled reason in `message`, for example how
99+
// a Linux package install gets updates.
100+
return state.message ?? "Automatic updates are off.";
101+
}
97102
return "Up to date";
98103
}
99104

‎apps/web/src/components/sidebar/SidebarUpdatePill.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ function SidebarUpdateControl() {
149149
: "Update available"
150150
: showCheckIcon
151151
? "Checking for updates…"
152-
: "Check for updates";
152+
: state?.status === "disabled"
153+
? getDesktopUpdateButtonTooltip(state)
154+
: "Check for updates";
153155
const disabled = showCheckIcon
154156
? true
155157
: showUpdateDetails

‎packaging/aur/t3code-bin/PKGBUILD‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ package() {
7070
cp -a --no-preserve=ownership "$srcdir/squashfs-root/." "$pkgdir/opt/$pkgname/"
7171
chmod -R u=rwX,go=rX "$pkgdir/opt/$pkgname"
7272
chmod 4755 "$pkgdir/opt/$pkgname/chrome-sandbox"
73+
# electron-updater package-type marker; the app reads it to explain how this install gets updates.
74+
printf 'pacman\n' > "$pkgdir/opt/$pkgname/resources/package-type"
75+
chmod 644 "$pkgdir/opt/$pkgname/resources/package-type"
7376

7477
install -Dm755 /dev/stdin "$pkgdir/usr/bin/t3code" <<'EOF'
7578
#!/bin/sh

‎packaging/aur/t3code-nightly-bin/PKGBUILD‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ package() {
7171
cp -a --no-preserve=ownership "$srcdir/squashfs-root/." "$pkgdir/opt/$pkgname/"
7272
chmod -R u=rwX,go=rX "$pkgdir/opt/$pkgname"
7373
chmod 4755 "$pkgdir/opt/$pkgname/chrome-sandbox"
74+
# electron-updater package-type marker; the app reads it to explain how this install gets updates.
75+
printf 'pacman\n' > "$pkgdir/opt/$pkgname/resources/package-type"
76+
chmod 644 "$pkgdir/opt/$pkgname/resources/package-type"
7477

7578
install -Dm755 /dev/stdin "$pkgdir/usr/bin/t3code-nightly" <<'EOF'
7679
#!/bin/sh

0 commit comments

Comments
 (0)