From fa1ac7bc957f3b8b13b97e85eac40729f16b510b Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Mon, 29 Dec 2025 20:54:33 -0600 Subject: feat(desktop): system notifications --- packages/desktop/src/index.tsx | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'packages/desktop/src') 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, } -- cgit v1.2.3