/** * Caption buttons (minimise, maximise / restore, close) for the frameless * title bar. Dialog windows (Settings) only have close, as in IDEA. */ import { useEffect, useState } from "react"; import clsx from "clsx"; import { t } from "@/platform/i18n"; import { Icon } from "@/ui"; import styles from "./TitleBar.module.css"; type AppWindow = import("@tauri-apps/api/window").Window; function withWindow(run: (w: AppWindow) => unknown) { void import("@tauri-apps/api/window").then(({ getCurrentWindow }) => run(getCurrentWindow())); } function CloseButton() { return ( ); } function SizeButtons() { const [maximized, setMaximized] = useState(false); useEffect(() => { let disposed = false; let unlisten: (() => void) | undefined; withWindow(async (w) => { const sync = () => void w.isMaximized().then((m) => !disposed && setMaximized(m)); sync(); const off = await w.onResized(sync); if (disposed) off(); else unlisten = off; }); return () => { disposed = true; unlisten?.(); }; }, []); const maximizeLabel = maximized ? t("window.caption.restore") : t("window.caption.maximize"); return ( <> ); } export function WindowControls({ dialog = false }: { dialog?: boolean }) { return (
{!dialog && }
); }