added fullscreen window button

This commit is contained in:
Vomitblood 2024-08-10 04:27:37 +08:00
parent f237031eb3
commit 2e261a8f10
7 changed files with 62 additions and 15 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 MiB

BIN
public/images/cry.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -14,6 +14,7 @@ export const FooterBar = () => {
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
height: "66px", height: "66px",
zIndex: 1000000,
}} }}
> >
<Box <Box

View file

@ -1,5 +1,5 @@
import { DeleteOutline, FileOpenOutlined } from "@mui/icons-material"; import { DeleteOutline, FileOpenOutlined } from "@mui/icons-material";
import { Box, Button, Stack, TextField } from "@mui/material"; import { Box, Button, CircularProgress, LinearProgress, Stack, TextField, Typography } from "@mui/material";
import { open } from "@tauri-apps/api/dialog"; import { open } from "@tauri-apps/api/dialog";
import { readBinaryFile } from "@tauri-apps/api/fs"; import { readBinaryFile } from "@tauri-apps/api/fs";
import { invoke } from "@tauri-apps/api/tauri"; import { invoke } from "@tauri-apps/api/tauri";
@ -27,6 +27,7 @@ export const Background: FC<BackgroundProps> = ({ sx }) => {
const [oldWallpaperPath, setOldWallpaperPath] = useState<string | null>(null); const [oldWallpaperPath, setOldWallpaperPath] = useState<string | null>(null);
const [targetWallpaperPath, setTargetWallpaperPath] = useState<string | null>(null); const [targetWallpaperPath, setTargetWallpaperPath] = useState<string | null>(null);
const [imageBlob, setImageBlob] = useState<string | null>(null); const [imageBlob, setImageBlob] = useState<string | null>(null);
const [noImageSelectedIcon, setNoImageSelectedIcon] = useState<string | null>(null);
const handleSettingsBackgroundValueChange = ( const handleSettingsBackgroundValueChange = (
settingKey: string, settingKey: string,
@ -124,6 +125,8 @@ export const Background: FC<BackgroundProps> = ({ sx }) => {
} }
}, [targetWallpaperPath]); }, [targetWallpaperPath]);
useEffect(() => {});
return ( return (
<Box sx={{ sx }}> <Box sx={{ sx }}>
<CategoryTitle title="Wallpaper" /> <CategoryTitle title="Wallpaper" />
@ -141,11 +144,11 @@ export const Background: FC<BackgroundProps> = ({ sx }) => {
> >
{imageBlob ? ( {imageBlob ? (
<Image <Image
src={imageBlob || "oh no"}
alt="Image not found" alt="Image not found"
// fill the box r/catsareliquid // fill the box r/catsareliquid
layout="fill" layout="fill"
objectFit="cover" objectFit="cover"
src={imageBlob}
/> />
) : ( ) : (
<Box <Box
@ -153,13 +156,33 @@ export const Background: FC<BackgroundProps> = ({ sx }) => {
alignItems: "center", alignItems: "center",
backgroundColor: "rgba(0, 0, 0, 0.1)", backgroundColor: "rgba(0, 0, 0, 0.1)",
display: "flex", display: "flex",
flexDirection: "column",
height: "100%", height: "100%",
justifyContent: "center", justifyContent: "center",
position: "absolute", position: "absolute",
width: "100%", width: "100%",
}} }}
> >
No image selected {targetWallpaperPath ? (
<CircularProgress color="primary" />
) : (
<>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
alt="Image not found"
src="/images/cry.webp"
style={{
height: "50%",
}}
/>
<Typography
color="text.disabled"
variant="h6"
>
No image selected
</Typography>
</>
)}
</Box> </Box>
)} )}
</Box> </Box>

View file

@ -44,6 +44,19 @@ export const Window: FC<WindowProps> = ({ sx }) => {
} }
/> />
<CategoryTitle title="Titlebar Buttons" /> <CategoryTitle title="Titlebar Buttons" />
<SettingsItem
defaultText={defaultSettings.window.fullscreen_button ? "On" : "Off"}
description="Fullscreen button"
input={
<Switch
checked={stagedSettings.window.fullscreen_button}
name="fullscreen_button"
onChange={(e) => {
handleSettingsWindowValueChange(e.target.name, e.target.checked);
}}
/>
}
/>
<SettingsItem <SettingsItem
defaultText={defaultSettings.window.minimize_button ? "On" : "Off"} defaultText={defaultSettings.window.minimize_button ? "On" : "Off"}
description="Minimize button" description="Minimize button"

View file

@ -1,6 +1,5 @@
import { Close, CloseFullscreen, Minimize } from "@mui/icons-material"; import { Close, CloseFullscreen, 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 { exit } from "@tauri-apps/api/process";
import { WebviewWindow } from "@tauri-apps/api/window"; import { WebviewWindow } from "@tauri-apps/api/window";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useSettings } from "../../contexts/SettingsContext"; import { useSettings } from "../../contexts/SettingsContext";
@ -24,11 +23,15 @@ export const WindowButtons = () => {
setAppWindow(appWindow); setAppWindow(appWindow);
}; };
const toggleFullscreen = async () => {
appWindow?.setFullscreen(!(await appWindow?.isFullscreen()));
};
const minimize = () => { const minimize = () => {
appWindow?.minimize(); appWindow?.minimize();
}; };
const maximize = () => { const toggleMaximize = () => {
appWindow?.toggleMaximize(); appWindow?.toggleMaximize();
}; };
@ -52,6 +55,17 @@ export const WindowButtons = () => {
direction="row" direction="row"
spacing={1} spacing={1}
> >
{settings.window.fullscreen_button && (
<IconButton
onClick={toggleFullscreen}
size="small"
sx={{
backgroundColor: userTheme.palette.grey[800],
}}
>
{appWindow?.isFullscreen() ? <FullscreenExit fontSize="inherit" /> : <Fullscreen fontSize="inherit" />}
</IconButton>
)}
{settings.window.minimize_button && ( {settings.window.minimize_button && (
<IconButton <IconButton
onClick={minimize} onClick={minimize}
@ -60,23 +74,18 @@ export const WindowButtons = () => {
backgroundColor: userTheme.palette.grey[800], backgroundColor: userTheme.palette.grey[800],
}} }}
> >
<Minimize <Minimize fontSize="inherit" />
fontSize="inherit"
sx={{
backgroundColor: userTheme.palette.grey[800],
}}
/>
</IconButton> </IconButton>
)} )}
{settings.window.maximize_button && ( {settings.window.maximize_button && (
<IconButton <IconButton
onClick={maximize} onClick={toggleMaximize}
size="small" size="small"
sx={{ sx={{
backgroundColor: userTheme.palette.grey[800], backgroundColor: userTheme.palette.grey[800],
}} }}
> >
<CloseFullscreen fontSize="inherit" /> <WebAssetOutlined fontSize="inherit" />
</IconButton> </IconButton>
)} )}
<IconButton <IconButton

View file

@ -17,9 +17,10 @@ export const defaultSettings = {
radius: 8 as number, radius: 8 as number,
transition_duration: 200 as number, transition_duration: 200 as number,
window_height: 80 as number, window_height: 80 as number,
window_width: 400 as number, window_width: 500 as number,
}, },
window: { window: {
fullscreen_button: false as boolean,
maximize_button: false as boolean, maximize_button: false as boolean,
minimize_button: false as boolean, minimize_button: false as boolean,
start_fullscreen: false as boolean, // TODO: this should be true on prod start_fullscreen: false as boolean, // TODO: this should be true on prod