From c9719dff7223aa1fc19540f3cd627c7f40e4bf36 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Thu, 12 Feb 2026 20:04:19 -0600 Subject: [PATCH] fix(app): notification should navigate to session --- packages/app/src/entry.tsx | 7 ++--- packages/app/src/index.ts | 1 + .../app/src/utils/notification-click.test.ts | 26 +++++++++++++++++++ packages/app/src/utils/notification-click.ts | 12 +++++++++ packages/desktop/src/index.tsx | 14 ++++++---- 5 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 packages/app/src/utils/notification-click.test.ts create mode 100644 packages/app/src/utils/notification-click.ts diff --git a/packages/app/src/entry.tsx b/packages/app/src/entry.tsx index f041204dc..3a85086b4 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.ts index 59e1431fa..33c22f099 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.ts new file mode 100644 index 000000000..76535f83a --- /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.ts new file mode 100644 index 000000000..1234cd1d6 --- /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.tsx index 620914dd7..ff0a09376 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -1,7 +1,14 @@ // @refresh reload import { 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): 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() } })