Skip to content

Commit fd46d74

Browse files
only21milclaude
andcommitted
fix(desktop): a settings relaunch no longer replays the link that launched the app
On Linux and Windows a t3code:// link that cold-launches the app arrives in argv, and startup acts on it. Relaunching for a settings change passed the whole argv on, so the new process ran that link again: a spent pairing token, a repeated prompt, or a second ChatGPT sign-in. Relaunch now drops arguments in the app's own link scheme. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 54c5f25 commit fd46d74

2 files changed

Lines changed: 56 additions & 3 deletions

File tree

‎apps/desktop/src/app/DesktopLifecycle.test.ts‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as Layer from "effect/Layer";
55
import * as Ref from "effect/Ref";
66
import * as TestClock from "effect/testing/TestClock";
77

8+
import * as HostProcess from "@t3tools/shared/HostProcess";
9+
810
import type * as Electron from "electron";
911

1012
import * as ElectronApp from "../electron/ElectronApp.ts";
@@ -20,6 +22,7 @@ function layerElectronApp(
2022
appListeners: Map<string, (...args: readonly unknown[]) => void>,
2123
quit: Effect.Effect<void> = Effect.void,
2224
exit: (code: number) => Effect.Effect<void> = () => Effect.void,
25+
relaunch: (options: Electron.RelaunchOptions) => Effect.Effect<void> = () => Effect.void,
2326
) {
2427
const registerListener = (eventName: string, listener: (...args: readonly unknown[]) => void) =>
2528
Effect.acquireRelease(
@@ -40,7 +43,7 @@ function layerElectronApp(
4043
requestSingleInstanceLock: Effect.succeed(true),
4144
quit,
4245
exit,
43-
relaunch: () => Effect.void,
46+
relaunch,
4447
setPath: () => Effect.void,
4548
setName: () => Effect.void,
4649
setAboutPanelOptions: () => Effect.void,
@@ -223,6 +226,50 @@ describe("DesktopLifecycle", () => {
223226
}),
224227
);
225228

229+
it.effect("relaunches without the app link that launched it", () =>
230+
Effect.gen(function* () {
231+
const relaunched = yield* Deferred.make<Electron.RelaunchOptions>();
232+
const layerEnvironment = Layer.succeed(DesktopEnvironment.DesktopEnvironment, {
233+
platform: "linux",
234+
isDevelopment: false,
235+
} as DesktopEnvironment.DesktopEnvironment["Service"]);
236+
const layer = DesktopLifecycle.layer.pipe(
237+
Layer.provideMerge(
238+
layerElectronApp(
239+
new Map(),
240+
Effect.void,
241+
() => Effect.void,
242+
(options) => Deferred.succeed(relaunched, options).pipe(Effect.asVoid),
243+
),
244+
),
245+
Layer.provideMerge(layerElectronTheme),
246+
Layer.provideMerge(layerElectronWindow()),
247+
Layer.provideMerge(layerDesktopWindow()),
248+
Layer.provideMerge(layerEnvironment),
249+
Layer.provideMerge(DesktopShutdown.layer),
250+
Layer.provideMerge(DesktopState.layer),
251+
);
252+
253+
const options = yield* Effect.gen(function* () {
254+
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
255+
yield* (yield* DesktopShutdown.DesktopShutdown).markComplete;
256+
yield* lifecycle.relaunch("network access changed");
257+
return yield* Deferred.await(relaunched);
258+
}).pipe(
259+
Effect.provide(layer),
260+
Effect.provideService(HostProcess.ExecutablePath, "/opt/T3 Code/t3code"),
261+
Effect.provideService(HostProcess.Arguments, [
262+
"/opt/T3 Code/t3code",
263+
"--no-sandbox",
264+
"T3CODE://pair?token=spent",
265+
"t3code://new?prompt=hello",
266+
]),
267+
);
268+
269+
assert.deepEqual(options, { execPath: "/opt/T3 Code/t3code", args: ["--no-sandbox"] });
270+
}),
271+
);
272+
226273
it.effect("exits on a repeated quit only once shutdown has stalled", () =>
227274
Effect.gen(function* () {
228275
const appListeners = new Map<string, (...args: readonly unknown[]) => void>();

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ import * as Scope from "effect/Scope";
99

1010
import type * as Electron from "electron";
1111

12+
import * as HostProcess from "@t3tools/shared/HostProcess";
13+
1214
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
1315
import { makeComponentLogger } from "./DesktopObservability.ts";
1416
import * as DesktopShutdown from "./DesktopShutdown.ts";
1517
import * as ElectronApp from "../electron/ElectronApp.ts";
18+
import * as ElectronProtocol from "../electron/ElectronProtocol.ts";
1619
import * as ElectronTheme from "../electron/ElectronTheme.ts";
1720
import * as ElectronWindow from "../electron/ElectronWindow.ts";
1821
import * as DesktopState from "./DesktopState.ts";
@@ -223,9 +226,12 @@ export const make = DesktopLifecycle.of({
223226
yield* electronApp.exit(75);
224227
return;
225228
}
229+
// Startup already acted on the app link that launched it; passing it on replays it.
230+
const appLinkPrefix = `${ElectronProtocol.getDesktopScheme(environment.isDevelopment)}:`;
231+
const args = yield* HostProcess.Arguments;
226232
yield* electronApp.relaunch({
227-
execPath: process.execPath,
228-
args: process.argv.slice(1),
233+
execPath: yield* HostProcess.ExecutablePath,
234+
args: args.slice(1).filter((arg) => !arg.toLowerCase().startsWith(appLinkPrefix)),
229235
});
230236
yield* electronApp.exit(0);
231237
}).pipe(

0 commit comments

Comments
 (0)