From 2af326606c936380c303bf56506e3c8bed04b0eb Mon Sep 17 00:00:00 2001 From: Hegyi Áron Ferenc Date: Thu, 29 Jan 2026 08:09:53 +0100 Subject: feat(desktop): Add desktop deep link (#10072) Co-authored-by: Brendan Allan --- packages/desktop/src/index.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'packages/desktop/src') diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index 344c6be8d..2e7ca136a 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -3,6 +3,7 @@ import "./webview-zoom" import { render } from "solid-js/web" import { AppBaseProviders, AppInterface, PlatformProvider, Platform } from "@opencode-ai/app" import { open, save } from "@tauri-apps/plugin-dialog" +import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link" import { open as shellOpen } from "@tauri-apps/plugin-shell" import { type as ostype } from "@tauri-apps/plugin-os" import { check, Update } from "@tauri-apps/plugin-updater" @@ -42,6 +43,22 @@ window.getComputedStyle = ((elt: Element, pseudoElt?: string | null) => { let update: Update | null = null +const deepLinkEvent = "opencode:deep-link" + +const emitDeepLinks = (urls: string[]) => { + if (urls.length === 0) return + window.__OPENCODE__ ??= {} + const pending = window.__OPENCODE__.deepLinks ?? [] + window.__OPENCODE__.deepLinks = [...pending, ...urls] + window.dispatchEvent(new CustomEvent(deepLinkEvent, { detail: { urls } })) +} + +const listenForDeepLinks = async () => { + const startUrls = await getCurrent().catch(() => null) + if (startUrls?.length) emitDeepLinks(startUrls) + await onOpenUrl((urls) => emitDeepLinks(urls)).catch(() => undefined) +} + const createPlatform = (password: Accessor): Platform => ({ platform: "desktop", os: (() => { @@ -332,6 +349,7 @@ const createPlatform = (password: Accessor): Platform => ({ }) createMenu() +void listenForDeepLinks() render(() => { const [serverPassword, setServerPassword] = createSignal(null) -- cgit v1.2.3