mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2024-11-23 03:49:41 +00:00
(feat:background) Improve the coloring of the top bar
This commit is contained in:
parent
4d37cfdb1c
commit
777adc3842
@ -10,6 +10,8 @@ import { fetch } from "@tauri-apps/api/http";
|
|||||||
import { exists } from "@tauri-apps/api/fs";
|
import { exists } from "@tauri-apps/api/fs";
|
||||||
import { convertFileSrc } from "@tauri-apps/api/tauri";
|
import { convertFileSrc } from "@tauri-apps/api/tauri";
|
||||||
|
|
||||||
|
import { prominent } from "color.js";
|
||||||
|
|
||||||
import { LauncherResponse, StoreWrite, SupportedGames } from "@backend/types.ts";
|
import { LauncherResponse, StoreWrite, SupportedGames } from "@backend/types.ts";
|
||||||
import { AppDataPath, LauncherUrls } from "@app/constants.ts";
|
import { AppDataPath, LauncherUrls } from "@app/constants.ts";
|
||||||
|
|
||||||
@ -85,24 +87,36 @@ export async function getBackgroundFile(hash: string): Promise<string> {
|
|||||||
return convertFileSrc(`${AppDataPath}/bg/${hash}.png`);
|
return convertFileSrc(`${AppDataPath}/bg/${hash}.png`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BackgroundData = {
|
||||||
|
url: string;
|
||||||
|
colors: string[];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React hook which returns the URL of the locally cached background image.
|
* React hook which returns the URL of the locally cached background image.
|
||||||
*/
|
*/
|
||||||
export function useBackground() {
|
export function useBackground(): BackgroundData {
|
||||||
const { selectedGame } = useSettings();
|
const { selectedGame } = useSettings();
|
||||||
const { backgroundHash, fetchLatestBackground } =
|
const { backgroundHash, fetchLatestBackground } =
|
||||||
selectedGame == SupportedGames.GenshinImpact ? useGenshinStore() : useStarRailStore();
|
selectedGame == SupportedGames.GenshinImpact ? useGenshinStore() : useStarRailStore();
|
||||||
const [background, setBackground] = useState<string | null>(null);
|
const [background, setBackground] = useState<string | null>(null);
|
||||||
|
const [colorPalette, setColorPalette] = useState<string[] | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (backgroundHash != "") {
|
if (backgroundHash != "") {
|
||||||
setBackground(await getBackgroundFile(backgroundHash));
|
const filePath = await getBackgroundFile(backgroundHash);
|
||||||
|
setBackground(filePath);
|
||||||
|
setColorPalette(await prominent(filePath,
|
||||||
|
{ amount: 5, format: "hex" }) as string[]);
|
||||||
} else {
|
} else {
|
||||||
fetchLatestBackground();
|
fetchLatestBackground();
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}, [backgroundHash, fetchLatestBackground]);
|
}, [backgroundHash, fetchLatestBackground]);
|
||||||
|
|
||||||
return background;
|
return {
|
||||||
|
url: background ?? "",
|
||||||
|
colors: colorPalette ?? []
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ function App() {
|
|||||||
return (
|
return (
|
||||||
<div class={"App"}
|
<div class={"App"}
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `url(${background})`
|
backgroundImage: `url(${background.url})`
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TopBar />
|
<TopBar color={background.colors[2]} />
|
||||||
|
|
||||||
<Router>
|
<Router>
|
||||||
<Route path={PageRoutes.HOME} component={Launcher} />
|
<Route path={PageRoutes.HOME} component={Launcher} />
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
import "@css/components/TopBar.scss";
|
import "@css/components/TopBar.scss";
|
||||||
|
|
||||||
function TopBar() {
|
interface IProps {
|
||||||
|
color: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TopBar(props: IProps) {
|
||||||
return (
|
return (
|
||||||
<div class={"TopBar"} data-tauri-drag-region>
|
<div class={"TopBar"} data-tauri-drag-region
|
||||||
|
style={{ backgroundColor: `${props.color}55` }}
|
||||||
|
>
|
||||||
<div class={"flex flex-row gap-1 text-white"}>
|
<div class={"flex flex-row gap-1 text-white"}>
|
||||||
<p>Cultivation</p>
|
<p>Cultivation</p>
|
||||||
<p>2.0.0</p>
|
<p>2.0.0</p>
|
||||||
|
@ -13,7 +13,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.App {
|
.App {
|
||||||
@apply w-full h-screen;
|
@apply w-full h-screen bg-no-repeat bg-contain;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
.TopBar {
|
.TopBar {
|
||||||
@apply flex flex-row justify-between items-center w-full;
|
@apply flex flex-row justify-between items-center w-full;
|
||||||
@apply bg-gray-900 pl-4 pr-4;
|
@apply pl-4 pr-4 backdrop-blur-3xl;
|
||||||
|
|
||||||
height: 40px;
|
height: 40px;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user