feat: desktop tray unread overlay + taskbar flash on new mention
Extends useTauriNotificationBadge to also invoke set_tray_unread (mirror the unread-mention state onto the tray icon, visible when minimized) and flash_window (flash the taskbar button when new mentions arrive while the window is unfocused). No-op outside Tauri. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { roomToUnreadAtom } from '../state/room/roomToUnread';
|
import { roomToUnreadAtom } from '../state/room/roomToUnread';
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ const tauriInvoke = (): TauriInternals['invoke'] | undefined =>
|
|||||||
|
|
||||||
export function useTauriNotificationBadge() {
|
export function useTauriNotificationBadge() {
|
||||||
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
||||||
|
const prevHighlightsRef = useRef(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const invoke = tauriInvoke();
|
const invoke = tauriInvoke();
|
||||||
@@ -21,5 +22,14 @@ export function useTauriNotificationBadge() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
invoke('set_badge_count', { count: totalHighlights }).catch(() => {});
|
invoke('set_badge_count', { count: totalHighlights }).catch(() => {});
|
||||||
|
// Mirror the unread state onto the tray icon (visible when minimized to tray).
|
||||||
|
invoke('set_tray_unread', { unread: totalHighlights > 0 }).catch(() => {});
|
||||||
|
|
||||||
|
// Flash the taskbar button when new mentions arrive and the window is not
|
||||||
|
// focused, then reset the baseline.
|
||||||
|
if (totalHighlights > prevHighlightsRef.current && !document.hasFocus()) {
|
||||||
|
invoke('flash_window').catch(() => {});
|
||||||
|
}
|
||||||
|
prevHighlightsRef.current = totalHighlights;
|
||||||
}, [roomToUnread]);
|
}, [roomToUnread]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user