The open source coding agent.
TypeScript
fix(app): notification should navigate to session
Adamc9719dff7223
diff --git a/packages/app/src/entry.tsx b/packages/app/src/entry.tsxindex f041204dcc2..3a85086b48b 100644--- a/packages/app/src/entry.tsx+++ b/packages/app/src/entry.tsx@@ -4,6 +4,7 @@ import { AppBaseProviders, AppInterface } from "@/app"import { Platform, PlatformProvider } from "@/context/platform"import { dict as en } from "@/i18n/en"import { dict as zh } from "@/i18n/zh"+import { handleNotificationClick } from "@/utils/notification-click"import pkg from "../package.json"const DEFAULT_SERVER_URL_KEY = "opencode.settings.dat:defaultServerUrl"@@ -68,11 +69,7 @@ const notify: Platform["notify"] = async (title, description, href) => {})notification.onclick = () => {- window.focus()- if (href) {- window.history.pushState(null, "", href)- window.dispatchEvent(new PopStateEvent("popstate"))- }+ handleNotificationClick(href)notification.close()}}diff --git a/packages/app/src/index.ts b/packages/app/src/index.tsindex 59e1431fa8c..33c22f099e3 100644--- a/packages/app/src/index.ts+++ b/packages/app/src/index.ts@@ -1,3 +1,4 @@export { PlatformProvider, type Platform, type DisplayBackend } from "./context/platform"export { AppBaseProviders, AppInterface } from "./app"export { useCommand } from "./context/command"+export { handleNotificationClick } from "./utils/notification-click"diff --git a/packages/app/src/utils/notification-click.test.ts b/packages/app/src/utils/notification-click.test.tsnew file mode 100644index 00000000000..76535f83a8e--- /dev/null+++ b/packages/app/src/utils/notification-click.test.ts@@ -0,0 +1,26 @@+import { describe, expect, test } from "bun:test"+import { handleNotificationClick } from "./notification-click"++describe("notification click", () => {+ test("focuses and navigates when href exists", () => {+ const calls: string[] = []+ handleNotificationClick("/abc/session/123", {+ focus: () => calls.push("focus"),+ location: {+ assign: (href) => calls.push(href),+ },+ })+ expect(calls).toEqual(["focus", "/abc/session/123"])+ })++ test("only focuses when href is missing", () => {+ const calls: string[] = []+ handleNotificationClick(undefined, {+ focus: () => calls.push("focus"),+ location: {+ assign: (href) => calls.push(href),+ },+ })+ expect(calls).toEqual(["focus"])+ })+})diff --git a/packages/app/src/utils/notification-click.ts b/packages/app/src/utils/notification-click.tsnew file mode 100644index 00000000000..1234cd1d629--- /dev/null+++ b/packages/app/src/utils/notification-click.ts@@ -0,0 +1,12 @@+type WindowTarget = {+ focus: () => void+ location: {+ assign: (href: string) => void+ }+}++export const handleNotificationClick = (href?: string, target: WindowTarget = window) => {+ target.focus()+ if (!href) return+ target.location.assign(href)+}diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsxindex 620914dd7e7..ff0a093766e 100644--- a/packages/desktop/src/index.tsx+++ b/packages/desktop/src/index.tsx@@ -1,7 +1,14 @@// @refresh reloadimport { webviewZoom } from "./webview-zoom"import { render } from "solid-js/web"-import { AppBaseProviders, AppInterface, PlatformProvider, Platform, useCommand } from "@opencode-ai/app"+import {+ AppBaseProviders,+ AppInterface,+ PlatformProvider,+ Platform,+ useCommand,+ handleNotificationClick,+} from "@opencode-ai/app"import { open, save } from "@tauri-apps/plugin-dialog"import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"import { openPath as openerOpenPath } from "@tauri-apps/plugin-opener"@@ -329,10 +336,7 @@ const createPlatform = (password: Accessor<string | null>): Platform => {void win.show().catch(() => undefined)void win.unminimize().catch(() => undefined)void win.setFocus().catch(() => undefined)- if (href) {- window.history.pushState(null, "", href)- window.dispatchEvent(new PopStateEvent("popstate"))- }+ handleNotificationClick(href)notification.close()}})