import React, { useEffect, useRef, useState } from "react"; import { app, utils } from "../../main"; import styles from "./App.module.scss"; import TitleBar from "./titleBar/TitleBar"; interface Props { /** * App view body */ children: JSX.Element[] | JSX.Element; /** * The app title */ title?: string; } export interface RefInstance { /** * CSS body container height */ bodyHeight?: string; } const App = React.forwardRef((props, ref) => { document.body.style.margin = "0px"; props = utils.mergeObject( { children: <>, title: "", }, props ); const [ bodyHeight, setBodyHeight ] = useState(null); const bodyRef = useRef(null); function resizeHandle() { if (app.getMeta().envMode == "electron") { setBodyHeight(window.outerHeight - (document.body.offsetHeight > 40 ? 40 : 0) + "px"); } else { setBodyHeight(document.documentElement.scrollHeight + "px"); } } if (bodyHeight == null) { window.addEventListener("resize", resizeHandle); } document.title = props.title!; if (ref == undefined) { ref = {} as any; } const refClone = ref as { current: RefInstance }; refClone.current = {} as any; useEffect(() => { resizeHandle(); return () => { window.removeEventListener("resize", resizeHandle, true); } }); return (
{ app.getMeta().envMode == "electron" ? : null }
{props.children}
); }); export default App;