Skip to content

Commit c9719df

Browse files
committed
fix(app): notification should navigate to session
1 parent 7f95cc6 commit c9719df

5 files changed

Lines changed: 50 additions & 10 deletions

File tree

packages/app/src/entry.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AppBaseProviders, AppInterface } from "@/app"
44
import { Platform, PlatformProvider } from "@/context/platform"
55
import { dict as en } from "@/i18n/en"
66
import { dict as zh } from "@/i18n/zh"
7+
import { handleNotificationClick } from "@/utils/notification-click"
78
import pkg from "../package.json"
89

910
const DEFAULT_SERVER_URL_KEY = "opencode.settings.dat:defaultServerUrl"
@@ -68,11 +69,7 @@ const notify: Platform["notify"] = async (title, description, href) => {
6869
})
6970

7071
notification.onclick = () => {
71-
window.focus()
72-
if (href) {
73-
window.history.pushState(null, "", href)
74-
window.dispatchEvent(new PopStateEvent("popstate"))
75-
}
72+
handleNotificationClick(href)
7673
notification.close()
7774
}
7875
}

packages/app/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { PlatformProvider, type Platform, type DisplayBackend } from "./context/platform"
22
export { AppBaseProviders, AppInterface } from "./app"
33
export { useCommand } from "./context/command"
4+
export { handleNotificationClick } from "./utils/notification-click"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { handleNotificationClick } from "./notification-click"
3+
4+
describe("notification click", () => {
5+
test("focuses and navigates when href exists", () => {
6+
const calls: string[] = []
7+
handleNotificationClick("/abc/session/123", {
8+
focus: () => calls.push("focus"),
9+
location: {
10+
assign: (href) => calls.push(href),
11+
},
12+
})
13+
expect(calls).toEqual(["focus", "/abc/session/123"])
14+
})
15+
16+
test("only focuses when href is missing", () => {
17+
const calls: string[] = []
18+
handleNotificationClick(undefined, {
19+
focus: () => calls.push("focus"),
20+
location: {
21+
assign: (href) => calls.push(href),
22+
},
23+
})
24+
expect(calls).toEqual(["focus"])
25+
})
26+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type WindowTarget = {
2+
focus: () => void
3+
location: {
4+
assign: (href: string) => void
5+
}
6+
}
7+
8+
export const handleNotificationClick = (href?: string, target: WindowTarget = window) => {
9+
target.focus()
10+
if (!href) return
11+
target.location.assign(href)
12+
}

packages/desktop/src/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// @refresh reload
22
import { webviewZoom } from "./webview-zoom"
33
import { render } from "solid-js/web"
4-
import { AppBaseProviders, AppInterface, PlatformProvider, Platform, useCommand } from "@opencode-ai/app"
4+
import {
5+
AppBaseProviders,
6+
AppInterface,
7+
PlatformProvider,
8+
Platform,
9+
useCommand,
10+
handleNotificationClick,
11+
} from "@opencode-ai/app"
512
import { open, save } from "@tauri-apps/plugin-dialog"
613
import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"
714
import { openPath as openerOpenPath } from "@tauri-apps/plugin-opener"
@@ -329,10 +336,7 @@ const createPlatform = (password: Accessor<string | null>): Platform => {
329336
void win.show().catch(() => undefined)
330337
void win.unminimize().catch(() => undefined)
331338
void win.setFocus().catch(() => undefined)
332-
if (href) {
333-
window.history.pushState(null, "", href)
334-
window.dispatchEvent(new PopStateEvent("popstate"))
335-
}
339+
handleNotificationClick(href)
336340
notification.close()
337341
}
338342
})

0 commit comments

Comments
 (0)