@devries-cameron20 / t3code Mirror · read-only / commits / 1e659c9744
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 23:15 UTC

fix(desktop): register Windows OAuth callbacks with the app entry point (#15995)

Co-authored-by: AskPlays <adrian.skalevag@online.no> Co-authored-by: Julius Marminge <julius0216@outlook.com>

AskPlays committed Oct 20, 2026 at 06:11 UTC 1e659c9744b14923978591d8c65c6faea8f70758
2 files changed +82 -2
apps/desktop/src/app/DesktopClerk.test.ts
+68 -2
@@ -1,6 +1,7 @@
1 // @effect-diagnostics nodeBuiltinImport:off globalFetchInEffect:off - Hosted handoff test uses a real localhost listener without an OpenAI account.
2 import * as NodeHttp from "node:http";
3 -import * as NodePath from "@effect/platform-node/NodePath";
3 +import * as NodePath from "node:path";
4 +import * as PlatformNodePath from "@effect/platform-node/NodePath";
5 import { codexAuthHandoffUrl, readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff";
6 import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
7 import * as HostProcess from "@t3tools/shared/HostProcess";
@@ -59,11 +60,15 @@ const layerDesktopClerk = (
60 copyText: () => Effect.void,
61 },
62 listeners = new Map<string, (...args: unknown[]) => void>(),
63 + isPackaged = false,
64 ) => {
65 const environment = DesktopEnvironment.DesktopEnvironment.of({
66 stateDir: "/tmp/t3-state",
67 isDevelopment,
68 appDataDirectory: "/tmp/app-data",
69 + isPackaged,
70 + dirname: platform === "win32" ? String.raw`C:\T3 Code\dist-electron` : "/tmp/dist-electron",
71 + path: platform === "win32" ? NodePath.win32 : NodePath.posix,
72 platform,
73 } as unknown as DesktopEnvironment.DesktopEnvironment["Service"]);
74
@@ -95,7 +100,7 @@ const layerDesktopClerk = (
100 return DesktopClerk.layer.pipe(
101 Layer.provide(
102 Layer.mergeAll(
98 - NodePath.layerPosix,
103 + PlatformNodePath.layerPosix,
104 Layer.succeed(DesktopEnvironment.DesktopEnvironment, environment),
105 Layer.succeed(ElectronApp.ElectronApp, electronApp),
106 Layer.succeed(ElectronShell.ElectronShell, shell),
@@ -112,6 +117,67 @@ describe("DesktopClerk", () => {
117 storageMock.mockReset();
118 });
119
120 + it.effect.each([
121 + { platform: "win32", isPackaged: false, isDevelopment: false, registers: true },
122 + { platform: "win32", isPackaged: false, isDevelopment: true, registers: false },
123 + { platform: "win32", isPackaged: true, isDevelopment: false, registers: false },
124 + { platform: "darwin", isPackaged: false, isDevelopment: false, registers: false },
125 + { platform: "linux", isPackaged: false, isDevelopment: false, registers: false },
126 + ] as const)(
127 + "registers an entry point only for unpackaged non-development Windows ($platform, packaged=$isPackaged, development=$isDevelopment)",
128 + ({ platform, isPackaged, isDevelopment, registers }) => {
129 + const events: string[] = [];
130 + storageMock.mockReturnValue(storageAdapter);
131 + createClerkBridgeMock.mockImplementation(() => {
132 + events.push("bridge");
133 + return { cleanup: vi.fn() };
134 + });
135 + const setAsDefaultProtocolClient = vi.fn(() =>
136 + Effect.sync(() => {
137 + events.push("register");
138 + return true;
139 + }),
140 + );
141 + const electronApp = {
142 + on: () => Effect.void,
143 + setAsDefaultProtocolClient,
144 + } as unknown as ElectronApp.ElectronApp["Service"];
145 +
146 + return Effect.gen(function* () {
147 + const clerk = yield* DesktopClerk.DesktopClerk;
148 + yield* clerk.configure;
149 +
150 + assert.deepEqual(
151 + setAsDefaultProtocolClient.mock.calls,
152 + registers
153 + ? [["t3code", process.execPath, [String.raw`C:\T3 Code\dist-electron\main.cjs`]]]
154 + : [],
155 + );
156 + assert.deepEqual(events, registers ? ["bridge", "register"] : ["bridge"]);
157 + }).pipe(
158 + Effect.scoped,
159 + Effect.provide(
160 + layerDesktopClerk(
161 + isDevelopment,
162 + [],
163 + platform,
164 + undefined,
165 + undefined,
166 + undefined,
167 + isPackaged,
168 + ),
169 + ),
170 + Effect.provideService(ElectronApp.ElectronApp, electronApp),
171 + Effect.provideService(
172 + ElectronWindow.ElectronWindow,
173 + {} as ElectronWindow.ElectronWindow["Service"],
174 + ),
175 + Effect.provideService(DesktopWebLinks.DesktopWebLinks, ignoreWebLinks),
176 + Effect.provideService(HostProcess.Arguments, ["electron"]),
177 + );
178 + },
179 + );
180 +
181 it.effect("acquires and releases the SDK bridge with the layer", () => {
182 const cleanup = vi.fn();
183 const events: string[] = [];
apps/desktop/src/app/DesktopClerk.ts
+14
@@ -151,6 +151,20 @@ export const make = Effect.gen(function* () {
151 const context = yield* Effect.context<ElectronWindow.ElectronWindow>();
152 const runPromise = Effect.runPromiseWith(context);
153
154 + // Clerk's bare scheme registration omits the app entry on unpackaged Windows.
155 + // Development callbacks also need dev server environment this command cannot restore.
156 + if (
157 + !environment.isPackaged &&
158 + !environment.isDevelopment &&
159 + environment.platform === "win32"
160 + ) {
161 + yield* electronApp.setAsDefaultProtocolClient(
162 + ElectronProtocol.getDesktopScheme(environment.isDevelopment),
163 + process.execPath,
164 + [environment.path.join(environment.dirname, "main.cjs")],
165 + );
166 + }
167 +
168 const startProviderAuthHandoff = (value: string | undefined) => {
169 if (!value) return false;
170 const request = readCodexAuthHandoff(value, environment.isDevelopment);