Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions surfaces/gui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tauri-plugin-dialog = "2"
tauri-plugin-autostart = "2"
tauri-plugin-single-instance = "2"
tauri-plugin-updater = "2"
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
uuid = { version = "1", features = ["v4"] }
Expand Down
3 changes: 2 additions & 1 deletion surfaces/gui/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"core:window:allow-set-focus",
"core:window:allow-unminimize",
"dialog:default",
"autostart:default"
"autostart:default",
"opener:default"
]
}
1 change: 1 addition & 0 deletions surfaces/gui/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ pub fn run() {
show_main(app);
}))
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_autostart::init(
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
Expand Down
15 changes: 14 additions & 1 deletion surfaces/gui/src/components/Markdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { Markdown, OPEN_ARTIFACT_EVENT } from "./Markdown";

afterEach(cleanup);
vi.mock("../tauri", () => ({ openExternal: vi.fn() }));
const { openExternal } = await import("../tauri");

afterEach(() => {
cleanup();
vi.clearAllMocks();
});

// §34 (UX-016): [Title](artifact:path) renders as a chip that opens the artifact viewer via
// a window event; ordinary links keep the open-externally treatment.
Expand Down Expand Up @@ -30,6 +36,13 @@ describe("Markdown artifact links", () => {
expect(a.getAttribute("href")).toBe("https://example.com");
});

it("clicking an ordinary link opens it via openExternal (default browser)", () => {
const { container } = render(<Markdown text="see [the docs](https://example.com)" />);
const a = container.querySelector("a")!;
fireEvent.click(a);
expect(openExternal).toHaveBeenCalledWith("https://example.com");
});

it("chip title falls back to the filename when the link text is empty", () => {
vi.spyOn(window, "dispatchEvent");
render(<Markdown text="[](artifact:out/report.pdf)" />);
Expand Down
18 changes: 17 additions & 1 deletion surfaces/gui/src/components/Markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
import remarkGfm from "remark-gfm";
import { Icon } from "./Icon";
import { openExternal } from "../tauri";

// §34 (UX-016): the agent ends a deliverable turn with plain markdown —
// [Title](artifact:relative/path) — and the renderer turns it into a chip that opens the
Expand Down Expand Up @@ -50,7 +51,22 @@ export function Markdown({ text }: { text: string }) {
return <ArtifactChip path={href.slice("artifact:".length)} title={title} />;
}
return (
<a href={href} {...props} target="_blank" rel="noreferrer">
<a
href={href}
{...props}
target="_blank"
rel="noreferrer"
onClick={(e) => {
// In the Tauri desktop shell, target="_blank" navigates the webview
// instead of opening the system browser. Intercept the click and
// hand the URL to the opener plugin (which launches the default
// browser); fall back to the default anchor behaviour in browser dev.
if (href) {
e.preventDefault();
openExternal(href);
}
}}
>
{children}
</a>
);
Expand Down
7 changes: 4 additions & 3 deletions surfaces/gui/src/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ export const clearPendingUpdate = () => invokeStrict<void>("clear_pending_update
* Windows hands off to the installer). */
export const installUpdate = () => invokeStrict<void>("install_update");

/** Best-effort open a URL in the user's browser. Uses the Tauri opener plugin if present, else
* `window.open`. The caller should also render the raw URL so it stays copyable if both no-op
* (the desktop webview has no opener plugin wired yet). */
/** Best-effort open a URL in the user's default browser. Uses the Tauri opener
* plugin if present (desktop shell), else falls back to `window.open` (browser
* dev mode). The caller should also render the raw URL so it stays copyable if
* both no-op. */
export function openExternal(url: string): void {
const opener = (globalThis as any).__TAURI__?.opener;
if (opener?.openUrl) {
Expand Down