2026-07-01 09:07:03 -04:00
|
|
|
import { useEffect } from 'react';
|
2026-11-09 21:42:27 -05:00
|
|
|
import { useAtomValue, useSetAtom } from 'jotai';
|
|
|
|
|
import { customWindowChromeAtom, nativeChromeActiveAtom } from '../state/customWindowChrome';
|
|
|
|
|
import { isTauri, tauriInvoke } from './useTauri';
|
2026-07-01 09:07:03 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* P5-47 — drive the native window frame from the `customWindowChromeAtom`.
|
|
|
|
|
*
|
|
|
|
|
* On mount and whenever the atom changes, pushes the value onto the native
|
|
|
|
|
* `set_custom_chrome` command: `enabled = true` strips the OS decorations so the
|
|
|
|
|
* web `<TitleBar/>` can take over, `enabled = false` restores the native frame.
|
|
|
|
|
* No-op in the browser (`isTauri()` guard), so it's safe to call unconditionally
|
|
|
|
|
* from the app shell.
|
2026-11-09 21:42:27 -05:00
|
|
|
*
|
|
|
|
|
* The command answers whether the native frame is stripped *now* (on Linux /
|
|
|
|
|
* Wayland the frame only changes at the next launch); that drives whether the
|
|
|
|
|
* Lotus titlebar is shown. Older desktop builds answer nothing, so the setting
|
|
|
|
|
* is used as before.
|
2026-07-01 09:07:03 -04:00
|
|
|
*/
|
|
|
|
|
export function useTauriWindowChrome(): void {
|
|
|
|
|
const enabled = useAtomValue(customWindowChromeAtom);
|
2026-11-09 21:42:27 -05:00
|
|
|
const setNativeActive = useSetAtom(nativeChromeActiveAtom);
|
2026-07-01 09:07:03 -04:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-11-09 21:42:27 -05:00
|
|
|
const invoke = isTauri() ? tauriInvoke() : undefined;
|
|
|
|
|
if (!invoke) return undefined;
|
|
|
|
|
let cancelled = false;
|
|
|
|
|
invoke('set_custom_chrome', { enabled })
|
|
|
|
|
.then((active) => {
|
|
|
|
|
if (!cancelled) setNativeActive(typeof active === 'boolean' ? active : enabled);
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
if (!cancelled) setNativeActive(enabled);
|
|
|
|
|
});
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true;
|
|
|
|
|
};
|
|
|
|
|
}, [enabled, setNativeActive]);
|
2026-07-01 09:07:03 -04:00
|
|
|
}
|