(misc) Enable window.startDragging for Tauri

This commit is contained in:
KingRainbow44
2023-11-23 14:00:00 +01:00
parent 6fd11bb6f5
commit bb64f8ff3d
3 changed files with 57 additions and 0 deletions

25
src-tauri/src/http.rs Normal file
View File

@@ -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<String, Box<dyn Error>> {
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())
}

View File

@@ -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

View File

@@ -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<string | null>(null);
}