diff --git a/src-tauri/src/frontend_calls/change_final_path.rs b/src-tauri/src/frontend_calls/change_final_path.rs index bc2f6f3..9a4e623 100644 --- a/src-tauri/src/frontend_calls/change_final_path.rs +++ b/src-tauri/src/frontend_calls/change_final_path.rs @@ -1,17 +1,25 @@ use std::fs; -#[tauri::command] -pub fn change_final_path(new_path: &str) { - let config_path = dirs::config_dir() - .unwrap() - .join("PhazeDev/VRChatPhotoManager/.photos_path"); +use tauri::{Emitter, State, Window}; - fs::write(&config_path, new_path.as_bytes()).unwrap(); +use crate::util::cache::Cache; +#[tauri::command] +pub fn change_final_path(new_path: &str, window: Window, cache: State) -> bool { match fs::metadata(&new_path) { - Ok(_) => {} + Ok(_) => { + let config_path = dirs::config_dir() + .unwrap() + .join("PhazeDev/VRChatPhotoManager/.photos_path"); + + fs::write(&config_path, new_path.as_bytes()).unwrap(); + cache.insert("photo-path".into(), new_path.to_owned()); + + true + } Err(_) => { - fs::create_dir(&new_path).unwrap(); + window.emit("vrcpm-error", "Error Changing Path: Path does not exist.").unwrap(); + false } - }; + } } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 12cf9c3..b01154c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -77,6 +77,7 @@ fn main() { println!("Loading App..."); let photos_path = util::get_photo_path::get_photo_path(); + println!("Loading photos from: {:#?}", &photos_path); cache.insert("photo-path".into(), photos_path.to_str().unwrap().to_owned()); diff --git a/src-tauri/src/util/get_photo_path.rs b/src-tauri/src/util/get_photo_path.rs index 9ab5689..b2d3c1f 100644 --- a/src-tauri/src/util/get_photo_path.rs +++ b/src-tauri/src/util/get_photo_path.rs @@ -7,7 +7,13 @@ pub fn get_photo_path() -> path::PathBuf { match fs::read_to_string(config_path) { Ok(path) => { - path::PathBuf::from(path) + let p = path::PathBuf::from(path); + + if fs::exists(&p).unwrap(){ + p + } else{ + dirs::picture_dir().unwrap().join("VRChat") + } }, Err(_) => { let p = dirs::picture_dir().unwrap().join("VRChat"); diff --git a/src/Components/App.tsx b/src/Components/App.tsx index 9c51e36..d90508c 100644 --- a/src/Components/App.tsx +++ b/src/Components/App.tsx @@ -1,11 +1,14 @@ -import { onMount } from "solid-js"; +import { createSignal, onMount } from "solid-js"; import PhotoList from "./PhotoList"; import PhotoViewer from "./PhotoViewer"; import SettingsMenu from "./SettingsMenu"; -import { utils } from "animejs"; +import { animate, utils } from "animejs"; +import { listen } from "@tauri-apps/api/event"; let App = () => { + let [ errorText, setErrorText ] = createSignal(''); + onMount(() => { utils.set('.settings', { @@ -13,6 +16,25 @@ let App = () => { opacity: 0, translateX: '500px' }) + + listen('vrcpm-error', ( ev ) => { + setErrorText(ev.payload); + + utils.set('.error-notif', { translateX: '-50%', translateY: '-100px' }); + animate('.error-notif', { + ease: 'outElastic', + opacity: 1, + translateY: '0px' + }); + + setTimeout(() => { + animate('.error-notif', { + ease: 'outElastic', + opacity: 0, + translateY: '-100px' + }); + }, 2000); + }); }) return ( @@ -23,6 +45,7 @@ let App = () => {
Image Copied!
+
{ errorText() }
); } diff --git a/src/Components/SettingsMenu.tsx b/src/Components/SettingsMenu.tsx index bc1551a..bf4e393 100644 --- a/src/Components/SettingsMenu.tsx +++ b/src/Components/SettingsMenu.tsx @@ -314,23 +314,26 @@ let SettingsMenu = () => { finalPathConfirm = el}> { - finalPathPreviousData = finalPathData; - finalPathConfirm.style.display = 'none'; + let changed = await invoke('change_final_path', { newPath: finalPathData }); + + if(changed){ + finalPathPreviousData = finalPathData; + finalPathConfirm.style.display = 'none'; - await invoke('change_final_path', { newPath: finalPathData }); - window.location.reload(); + window.location.reload(); - animate('.settings', { - opacity: 0, - translateX: '500px', - easing: 'easeInOutQuad', - duration: 250, - onComplete: () => { - utils.set('.settings', { display: 'none' }); - } - }) + animate('.settings', { + opacity: 0, + translateX: '500px', + easing: 'easeInOutQuad', + duration: 250, + onComplete: () => { + utils.set('.settings', { display: 'none' }); + } + }) - window.location.reload(); + window.location.reload(); + } }}> Save diff --git a/src/styles.css b/src/styles.css index 01bde5a..4bc1e11 100644 --- a/src/styles.css +++ b/src/styles.css @@ -100,4 +100,21 @@ body{ img{ max-width: 100%; max-height: 100%; +} + +.error-notif{ + position: fixed; + top: 40px; + left: 50%; + color: white; + transform: translateX(-50%) translateY(-100px); + background: rgba(43, 43, 43, 0.76); + padding: 10px 40px; + backdrop-filter: blur(10px); + -webkit-backdrop-filter: blur(10px); + border-radius: 50px; + box-shadow: #000 0 0 10px; + z-index: 12; + opacity: 0; + pointer-events: none; } \ No newline at end of file