Web half of the desktop feature wave. A shared bridge (`hooks/useTauri.ts`: invokeTauri/isTauri/useTauriEvent) backs per-feature hooks that no-op in the browser and drive the native Tauri commands (compiled in cinny-desktop): - P5-46 useTauriCallPower — hold system awake while a call is active. - P5-36 useTauriJumpList — Windows jump list of recent rooms → matrix: deep links. - P5-44 useTauriThumbbar — taskbar Mute/Deafen/End; events toggle mic/sound/hangup. - P5-43 useTauriSmtc — SMTC call state + button events. - P5-49 useTauriNetwork — react to native network-change → mx.retryImmediately(). - P5-47 window chrome — opt-in `customWindowChromeAtom` + TDS `TitleBar`; DesktopChrome wrapper in App.tsx (zero layout impact when off) + a desktop-only settings toggle. - P5-55 composer toolbar drag-reorder (settings order[] + pragmatic-drag-and-drop). - P5-57 DraftIndicator — subtle "draft saved" cue in the composer. Client-scoped hooks mount via TauriDesktopFeatures in ClientNonUIFeatures; window chrome mounts at App level. Gates: tsc/eslint/prettier clean, build OK, 556 tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { useRef, useState } from 'react';
|
|
import { useMatrixClient } from './useMatrixClient';
|
|
import { useTauriEvent } from './useTauri';
|
|
|
|
/** Detail shape of the `network-changed` event emitted by the native side. */
|
|
type NetworkChangedDetail = {
|
|
online: boolean;
|
|
};
|
|
|
|
/**
|
|
* P5-49 — Network awareness (desktop). Subscribes to the native
|
|
* `network-changed` event (Windows Network List Manager poll, `{ online }`) and,
|
|
* on a transition back to online, calls `mx.retryImmediately()` so the sync loop
|
|
* retries its backed-off `/sync` at once instead of waiting out the backoff
|
|
* timer. Returns the last known connectivity (`undefined` until the first
|
|
* event). Inert in the browser, since `useTauriEvent` only listens under Tauri.
|
|
*/
|
|
export function useTauriNetwork(): boolean | undefined {
|
|
const mx = useMatrixClient();
|
|
const [online, setOnline] = useState<boolean | undefined>(undefined);
|
|
// Track the previous value in a ref so we can detect an offline -> online
|
|
// transition without adding it to a dependency list.
|
|
const onlineRef = useRef<boolean | undefined>(undefined);
|
|
|
|
useTauriEvent<NetworkChangedDetail>('network-changed', ({ online: next }) => {
|
|
const previous = onlineRef.current;
|
|
onlineRef.current = next;
|
|
setOnline(next);
|
|
// Only nudge the client when connectivity is (re)gained. The initial event
|
|
// (previous === undefined) also triggers a retry, which is safe: it's a
|
|
// no-op if nothing is backed off.
|
|
if (next && previous !== true) {
|
|
mx.retryImmediately();
|
|
}
|
|
});
|
|
|
|
return online;
|
|
}
|