diff --git a/src-tauri/src/http.rs b/src-tauri/src/http.rs new file mode 100644 index 0000000..da95b67 --- /dev/null +++ b/src-tauri/src/http.rs @@ -0,0 +1,25 @@ +use core::error::Error; +use std::fs::File; +use std::io::Write; +use std::path::Path; + +/// Downloads a file from the given URL. +/// Saves it to the specified file. +/// This will overwrite the file if it already exists. +/// url: The URL to download from. +/// to_file: The file to save to. +#[tauri::command] +pub async fn download_file(url: String, to_file: String) -> Result> { + let mut response = reqwest::get(&url).await?; + let mut dest = { + let fname = Path::new(&to_file); + match File::create(&fname) { + Ok(f) => f, + Err(e) => return Err(Box::new(e)), + } + }; + while let Some(chunk) = response.chunk().await? { + dest.write_all(&chunk).await?; + } + Ok("Downloaded".to_string()) +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1da6d01..cc9c208 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -15,6 +15,9 @@ "shell": { "all": false, "open": true + }, + "window": { + "startDragging": true } }, "bundle": { @@ -36,6 +39,7 @@ { "fullscreen": false, "resizable": true, + "decorations": false, "title": "Cultivation", "width": 1280, "height": 730 diff --git a/src/backend/stores/mihoyo.ts b/src/backend/stores/mihoyo.ts new file mode 100644 index 0000000..54219b6 --- /dev/null +++ b/src/backend/stores/mihoyo.ts @@ -0,0 +1,28 @@ +import { create } from "zustand"; +import { persist, createJSONStorage } from "zustand/middleware"; + +import { invoke } from "@tauri-apps/api"; + +export type GenshinStore = { + backgroundHash: string; +}; + +export const useGenshinStore = create( + persist( + (): GenshinStore => ({ + backgroundHash: "" + }), + { + name: "genshin", + storage: createJSONStorage(() => localStorage) + } + ) +); + +/** + * React hook which returns the URL of the locally cached background image. + */ +export function useBackground() { + const { backgroundHash } = useGenshinStore(); + const [background, setBackground] = useState(null); +}