Compare commits
1 Commits
053b364a44
...
107921e0d0
| Author | SHA1 | Date | |
|---|---|---|---|
| 107921e0d0 |
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { roomToUnreadAtom } from '../state/room/roomToUnread';
|
||||
|
||||
@@ -10,6 +10,7 @@ const tauriInvoke = (): TauriInternals['invoke'] | undefined =>
|
||||
|
||||
export function useTauriNotificationBadge() {
|
||||
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
||||
const prevHighlightsRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const invoke = tauriInvoke();
|
||||
@@ -21,5 +22,14 @@ export function useTauriNotificationBadge() {
|
||||
});
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user