diff --git a/wallitor-gui/src-tauri/src/handler/wallpaper.rs b/wallitor-gui/src-tauri/src/handler/wallpaper.rs index 9180249..fef5b9e 100644 --- a/wallitor-gui/src-tauri/src/handler/wallpaper.rs +++ b/wallitor-gui/src-tauri/src/handler/wallpaper.rs @@ -1,9 +1,8 @@ -use std::path::Path; -use std::fs; use chrono::Local; use serde::{Deserialize, Serialize}; use serde_json::{self, json}; - +use std::fs; +use std::path::Path; #[derive(Deserialize)] pub struct AddInfo { @@ -13,7 +12,7 @@ pub struct AddInfo { description: String, } -#[derive(Serialize,Deserialize)] +#[derive(Serialize, Deserialize)] struct Info { media_type: String, description: String, @@ -21,12 +20,12 @@ struct Info { entry_point: String, } -#[derive(Serialize,Deserialize)] +#[derive(Serialize, Deserialize)] struct Opt { mute: bool, } -#[derive(Serialize,Deserialize)] +#[derive(Serialize, Deserialize)] pub struct Config { name: String, info: Info, @@ -102,9 +101,64 @@ pub struct EditInfo { name: String, preview: String, description: String, + mute: bool, +} + +fn delete_preview(target_dir: &String) -> bool { + if let Ok(entries) = fs::read_dir(target_dir) { + for entry in entries { + if let Ok(entry) = entry { + let path = entry.path(); + if let Some(file_name) = path.file_stem().and_then(|s| s.to_str()) { + if file_name == "preview" { + if fs::remove_file(path).is_err() { + return false; + } + } + } + } + } + } + return true; +} + +fn copy_preview(source_file: &String, target_dir: &String) -> bool { + let preview_path = Path::new(source_file); + if let Ok(true) = fs::exists(preview_path) { + if delete_preview(target_dir) { + if let Some(ext) = preview_path.extension().and_then(|f| f.to_str()) { + if fs::copy( + preview_path, + Path::new(&format!("{}/preview.{}", target_dir, ext)), + ) + .is_ok() + { + return true; + } + } + } + } + return false; } #[tauri::command] -pub async fn edit_wallpaper(title: String) -> bool { - true -} \ No newline at end of file +pub async fn edit_wallpaper(info: EditInfo) -> bool { + let folder_path = Path::new(&info.path); + if let Ok(true) = fs::exists(folder_path) { + let config_path_str = format!("{}/config.json", info.path); + let config_path = Path::new(&config_path_str); + if let Ok(file) = fs::read(config_path) { + let mut config: Config = serde_json::from_slice(&file).unwrap(); + config.info.description = info.description; + config.name = info.name; + config.option.mute = info.mute; + if let Ok(()) = fs::write(config_path, json!(config).to_string()) { + if !info.preview.is_empty() { + return copy_preview(&info.preview, &info.path); + } + return true; + } + } + } + false +} diff --git a/wallitor-gui/src/assets/svgs/direction-left.svg b/wallitor-gui/src/assets/svgs/direction-left.svg new file mode 100644 index 0000000..1f8b0ad --- /dev/null +++ b/wallitor-gui/src/assets/svgs/direction-left.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wallitor-gui/src/assets/svgs/edit.svg b/wallitor-gui/src/assets/svgs/edit.svg new file mode 100644 index 0000000..6e50829 --- /dev/null +++ b/wallitor-gui/src/assets/svgs/edit.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/wallitor-gui/src/components/ApplyBar.vue b/wallitor-gui/src/components/ApplyBar.vue index 32b9ea0..c9f33f0 100644 --- a/wallitor-gui/src/components/ApplyBar.vue +++ b/wallitor-gui/src/components/ApplyBar.vue @@ -67,7 +67,7 @@ const props = defineProps({ }) const store = useStore(); const visible = defineModel(); -const emit = defineEmits(["submit"]); +defineEmits(["submit"]); const visible_ = ref(false); const cell = ref({ img: "", @@ -107,9 +107,9 @@ function open(conFig: Cell) { } function apply() { - store.commit("apply_wallpaper",{ - url:`/video/?url=${cell.value.path}\\res\\${cell.value.config.info.entry_point}&mute=${cell.value.config.option.mute}`, - title:"wallitor_video_playback" + store.commit("apply_wallpaper", { + url: `/video/?url=${cell.value.path}\\res\\${cell.value.config.info.entry_point}&mute=${cell.value.config.option.mute}`, + title: "wallitor_video_playback" }) appWindow.minimize(); } diff --git a/wallitor-gui/src/components/EditItem.vue b/wallitor-gui/src/components/EditItem.vue index a73ce5c..fe07766 100644 --- a/wallitor-gui/src/components/EditItem.vue +++ b/wallitor-gui/src/components/EditItem.vue @@ -13,9 +13,16 @@ - + + + + + 点击添加封面 + + + @@ -23,6 +30,12 @@ + + 静音 + + + + 添加 @@ -105,8 +118,9 @@ function handleEdit() { invoke("edit_wallpaper", { info: info }).then((res) => { + console.log(info); if (applyButton.value) applyButton.value.disabled = false; - if (res as string == "Success") { + if (res as boolean) { store.commit("getWpList"); emit("submit"); ElMessage({ diff --git a/wallitor-gui/src/components/TitleBar.vue b/wallitor-gui/src/components/TitleBar.vue index 1e82b15..f2ea9af 100644 --- a/wallitor-gui/src/components/TitleBar.vue +++ b/wallitor-gui/src/components/TitleBar.vue @@ -26,7 +26,7 @@ - + @@ -63,7 +63,9 @@ import SvgIcon from '@/components/SvgIcon.vue'; import { ref, defineProps } from 'vue' import type { PropType } from 'vue' import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'; +import { useRouter } from 'vue-router'; const appWindow = getCurrentWebviewWindow(); +const router = useRouter(); type Mode = "win" | "mac"; @@ -89,6 +91,10 @@ function toggleMaximize() { function close() { appWindow.hide(); } + +function openSettings() { + router.push("settings"); +}