diff options
| author | Adam <[email protected]> | 2025-12-29 20:54:33 -0600 |
|---|---|---|
| committer | Adam <[email protected]> | 2025-12-30 04:57:35 -0600 |
| commit | fa1ac7bc957f3b8b13b97e85eac40729f16b510b (patch) | |
| tree | 0e65db62401b8057019222a8d05f6b9de452bffb /packages/desktop/src | |
| parent | c82ab649e2307237b480a94dbb7df6d77a8bf71a (diff) | |
| download | opencode-fa1ac7bc957f3b8b13b97e85eac40729f16b510b.tar.gz opencode-fa1ac7bc957f3b8b13b97e85eac40729f16b510b.zip | |
feat(desktop): system notifications
Diffstat (limited to 'packages/desktop/src')
| -rw-r--r-- | packages/desktop/src/index.tsx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/desktop/src/index.tsx b/packages/desktop/src/index.tsx index 58aca8fd1..a36da4125 100644 --- a/packages/desktop/src/index.tsx +++ b/packages/desktop/src/index.tsx @@ -12,6 +12,8 @@ import { UPDATER_ENABLED } from "./updater" import { createMenu } from "./menu" import { check, Update } from "@tauri-apps/plugin-updater" import { invoke } from "@tauri-apps/api/core" +import { getCurrentWindow } from "@tauri-apps/api/window" +import { isPermissionGranted, requestPermission } from "@tauri-apps/plugin-notification" import { relaunch } from "@tauri-apps/plugin-process" import pkg from "../package.json" @@ -94,6 +96,33 @@ const platform: Platform = { await relaunch() }, + notify: async (title, description, href) => { + const granted = await isPermissionGranted().catch(() => false) + const permission = granted ? "granted" : await requestPermission().catch(() => "denied") + if (permission !== "granted") return + + const win = getCurrentWindow() + const focused = await win.isFocused().catch(() => document.hasFocus()) + if (focused) return + + await Promise.resolve() + .then(() => { + const notification = new Notification(title, { body: description ?? "" }) + notification.onclick = () => { + const win = getCurrentWindow() + 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")) + } + notification.close() + } + }) + .catch(() => undefined) + }, + // @ts-expect-error fetch: tauriFetch, } |
