feat(dictation): add persistent language selection in General settings
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
// The keyboard chain needs a synchronous answer; settings also subscribe
|
||||
// so the language control locks from connecting until cleanup completes.
|
||||
let active = false;
|
||||
const listeners = new Set<() => void>();
|
||||
|
||||
export function isDictationActive(): boolean { return active; }
|
||||
|
||||
export function setDictationActive(next: boolean): void {
|
||||
if (active === next) return;
|
||||
active = next;
|
||||
for (const listener of listeners) listener();
|
||||
}
|
||||
|
||||
function subscribe(listener: () => void): () => void {
|
||||
listeners.add(listener);
|
||||
return () => { listeners.delete(listener); };
|
||||
}
|
||||
|
||||
export function useDictationActive(): boolean {
|
||||
return useSyncExternalStore(subscribe, isDictationActive, () => false);
|
||||
}
|
||||
Reference in New Issue
Block a user