added custom draggable headerbar

This commit is contained in:
Vomitblood 2024-07-30 23:05:36 +08:00
parent 31eecb243a
commit 6e1be3513b
3 changed files with 87 additions and 15 deletions

View file

@ -27,7 +27,40 @@
"all": true "all": true
}, },
"window": { "window": {
"all": true "all": true,
"create": true,
"center": true,
"requestUserAttention": true,
"setResizable": true,
"setMaximizable": true,
"setMinimizable": true,
"setClosable": true,
"setTitle": true,
"maximize": true,
"unmaximize": true,
"minimize": true,
"unminimize": true,
"show": true,
"hide": true,
"close": true,
"setDecorations": true,
"setAlwaysOnTop": true,
"setContentProtected": true,
"setSize": true,
"setMinSize": true,
"setMaxSize": true,
"setPosition": true,
"setFullscreen": true,
"setFocus": true,
"setIcon": true,
"setSkipTaskbar": true,
"setCursorGrab": true,
"setCursorVisible": true,
"setCursorIcon": true,
"setCursorPosition": true,
"setIgnoreCursorEvents": true,
"startDragging": true,
"print": true
} }
}, },
"bundle": { "bundle": {
@ -71,6 +104,7 @@
}, },
"windows": [ "windows": [
{ {
"decorations": false,
"fullscreen": false, "fullscreen": false,
"height": 600, "height": 600,
"resizable": true, "resizable": true,

View file

@ -1,25 +1,45 @@
import { Box, Button, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import { WindowButtons } from "./WindowButtons"; import { WindowButtons } from "./WindowButtons";
export const HeaderBar = () => { export const HeaderBar = () => {
const test = async () => {
console.log("hello");
};
return ( return (
<Box <Box
className="titlebar"
data-tauri-drag-region="true"
sx={{ sx={{
alignItems: "center",
// TODO: remove when done
borderBottom: "1px solid red",
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
height: "64px", height: "64px",
justifyContent: "space-between",
p: 1, p: 1,
}} }}
> >
hello this is the left side <Box
<Box sx={{ flexGrow: 1 }} /> className="titlebar"
<Typography>hello this is the right side |</Typography> data-tauri-drag-region="true"
<Button onClick={test}>Relaunch</Button> sx={{
<WindowButtons /> alignItems: "center",
display: "flex",
flexDirection: "row",
}}
>
hello this is the left side
</Box>
<Box
className="titlebar"
data-tauri-drag-region="true"
sx={{
alignItems: "center",
display: "flex",
flexDirection: "row",
}}
>
<Typography>hello this is the right side |</Typography>
<WindowButtons />
</Box>
</Box> </Box>
); );
}; };

View file

@ -1,22 +1,40 @@
import { Close, CloseFullscreen, Minimize } from "@mui/icons-material"; import { Close, CloseFullscreen, Minimize } from "@mui/icons-material";
import { Box, Button, ButtonGroup, Stack, useTheme } from "@mui/material"; import { Box, Button, ButtonGroup, Stack, useTheme } from "@mui/material";
import { appWindow } from "@tauri-apps/api/window"; import { WebviewWindow } from "@tauri-apps/api/window";
import { useEffect, useState } from "react";
export const WindowButtons = () => { export const WindowButtons = () => {
const userTheme = useTheme(); const userTheme = useTheme();
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 () => {
const { appWindow } = await import("@tauri-apps/api/window");
setAppWindow(appWindow);
};
const minimize = () => { const minimize = () => {
appWindow.minimize(); appWindow?.minimize();
}; };
const maximize = () => { const maximize = () => {
appWindow.toggleMaximize(); appWindow?.toggleMaximize();
}; };
const close = () => { const close = () => {
appWindow.close(); appWindow?.close();
}; };
useEffect(() => {
initializeAppWindow();
});
return ( return (
<Box> <Box>
<Stack direction="row" spacing={1}> <Stack direction="row" spacing={1}>