fix(app): notification should navigate to session
This commit is contained in:
@@ -4,6 +4,7 @@ import { AppBaseProviders, AppInterface } from "@/app"
|
|||||||
import { Platform, PlatformProvider } from "@/context/platform"
|
import { Platform, PlatformProvider } from "@/context/platform"
|
||||||
import { dict as en } from "@/i18n/en"
|
import { dict as en } from "@/i18n/en"
|
||||||
import { dict as zh } from "@/i18n/zh"
|
import { dict as zh } from "@/i18n/zh"
|
||||||
|
import { handleNotificationClick } from "@/utils/notification-click"
|
||||||
import pkg from "../package.json"
|
import pkg from "../package.json"
|
||||||
|
|
||||||
const DEFAULT_SERVER_URL_KEY = "opencode.settings.dat:defaultServerUrl"
|
const DEFAULT_SERVER_URL_KEY = "opencode.settings.dat:defaultServerUrl"
|
||||||
@@ -68,11 +69,7 @@ const notify: Platform["notify"] = async (title, description, href) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
notification.onclick = () => {
|
notification.onclick = () => {
|
||||||
window.focus()
|
handleNotificationClick(href)
|
||||||
if (href) {
|
|
||||||
window.history.pushState(null, "", href)
|
|
||||||
window.dispatchEvent(new PopStateEvent("popstate"))
|
|
||||||
}
|
|
||||||
notification.close()
|
notification.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export { PlatformProvider, type Platform, type DisplayBackend } from "./context/platform"
|
export { PlatformProvider, type Platform, type DisplayBackend } from "./context/platform"
|
||||||
export { AppBaseProviders, AppInterface } from "./app"
|
export { AppBaseProviders, AppInterface } from "./app"
|
||||||
export { useCommand } from "./context/command"
|
export { useCommand } from "./context/command"
|
||||||
|
export { handleNotificationClick } from "./utils/notification-click"
|
||||||
|
|||||||
26
packages/app/src/utils/notification-click.test.ts
Normal file
26
packages/app/src/utils/notification-click.test.ts
Normal file
@@ -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"])
|
||||||
|
})
|
||||||
|
})
|
||||||
12
packages/app/src/utils/notification-click.ts
Normal file
12
packages/app/src/utils/notification-click.ts
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
// @refresh reload
|
// @refresh reload
|
||||||
import { webviewZoom } from "./webview-zoom"
|
import { webviewZoom } from "./webview-zoom"
|
||||||
import { render } from "solid-js/web"
|
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 { open, save } from "@tauri-apps/plugin-dialog"
|
||||||
import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"
|
import { getCurrent, onOpenUrl } from "@tauri-apps/plugin-deep-link"
|
||||||
import { openPath as openerOpenPath } from "@tauri-apps/plugin-opener"
|
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.show().catch(() => undefined)
|
||||||
void win.unminimize().catch(() => undefined)
|
void win.unminimize().catch(() => undefined)
|
||||||
void win.setFocus().catch(() => undefined)
|
void win.setFocus().catch(() => undefined)
|
||||||
if (href) {
|
handleNotificationClick(href)
|
||||||
window.history.pushState(null, "", href)
|
|
||||||
window.dispatchEvent(new PopStateEvent("popstate"))
|
|
||||||
}
|
|
||||||
notification.close()
|
notification.close()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user