Skip to content

Commit fd073ca

Browse files
fix(desktop): bump Clerk Electron SDK to 0.0.24 and register t3code:// scheme on Linux
@clerk/electron 0.0.24 holds Electron's single-instance lock so OAuth deep-link callbacks reach the running app instead of being swallowed by a second instance. Defer to the SDK's lock and gate bootstrap on the bridge's isPrimaryInstance instead of acquiring our own lock after bridge creation. Register the t3code/t3code-dev schemes in the Linux electron-builder config so the generated .desktop entry carries MimeType=x-scheme-handler/t3code; and %U in Exec, letting browsers hand OAuth callbacks to the app. Also aligns the whole Clerk catalog (backend, clerk-js, expo, react, shared) so no internal Clerk package is duplicated. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 4ba4871 commit fd073ca

12 files changed

Lines changed: 142 additions & 73 deletions

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ const makeElectronAppLayer = (calls: ElectronAppCalls) =>
5454
calls.setAboutPanelOptions.push(options);
5555
}),
5656
setAppUserModelId: () => Effect.void,
57-
requestSingleInstanceLock: Effect.succeed(true),
5857
getAppMetrics: Effect.succeed([]),
5958
isDefaultProtocolClient: () => Effect.succeed(false),
6059
setAsDefaultProtocolClient: () => Effect.succeed(true),

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

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ vi.mock("@clerk/electron/storage", () => ({
2222
storage: storageMock,
2323
}));
2424

25+
import * as Exit from "effect/Exit";
26+
import * as ElectronApp from "../electron/ElectronApp.ts";
27+
import * as ElectronWindow from "../electron/ElectronWindow.ts";
2528
import * as DesktopClerk from "./DesktopClerk.ts";
2629
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
2730

@@ -56,7 +59,7 @@ describe("DesktopClerk", () => {
5659
it.effect("acquires and releases the SDK bridge with the layer", () => {
5760
const cleanup = vi.fn();
5861
storageMock.mockReturnValue(storageAdapter);
59-
createClerkBridgeMock.mockReturnValue({ cleanup });
62+
createClerkBridgeMock.mockReturnValue({ cleanup, isPrimaryInstance: true });
6063

6164
return Effect.gen(function* () {
6265
yield* Effect.scoped(Layer.build(makeDesktopClerkLayer()));
@@ -124,11 +127,67 @@ describe("DesktopClerk", () => {
124127
});
125128
});
126129

130+
it.effect("registers the second-instance handler in the primary instance", () => {
131+
storageMock.mockReturnValue(storageAdapter);
132+
createClerkBridgeMock.mockReturnValue({ cleanup: vi.fn(), isPrimaryInstance: true });
133+
const quit = vi.fn();
134+
const registeredEvents: string[] = [];
135+
const electronApp = {
136+
quit: Effect.sync(quit),
137+
on: (eventName: string) =>
138+
Effect.sync(() => {
139+
registeredEvents.push(eventName);
140+
}),
141+
} as unknown as ElectronApp.ElectronApp["Service"];
142+
const electronWindow = {} as ElectronWindow.ElectronWindow["Service"];
143+
144+
return Effect.gen(function* () {
145+
const clerk = yield* DesktopClerk.DesktopClerk;
146+
const exit = yield* Effect.exit(Effect.scoped(clerk.configure));
147+
148+
assert.isTrue(Exit.isSuccess(exit));
149+
assert.equal(quit.mock.calls.length, 0);
150+
assert.deepEqual(registeredEvents, ["second-instance"]);
151+
}).pipe(
152+
Effect.provide(makeDesktopClerkLayer()),
153+
Effect.provideService(ElectronApp.ElectronApp, electronApp),
154+
Effect.provideService(ElectronWindow.ElectronWindow, electronWindow),
155+
);
156+
});
157+
158+
it.effect("quits and interrupts startup in a secondary instance", () => {
159+
storageMock.mockReturnValue(storageAdapter);
160+
createClerkBridgeMock.mockReturnValue({ cleanup: vi.fn(), isPrimaryInstance: false });
161+
const quit = vi.fn();
162+
const registeredEvents: string[] = [];
163+
const electronApp = {
164+
quit: Effect.sync(quit),
165+
on: (eventName: string) =>
166+
Effect.sync(() => {
167+
registeredEvents.push(eventName);
168+
}),
169+
} as unknown as ElectronApp.ElectronApp["Service"];
170+
const electronWindow = {} as ElectronWindow.ElectronWindow["Service"];
171+
172+
return Effect.gen(function* () {
173+
const clerk = yield* DesktopClerk.DesktopClerk;
174+
const exit = yield* Effect.exit(Effect.scoped(clerk.configure));
175+
176+
assert.isTrue(Exit.hasInterrupts(exit));
177+
assert.equal(quit.mock.calls.length, 1);
178+
assert.deepEqual(registeredEvents, []);
179+
}).pipe(
180+
Effect.provide(makeDesktopClerkLayer()),
181+
Effect.provideService(ElectronApp.ElectronApp, electronApp),
182+
Effect.provideService(ElectronWindow.ElectronWindow, electronWindow),
183+
);
184+
});
185+
127186
it.each([
128187
{ isDevelopment: true, scheme: "t3code-dev" },
129188
{ isDevelopment: false, scheme: "t3code" },
130189
])("configures the SDK with the $scheme renderer origin", ({ isDevelopment, scheme }) => {
131-
const bridge = { cleanup: vi.fn() };
190+
const bridge = { cleanup: vi.fn(), isPrimaryInstance: true };
132191
storageMock.mockReturnValue(storageAdapter);
133192
createClerkBridgeMock.mockReturnValue(bridge);
134193

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function createDesktopClerkBridge(stateDir: string, isDevelopment: boolea
8484

8585
export const make = Effect.gen(function* () {
8686
const environment = yield* DesktopEnvironment.DesktopEnvironment;
87-
yield* Effect.acquireRelease(
87+
const bridge = yield* Effect.acquireRelease(
8888
Effect.try({
8989
try: () => createDesktopClerkBridge(environment.stateDir, environment.isDevelopment),
9090
catch: (cause) =>
@@ -113,7 +113,12 @@ export const make = Effect.gen(function* () {
113113
const context = yield* Effect.context<ElectronWindow.ElectronWindow>();
114114
const runPromise = Effect.runPromiseWith(context);
115115

116-
if (!(yield* electronApp.requestSingleInstanceLock)) {
116+
// The SDK bridge holds Electron's single-instance lock (acquired at
117+
// bridge creation) so OAuth deep-link callbacks on Windows/Linux are
118+
// forwarded to the running app. In a secondary instance the bridge has
119+
// already begun quitting the app; app.quit() is asynchronous, so stop
120+
// bootstrap here before whenReady can fire.
121+
if (!bridge.isPrimaryInstance) {
117122
yield* electronApp.quit;
118123
return yield* Effect.interrupt;
119124
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ describe("DesktopLifecycle", () => {
2929
setName: () => Effect.void,
3030
setAboutPanelOptions: () => Effect.void,
3131
setAppUserModelId: () => Effect.void,
32-
requestSingleInstanceLock: Effect.succeed(true),
3332
getAppMetrics: Effect.succeed([]),
3433
isDefaultProtocolClient: () => Effect.succeed(false),
3534
setAsDefaultProtocolClient: () => Effect.succeed(true),

‎apps/desktop/src/electron/ElectronApp.test.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const {
1414
quitMock,
1515
relaunchMock,
1616
removeListenerMock,
17-
requestSingleInstanceLockMock,
1817
setAboutPanelOptionsMock,
1918
setAppUserModelIdMock,
2019
setAsDefaultProtocolClientMock,
@@ -35,7 +34,6 @@ const {
3534
quitMock: vi.fn(),
3635
relaunchMock: vi.fn(),
3736
removeListenerMock: vi.fn(),
38-
requestSingleInstanceLockMock: vi.fn(() => true),
3937
setAboutPanelOptionsMock: vi.fn(),
4038
setAppUserModelIdMock: vi.fn(),
4139
setAsDefaultProtocolClientMock: vi.fn(() => true),
@@ -67,7 +65,6 @@ vi.mock("electron", () => ({
6765
quit: quitMock,
6866
relaunch: relaunchMock,
6967
removeListener: removeListenerMock,
70-
requestSingleInstanceLock: requestSingleInstanceLockMock,
7168
runningUnderARM64Translation: false,
7269
setAboutPanelOptions: setAboutPanelOptionsMock,
7370
setAsDefaultProtocolClient: setAsDefaultProtocolClientMock,

‎apps/desktop/src/electron/ElectronApp.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export class ElectronApp extends Context.Service<
5656
options: Electron.AboutPanelOptionsOptions,
5757
) => Effect.Effect<void>;
5858
readonly setAppUserModelId: (id: string) => Effect.Effect<void>;
59-
readonly requestSingleInstanceLock: Effect.Effect<boolean>;
6059
readonly getAppMetrics: Effect.Effect<ReadonlyArray<Electron.ProcessMetric>>;
6160
readonly isDefaultProtocolClient: (protocol: string) => Effect.Effect<boolean>;
6261
readonly setAsDefaultProtocolClient: (
@@ -153,7 +152,6 @@ export const make = ElectronApp.of({
153152
Effect.sync(() => {
154153
Electron.app.setAppUserModelId(id);
155154
}),
156-
requestSingleInstanceLock: Effect.sync(() => Electron.app.requestSingleInstanceLock()),
157155
getAppMetrics: Effect.sync(() => Electron.app.getAppMetrics()),
158156
isDefaultProtocolClient: (protocol) =>
159157
Effect.sync(() => Electron.app.isDefaultProtocolClient(protocol)),

‎apps/desktop/src/telemetry/DesktopTelemetryPublisher.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ function makeElectronAppLayer(
3434
setName: () => Effect.void,
3535
setAboutPanelOptions: () => Effect.void,
3636
setAppUserModelId: () => Effect.void,
37-
requestSingleInstanceLock: Effect.succeed(true),
3837
getAppMetrics: Effect.sync(() => {
3938
onMetricsRead();
4039
return metrics;

‎apps/desktop/src/window/DesktopApplicationMenu.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const electronAppLayer = Layer.succeed(ElectronApp.ElectronApp, {
3939
setName: () => Effect.void,
4040
setAboutPanelOptions: () => Effect.void,
4141
setAppUserModelId: () => Effect.void,
42-
requestSingleInstanceLock: Effect.succeed(true),
4342
getAppMetrics: Effect.succeed([]),
4443
isDefaultProtocolClient: () => Effect.succeed(false),
4544
setAsDefaultProtocolClient: () => Effect.succeed(true),

0 commit comments

Comments
 (0)