Compare commits

...

1 Commits

Author SHA1 Message Date
Hona 3c945efe24 fix(desktop): keep cold-start deep links 2026-08-26 17:01:26 +00:00
3 changed files with 20 additions and 2 deletions
@@ -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"])
})
})
@@ -0,0 +1,3 @@
export function deepLinksFromArgv(argv: string[]) {
return argv.filter((arg) => arg.startsWith("opencode://"))
}
+3 -2
View File
@@ -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)