diff options
| author | Brendan Allan <[email protected]> | 2026-02-02 15:58:08 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-02-02 07:58:08 +0000 |
| commit | 04aef44fc30d599f11ea2ada60ed63c4856a18ff (patch) | |
| tree | 391c103e232d085f9322dec41d0321752d27f154 /packages/desktop/src | |
| parent | c02dd067b2ae62553c63b087b7b48a0f46628747 (diff) | |
| download | opencode-04aef44fc30d599f11ea2ada60ed63c4856a18ff.tar.gz opencode-04aef44fc30d599f11ea2ada60ed63c4856a18ff.zip | |
chore(desktop): integrate tauri-specta (#11740)
Diffstat (limited to 'packages/desktop/src')
| -rw-r--r-- | packages/desktop/src/bindings.ts | 20 | ||||
| -rw-r--r-- | packages/desktop/src/cli.ts | 4 | ||||
| -rw-r--r-- | packages/desktop/src/index.tsx | 20 | ||||
| -rw-r--r-- | packages/desktop/src/menu.ts | 4 | ||||
| -rw-r--r-- | packages/desktop/src/updater.ts | 6 |
5 files changed, 35 insertions, 19 deletions
diff --git a/packages/desktop/src/bindings.ts b/packages/desktop/src/bindings.ts new file mode 100644 index 000000000..eb5498fa6 --- /dev/null +++ b/packages/desktop/src/bindings.ts @@ -0,0 +1,20 @@ +// This file has been generated by Tauri Specta. Do not edit this file manually. + +import { invoke as __TAURI_INVOKE, Channel } from '@tauri-apps/api/core'; + +/** Commands */ +export const commands = { + killSidecar: () => __TAURI_INVOKE<void>("kill_sidecar"), + installCli: () => __TAURI_INVOKE<string>("install_cli"), + ensureServerReady: () => __TAURI_INVOKE<ServerReadyData>("ensure_server_ready"), + getDefaultServerUrl: () => __TAURI_INVOKE<string | null>("get_default_server_url"), + setDefaultServerUrl: (url: string | null) => __TAURI_INVOKE<null>("set_default_server_url", { url }), + parseMarkdownCommand: (markdown: string) => __TAURI_INVOKE<string>("parse_markdown_command", { markdown }), +}; + +/* Types */ +export type ServerReadyData = { + url: string, + password: string | null, + }; + diff --git a/packages/desktop/src/cli.ts b/packages/desktop/src/cli.ts index 5a8875cf8..28623bdf7 100644 --- a/packages/desktop/src/cli.ts +++ b/packages/desktop/src/cli.ts @@ -1,13 +1,13 @@ -import { invoke } from "@tauri-apps/api/core" import { message } from "@tauri-apps/plugin-dialog" import { initI18n, t } from "./i18n" +import { commands } from "./bindings" export async function installCli(): Promise<void> { await initI18n() try { - const path = await invoke<string>("install_cli") + const path = await commands.installCli() await message(t("desktop.cli.installed.message", { path }), { title: t("desktop.cli.installed.title") }) } catch (e) { await message(t("desktop.cli.failed.message", { error: String(e) }), { title: t("desktop.cli.failed.title") }) diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index 505a00b16..2b4406162 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -7,7 +7,6 @@ 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" -import { invoke } from "@tauri-apps/api/core" import { getCurrentWindow } from "@tauri-apps/api/window" import { isPermissionGranted, requestPermission } from "@tauri-apps/plugin-notification" import { relaunch } from "@tauri-apps/plugin-process" @@ -22,6 +21,7 @@ import { createMenu } from "./menu" import { initI18n, t } from "./i18n" import pkg from "../package.json" import "./styles.css" +import { commands } from "./bindings" const root = document.getElementById("root") if (import.meta.env.DEV && !(root instanceof HTMLElement)) { @@ -274,12 +274,12 @@ const createPlatform = (password: Accessor<string | null>): Platform => ({ update: async () => { if (!UPDATER_ENABLED || !update) return - if (ostype() === "windows") await invoke("kill_sidecar").catch(() => undefined) + if (ostype() === "windows") await commands.killSidecar().catch(() => undefined) await update.install().catch(() => undefined) }, restart: async () => { - await invoke("kill_sidecar").catch(() => undefined) + await commands.killSidecar().catch(() => undefined) await relaunch() }, @@ -335,17 +335,13 @@ const createPlatform = (password: Accessor<string | null>): Platform => ({ }, getDefaultServerUrl: async () => { - const result = await invoke<string | null>("get_default_server_url").catch(() => null) + const result = await commands.getDefaultServerUrl().catch(() => null) return result }, - setDefaultServerUrl: async (url: string | null) => { - await invoke("set_default_server_url", { url }) - }, + setDefaultServerUrl: async (url: string | null) => { await commands.setDefaultServerUrl(url) }, - parseMarkdown: async (markdown: string) => { - return invoke<string>("parse_markdown_command", { markdown }) - }, + parseMarkdown: (markdown: string) => commands.parseMarkdownCommand(markdown), webviewZoom, }) @@ -394,7 +390,7 @@ type ServerReadyData = { url: string; password: string | null } // Gate component that waits for the server to be ready function ServerGate(props: { children: (data: Accessor<ServerReadyData>) => JSX.Element }) { const [serverData] = createResource<ServerReadyData>(() => - invoke("ensure_server_ready").then((v) => { + commands.ensureServerReady().then((v) => { return new Promise((res) => setTimeout(() => res(v as ServerReadyData), 2000)) }), ) @@ -408,7 +404,7 @@ function ServerGate(props: { children: (data: Accessor<ServerReadyData>) => JSX. } const restartApp = async () => { - await invoke("kill_sidecar").catch(() => undefined) + await commands.killSidecar().catch(() => undefined) await relaunch().catch(() => undefined) } diff --git a/packages/desktop/src/menu.ts b/packages/desktop/src/menu.ts index 2edeff42b..d41084404 100644 --- a/packages/desktop/src/menu.ts +++ b/packages/desktop/src/menu.ts @@ -1,11 +1,11 @@ import { Menu, MenuItem, PredefinedMenuItem, Submenu } from "@tauri-apps/api/menu" import { type as ostype } from "@tauri-apps/plugin-os" -import { invoke } from "@tauri-apps/api/core" import { relaunch } from "@tauri-apps/plugin-process" import { runUpdater, UPDATER_ENABLED } from "./updater" import { installCli } from "./cli" import { initI18n, t } from "./i18n" +import { commands } from "./bindings" export async function createMenu() { if (ostype() !== "macos") return @@ -35,7 +35,7 @@ export async function createMenu() { }), await MenuItem.new({ action: async () => { - await invoke("kill_sidecar").catch(() => undefined) + await commands.killSidecar().catch(() => undefined) await relaunch().catch(() => undefined) }, text: t("desktop.menu.restart"), diff --git a/packages/desktop/src/updater.ts b/packages/desktop/src/updater.ts index b48bb6be0..732669633 100644 --- a/packages/desktop/src/updater.ts +++ b/packages/desktop/src/updater.ts @@ -1,10 +1,10 @@ import { check } from "@tauri-apps/plugin-updater" import { relaunch } from "@tauri-apps/plugin-process" import { ask, message } from "@tauri-apps/plugin-dialog" -import { invoke } from "@tauri-apps/api/core" import { type as ostype } from "@tauri-apps/plugin-os" import { initI18n, t } from "./i18n" +import { commands } from "./bindings" export const UPDATER_ENABLED = window.__OPENCODE__?.updaterEnabled ?? false @@ -39,13 +39,13 @@ export async function runUpdater({ alertOnFail }: { alertOnFail: boolean }) { if (!shouldUpdate) return try { - if (ostype() === "windows") await invoke("kill_sidecar") + if (ostype() === "windows") await commands.killSidecar() await update.install() } catch { await message(t("desktop.updater.installFailed.message"), { title: t("desktop.updater.installFailed.title") }) return } - await invoke("kill_sidecar") + await commands.killSidecar() await relaunch() } |
