diff --git a/apps/desktop2/src/components/col.tsx b/apps/desktop2/src/components/col.tsx index 4dbf28f2..c6e06b8a 100644 --- a/apps/desktop2/src/components/col.tsx +++ b/apps/desktop2/src/components/col.tsx @@ -78,7 +78,7 @@ export function Col({ }); } }; - }, []); + }, [webview]); return (
diff --git a/apps/desktop2/src/routes/$account.home.tsx b/apps/desktop2/src/routes/$account.home.tsx index 34624897..c69037e0 100644 --- a/apps/desktop2/src/routes/$account.home.tsx +++ b/apps/desktop2/src/routes/$account.home.tsx @@ -120,29 +120,20 @@ function Screen() { }, [columns]); useEffect(() => { - let unlistenColEvent: Awaited> | undefined = - undefined; - let unlistenWindowResize: Awaited> | undefined = - undefined; + const unlistenColEvent = listen("columns", (data) => { + if (data.payload.type === "add") add(data.payload.column); + if (data.payload.type === "remove") remove(data.payload.label); + if (data.payload.type === "set_title") + updateName(data.payload.label, data.payload.title); + }); - (async () => { - if (unlistenColEvent && unlistenWindowResize) return; - - unlistenColEvent = await listen("columns", (data) => { - if (data.payload.type === "add") add(data.payload.column); - if (data.payload.type === "remove") remove(data.payload.label); - if (data.payload.type === "set_title") - updateName(data.payload.label, data.payload.title); - }); - - unlistenWindowResize = await getCurrent().listen("tauri://resize", () => { - startResize(); - }); - })(); + const unlistenWindowResize = getCurrent().listen("tauri://resize", () => { + startResize(); + }); return () => { - if (unlistenColEvent) unlistenColEvent(); - if (unlistenWindowResize) unlistenWindowResize(); + unlistenColEvent.then((f) => f()); + unlistenWindowResize.then((f) => f()); }; }, []); diff --git a/apps/desktop2/src/routes/$account.tsx b/apps/desktop2/src/routes/$account.tsx index f921cfbb..75648eb4 100644 --- a/apps/desktop2/src/routes/$account.tsx +++ b/apps/desktop2/src/routes/$account.tsx @@ -8,7 +8,7 @@ import { sendNativeNotification, } from "@lume/utils"; import { Outlet, createFileRoute } from "@tanstack/react-router"; -import { UnlistenFn } from "@tauri-apps/api/event"; +import { invoke } from "@tauri-apps/api/core"; import { getCurrent } from "@tauri-apps/api/window"; import { useEffect, useState } from "react"; @@ -118,50 +118,45 @@ function Bell() { const { ark } = Route.useRouteContext(); const { account } = Route.useParams(); - const [isRing, setIsRing] = useState(false); + const [count, setCount] = useState(0); useEffect(() => { - let unlisten: UnlistenFn = undefined; + const unlisten = getCurrent().listen( + "activity", + async (payload) => { + setCount((prevCount) => prevCount + 1); + await invoke("set_badge", { count }); - async function listenNotify() { - unlisten = await getCurrent().listen( - "activity", - async (payload) => { - setIsRing(true); + const event: Event = JSON.parse(payload.payload); + const user = await ark.get_profile(event.pubkey); + const userName = + user.display_name || user.name || displayNpub(event.pubkey, 16); - const event: Event = JSON.parse(payload.payload); - const user = await ark.get_profile(event.pubkey); - const userName = - user.display_name || user.name || displayNpub(event.pubkey, 16); - - switch (event.kind) { - case Kind.Text: { - sendNativeNotification("Mentioned you in a note", userName); - break; - } - case Kind.Repost: { - sendNativeNotification("Reposted your note", userName); - break; - } - case Kind.ZapReceipt: { - const amount = decodeZapInvoice(event.tags); - sendNativeNotification( - `Zapped ₿ ${amount.bitcoinFormatted}`, - userName, - ); - break; - } - default: - break; + switch (event.kind) { + case Kind.Text: { + sendNativeNotification("Mentioned you in a note", userName); + break; } - }, - ); - } - - if (!unlisten) listenNotify(); + case Kind.Repost: { + sendNativeNotification("Reposted your note", userName); + break; + } + case Kind.ZapReceipt: { + const amount = decodeZapInvoice(event.tags); + sendNativeNotification( + `Zapped ₿ ${amount.bitcoinFormatted}`, + userName, + ); + break; + } + default: + break; + } + }, + ); return () => { - if (unlisten) unlisten(); + unlisten.then((f) => f()); }; }, []); @@ -169,13 +164,13 @@ function Bell() { diff --git a/apps/desktop2/src/routes/store.tsx b/apps/desktop2/src/routes/store.tsx index 8480a639..66c234a4 100644 --- a/apps/desktop2/src/routes/store.tsx +++ b/apps/desktop2/src/routes/store.tsx @@ -18,13 +18,13 @@ export const Route = createFileRoute("/store")({ function Screen() { return (
-
-
+
+
{({ isActive }) => (
@@ -37,7 +37,7 @@ function Screen() { {({ isActive }) => (
diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 4ee154b7..6167a5e2 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -1,3 +1,5 @@ +#[cfg(target_os = "macos")] +use cocoa::{appkit::NSApp, base::nil, foundation::NSString}; use std::path::PathBuf; use tauri::utils::config::WindowEffectsConfig; use tauri::window::Effect; @@ -166,3 +168,17 @@ pub fn open_window( Ok(()) } + +#[tauri::command] +pub fn set_badge(count: i32) { + #[cfg(target_os = "macos")] + unsafe { + let label = if count == 0 { + nil + } else { + NSString::alloc(nil).init_str(&format!("{}", count)) + }; + let dock_tile: cocoa::base::id = msg_send![NSApp(), dockTile]; + let _: cocoa::base::id = msg_send![dock_tile, setBadgeLabel: label]; + } +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e9b4315b..7537439a 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -138,7 +138,8 @@ fn main() { commands::window::resize_column, commands::window::open_window, commands::window::get_path, - commands::window::navigate + commands::window::navigate, + commands::window::set_badge ]) .run(tauri::generate_context!()) .expect("error while running tauri application")