fixed headerbar
This commit is contained in:
		
							parent
							
								
									c084b5fa48
								
							
						
					
					
						commit
						e92ff39658
					
				
							
								
								
									
										
											BIN
										
									
								
								client/bun.lockb
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								client/bun.lockb
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -2,13 +2,28 @@
 | 
				
			||||||
  "$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
 | 
					  "$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
 | 
				
			||||||
  "app": {
 | 
					  "app": {
 | 
				
			||||||
    "security": {
 | 
					    "security": {
 | 
				
			||||||
 | 
					      "capabilities": [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          "identifier": "my-identifier",
 | 
				
			||||||
 | 
					          "permissions": [
 | 
				
			||||||
 | 
					            "core:window:default",
 | 
				
			||||||
 | 
					            "core:window:allow-start-dragging",
 | 
				
			||||||
 | 
					            "core:window:allow-is-fullscreen",
 | 
				
			||||||
 | 
					            "core:window:allow-minimize",
 | 
				
			||||||
 | 
					            "core:window:allow-toggle-maximize",
 | 
				
			||||||
 | 
					            "core:window:allow-close"
 | 
				
			||||||
 | 
					          ],
 | 
				
			||||||
 | 
					          "windows": [
 | 
				
			||||||
 | 
					            "main"
 | 
				
			||||||
 | 
					          ]
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      ],
 | 
				
			||||||
      "csp": null
 | 
					      "csp": null
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "windows": [
 | 
					    "windows": [
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        "decorations": false,
 | 
					        "decorations": false,
 | 
				
			||||||
        "height": 600,
 | 
					        "height": 600,
 | 
				
			||||||
        "maximized": true,
 | 
					 | 
				
			||||||
        "resizable": true,
 | 
					        "resizable": true,
 | 
				
			||||||
        "title": "CSPJ",
 | 
					        "title": "CSPJ",
 | 
				
			||||||
        "width": 800
 | 
					        "width": 800
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,54 +1,26 @@
 | 
				
			||||||
import {
 | 
					import { Close, Minimize, WebAssetOutlined } from "@mui/icons-material";
 | 
				
			||||||
  Close,
 | 
					 | 
				
			||||||
  Fullscreen,
 | 
					 | 
				
			||||||
  FullscreenExit,
 | 
					 | 
				
			||||||
  Minimize,
 | 
					 | 
				
			||||||
  WebAssetOutlined,
 | 
					 | 
				
			||||||
} from "@mui/icons-material";
 | 
					 | 
				
			||||||
import { Box, IconButton, Stack, useTheme } from "@mui/material";
 | 
					import { Box, IconButton, Stack, useTheme } from "@mui/material";
 | 
				
			||||||
import {
 | 
					import { getCurrentWindow } from "@tauri-apps/api/window";
 | 
				
			||||||
  getCurrentWebviewWindow,
 | 
					 | 
				
			||||||
  WebviewWindow,
 | 
					 | 
				
			||||||
} from "@tauri-apps/api/webviewWindow";
 | 
					 | 
				
			||||||
import { useEffect, useState } from "react";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const WindowButtons = () => {
 | 
					export const WindowButtons = () => {
 | 
				
			||||||
  // contexts
 | 
					  // contexts
 | 
				
			||||||
  const userTheme = useTheme();
 | 
					  const userTheme = useTheme();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // states
 | 
					 | 
				
			||||||
  const [appWindow, setAppWindow] = useState<WebviewWindow>();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // explanation:
 | 
					 | 
				
			||||||
  // this is needed due to the server-sided nature of next js,
 | 
					 | 
				
			||||||
  // this means that the window object might not be available on first load
 | 
					 | 
				
			||||||
  // we will use dynamic imports to load the window object only when needed
 | 
					 | 
				
			||||||
  // in hindsight, using next js for this project was a mistake
 | 
					 | 
				
			||||||
  // using create-react-app or vite would have been a better choice just to generate a static site
 | 
					 | 
				
			||||||
  const initializeAppWindow = async () => {
 | 
					 | 
				
			||||||
    setAppWindow(getCurrentWebviewWindow());
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const toggleFullscreen = async () => {
 | 
					 | 
				
			||||||
    appWindow?.setFullscreen(!(await appWindow?.isFullscreen()));
 | 
					 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  const minimize = () => {
 | 
					  const minimize = () => {
 | 
				
			||||||
    appWindow?.minimize();
 | 
					    const appWindow = getCurrentWindow();
 | 
				
			||||||
 | 
					    appWindow.minimize();
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const toggleMaximize = () => {
 | 
					  const toggleMaximize = () => {
 | 
				
			||||||
    appWindow?.toggleMaximize();
 | 
					    const appWindow = getCurrentWindow();
 | 
				
			||||||
 | 
					    appWindow.toggleMaximize();
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const close = async () => {
 | 
					  const close = async () => {
 | 
				
			||||||
    appWindow?.close();
 | 
					    const appWindow = getCurrentWindow();
 | 
				
			||||||
 | 
					    appWindow.close();
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  useEffect(() => {
 | 
					 | 
				
			||||||
    initializeAppWindow();
 | 
					 | 
				
			||||||
  });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <Box
 | 
					    <Box
 | 
				
			||||||
      sx={{
 | 
					      sx={{
 | 
				
			||||||
| 
						 | 
					@ -58,19 +30,6 @@ export const WindowButtons = () => {
 | 
				
			||||||
      }}
 | 
					      }}
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
      <Stack direction="row" spacing={1}>
 | 
					      <Stack direction="row" spacing={1}>
 | 
				
			||||||
        <IconButton
 | 
					 | 
				
			||||||
          onClick={toggleFullscreen}
 | 
					 | 
				
			||||||
          size="small"
 | 
					 | 
				
			||||||
          sx={{
 | 
					 | 
				
			||||||
            backgroundColor: userTheme.palette.grey[800],
 | 
					 | 
				
			||||||
          }}
 | 
					 | 
				
			||||||
        >
 | 
					 | 
				
			||||||
          {appWindow?.isFullscreen() ? (
 | 
					 | 
				
			||||||
            <FullscreenExit fontSize="inherit" />
 | 
					 | 
				
			||||||
          ) : (
 | 
					 | 
				
			||||||
            <Fullscreen fontSize="inherit" />
 | 
					 | 
				
			||||||
          )}
 | 
					 | 
				
			||||||
        </IconButton>
 | 
					 | 
				
			||||||
        <IconButton
 | 
					        <IconButton
 | 
				
			||||||
          onClick={minimize}
 | 
					          onClick={minimize}
 | 
				
			||||||
          size="small"
 | 
					          size="small"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue