From a964264134ed58d3bd7769fdc873779cbee03a84 Mon Sep 17 00:00:00 2001 From: Vomitblood Date: Wed, 7 Aug 2024 15:04:05 +0800 Subject: [PATCH] added background settings panel --- build.sh | 6 +- src-tauri/tauri.conf.json | 7 +- src/components/Generic/Layout.tsx | 6 +- .../HeaderBar/Settings/Settings.tsx | 11 ++ .../SettingsTabs/SettingsTabBackground.tsx | 120 ++++++++++++------ src/lib/settings.ts | 8 +- src/pages/testing.tsx | 45 ++++--- 7 files changed, 125 insertions(+), 78 deletions(-) diff --git a/build.sh b/build.sh index 9afe1a6..1ad6bc1 100644 --- a/build.sh +++ b/build.sh @@ -29,7 +29,7 @@ docker run --rm -it \ mise settings set experimental true && \ mise exec bun --command \"bun run tauri build\" - chown -R $USER_ID:$GROUP_ID $CONTAINER_PROJECT_DIR - " + chown -R $USER_ID:$GROUP_ID $CONTAINER_PROJECT_DIR && \ -echo "Build complete. Output available in $HOST_OUTPUT_DIR" + echo "Build complete. Output available in $HOST_OUTPUT_DIR" + " diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 906e79d..6b5fb63 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,12 +13,7 @@ "tauri": { "allowlist": { "dialog": { - "all": true, - "ask": true, - "confirm": true, - "message": true, - "open": true, - "save": true + "all": true }, "fs": { "all": true, diff --git a/src/components/Generic/Layout.tsx b/src/components/Generic/Layout.tsx index 5a4b055..43bd94c 100644 --- a/src/components/Generic/Layout.tsx +++ b/src/components/Generic/Layout.tsx @@ -3,12 +3,15 @@ import { convertFileSrc } from "@tauri-apps/api/tauri"; import { useState } from "react"; import { FooterBar } from "../FooterBar"; import { HeaderBar } from "../HeaderBar/HeaderBar"; +import { useSettings } from "../../contexts/SettingsContext"; export const Layout = () => { + const { settings } = useSettings(); + const [imageUrl, setImageUrl] = useState(null); const setBackground = async () => { - const assetUrl = convertFileSrc("/home/vomitblood/build/stort/public/images/background.jpg"); + const assetUrl = convertFileSrc("/home/vomitblood/Downloads/toothless-dance.gif"); setImageUrl(assetUrl); }; @@ -16,6 +19,7 @@ export const Layout = () => { { // contexts @@ -104,6 +105,10 @@ export const Settings = () => { label="Style" value="style" /> + { > + + + = ({ sx }) => { +export const SettingsTabBackground: FC = ({ sx }) => { // atoms const [stagedSettings, setStagedSettings] = useAtom(stagedSettingsAtom); - const handleSettingsWindowValueChange = (settingKey: string, settingValue: boolean | number | string | number[]) => { + const handleSettingsBackgroundValueChange = ( + settingKey: string, + settingValue: boolean | number | string | number[], + ) => { const newSettings = { ...stagedSettings, - window: { - ...stagedSettings.window, + background: { + ...stagedSettings.background, [settingKey]: settingValue, }, }; setStagedSettings(newSettings); }; + const selectImage = async () => { + const selected = await open({ + multiple: false, + filters: [ + { + name: "Images", + extensions: ["jpg", "png", "jpeg", "webp", "gif"], + }, + ], + }); + + if (selected) { + console.log(selected); + } + }; + + // TODO: implement + const clearImage = async () => {}; + return ( - + + + Image not found + + + + + + + + { - handleSettingsWindowValueChange(e.target.name, e.target.checked); + handleSettingsBackgroundValueChange(e.target.name, e.target.value); }} - /> - } - /> - - { - handleSettingsWindowValueChange(e.target.name, e.target.checked); - }} - /> - } - /> - { - handleSettingsWindowValueChange(e.target.name, e.target.checked); + sx={{ + width: "100%", }} + size="small" + type="color" + value={stagedSettings.background.background_color} + variant="standard" /> } /> diff --git a/src/lib/settings.ts b/src/lib/settings.ts index 0d21213..735c4d8 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -4,12 +4,8 @@ import { readTomlFile, writeTomlFile } from "./utils/toml"; export const defaultSettings = { background: { - background_color: "#8ab4f8" as string, - background_image: "" as string, - background_image_size: "cover" as string, - background_image_position: "center" as string, - background_image_repeat: "no-repeat" as string, - footer_background_color: "#8ab4f8" as string, + background_color: "#202124" as string, + background_image_path: "" as string, }, style: { accent_color: "#8ab4f8" as string, diff --git a/src/pages/testing.tsx b/src/pages/testing.tsx index da4989f..da5c755 100644 --- a/src/pages/testing.tsx +++ b/src/pages/testing.tsx @@ -2,6 +2,7 @@ import { BugReport } from "@mui/icons-material"; import { Box, Button, IconButton, TextField, Typography } from "@mui/material"; import { useRouter } from "next/router"; import { useState } from "react"; +import { SettingsItem } from "../components/HeaderBar/Settings/SettingsItem"; import { useSettings } from "../contexts/SettingsContext"; import { testing } from "../lib/testing"; @@ -12,6 +13,7 @@ export default function Testing() { // states const [text, setText] = useState(""); + const [color, setColor] = useState("#000000"); return ( @@ -29,28 +31,7 @@ export default function Testing() { > reset settings - + {text} - + { + setColor(e.target.value); + }} + sx={{ + width: "100%", + }} + size="small" + type="color" + value={color} + variant="standard" + /> + } + /> ); }