diff --git a/packages/desktop/src/main/lifecycle/deep-links.test.ts b/packages/desktop/src/main/lifecycle/deep-links.test.ts new file mode 100644 index 000000000000..9abbdc7c8dd5 --- /dev/null +++ b/packages/desktop/src/main/lifecycle/deep-links.test.ts @@ -0,0 +1,14 @@ +import { describe, expect, test } from "bun:test" +import { deepLinksFromArgv } from "./deep-links" + +describe("deep links from argv", () => { + test("finds a cold-start protocol URL", () => { + expect(deepLinksFromArgv(["opencode", "--flag", "opencode://session/123"])).toEqual(["opencode://session/123"]) + }) + + test("keeps every protocol URL and ignores other arguments", () => { + expect( + deepLinksFromArgv(["opencode", "opencode://project/one", "https://opencode.ai", "opencode://project/two"]), + ).toEqual(["opencode://project/one", "opencode://project/two"]) + }) +}) diff --git a/packages/desktop/src/main/lifecycle/deep-links.ts b/packages/desktop/src/main/lifecycle/deep-links.ts new file mode 100644 index 000000000000..7d7075e6a609 --- /dev/null +++ b/packages/desktop/src/main/lifecycle/deep-links.ts @@ -0,0 +1,3 @@ +export function deepLinksFromArgv(argv: string[]) { + return argv.filter((arg) => arg.startsWith("opencode://")) +} diff --git a/packages/desktop/src/main/lifecycle/index.ts b/packages/desktop/src/main/lifecycle/index.ts index ac9f6373c33f..69abd8229a41 100644 --- a/packages/desktop/src/main/lifecycle/index.ts +++ b/packages/desktop/src/main/lifecycle/index.ts @@ -9,6 +9,7 @@ import { DesktopLogging, scoped } from "../native/logging" import { safeWebContentsURL } from "../windows/state" import { getLastFocusedWindow, makeMainWindows, setAppQuitting, setRelaunchHandler } from "../windows" import { acquireApplicationLock, configureApplication } from "./environment" +import { deepLinksFromArgv } from "./deep-links" import { Shutdown } from "./shutdown" export interface Interface { @@ -29,7 +30,7 @@ const runtime = Layer.effect( const windows = yield* makeMainWindows() const createWindow = windows.create const restoreWindows = windows.restore - const pendingDeepLinks: string[] = [] + const pendingDeepLinks = process.platform === "darwin" ? [] : deepLinksFromArgv(process.argv) let shutdownReady = false const prepareToRestart = shutdown.run.pipe(Effect.ensuring(Effect.sync(() => (shutdownReady = true)))) const emitDeepLinks = (urls: string[]) => { @@ -52,7 +53,7 @@ const runtime = Layer.effect( ) } const secondInstance = (_event: Event, argv: string[]) => { - const urls = argv.filter((arg) => arg.startsWith("opencode://")) + const urls = deepLinksFromArgv(argv) if (urls.length) { runFork(Effect.logInfo("deep link received via second-instance", { urls })) emitDeepLinks(urls)