summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src
diff options
context:
space:
mode:
authorAdam <[email protected]>2026-02-12 20:04:19 -0600
committerAdam <[email protected]>2026-02-12 20:04:36 -0600
commitc9719dff7223aa1fc19540f3cd627c7f40e4bf36 (patch)
tree05032d15edce5b5c0d2cecd0e919b4365b531329 /packages/app/src
parent7f95cc64c57b439f58833d0300a1da93b3b893df (diff)
downloadopencode-c9719dff7223aa1fc19540f3cd627c7f40e4bf36.tar.gz
opencode-c9719dff7223aa1fc19540f3cd627c7f40e4bf36.zip
fix(app): notification should navigate to session
Diffstat (limited to 'packages/app/src')
-rw-r--r--packages/app/src/entry.tsx7
-rw-r--r--packages/app/src/index.ts1
-rw-r--r--packages/app/src/utils/notification-click.test.ts26
-rw-r--r--packages/app/src/utils/notification-click.ts12
4 files changed, 41 insertions, 5 deletions
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)
+}