22 lines
842 B
TypeScript
22 lines
842 B
TypeScript
|
|
import { useSetAtom } from 'jotai';
|
||
|
|
import { manualDndAtom } from '../state/manualDnd';
|
||
|
|
import { useTauriEvent } from './useTauri';
|
||
|
|
|
||
|
|
/** Detail shape of the `lotus-dnd-changed` event emitted by the native side. */
|
||
|
|
type DndChangedDetail = {
|
||
|
|
active: boolean;
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* P6-1 — Tray "Do Not Disturb" → notification suppression (desktop). Subscribes
|
||
|
|
* to the native `lotus-dnd-changed` event (emitted when the user toggles the
|
||
|
|
* tray "Do Not Disturb" item, `{ active }`) and mirrors it into `manualDndAtom`,
|
||
|
|
* which the notification gate reads to suppress notifications while DND is on.
|
||
|
|
* Inert in the browser, since `useTauriEvent` only listens under Tauri.
|
||
|
|
*/
|
||
|
|
export function useTauriDnd(): void {
|
||
|
|
const setDnd = useSetAtom(manualDndAtom);
|
||
|
|
|
||
|
|
useTauriEvent<DndChangedDetail>('lotus-dnd-changed', ({ active }) => setDnd(active));
|
||
|
|
}
|