A photo manager for VRChat.

Fix changing photo path behaviour closes #8

phaz.uk 882c547f a263c5fb

verified
Changed files
+84 -26
src
src-tauri
+17 -9
src-tauri/src/frontend_calls/change_final_path.rs
··· 1 1 use std::fs; 2 2 3 - #[tauri::command] 4 - pub fn change_final_path(new_path: &str) { 5 - let config_path = dirs::config_dir() 6 - .unwrap() 7 - .join("PhazeDev/VRChatPhotoManager/.photos_path"); 3 + use tauri::{Emitter, State, Window}; 8 4 9 - fs::write(&config_path, new_path.as_bytes()).unwrap(); 5 + use crate::util::cache::Cache; 10 6 7 + #[tauri::command] 8 + pub fn change_final_path(new_path: &str, window: Window, cache: State<Cache>) -> bool { 11 9 match fs::metadata(&new_path) { 12 - Ok(_) => {} 10 + Ok(_) => { 11 + let config_path = dirs::config_dir() 12 + .unwrap() 13 + .join("PhazeDev/VRChatPhotoManager/.photos_path"); 14 + 15 + fs::write(&config_path, new_path.as_bytes()).unwrap(); 16 + cache.insert("photo-path".into(), new_path.to_owned()); 17 + 18 + true 19 + } 13 20 Err(_) => { 14 - fs::create_dir(&new_path).unwrap(); 21 + window.emit("vrcpm-error", "Error Changing Path: Path does not exist.").unwrap(); 22 + false 15 23 } 16 - }; 24 + } 17 25 }
+1
src-tauri/src/main.rs
··· 77 77 78 78 println!("Loading App..."); 79 79 let photos_path = util::get_photo_path::get_photo_path(); 80 + println!("Loading photos from: {:#?}", &photos_path); 80 81 81 82 cache.insert("photo-path".into(), photos_path.to_str().unwrap().to_owned()); 82 83
+7 -1
src-tauri/src/util/get_photo_path.rs
··· 7 7 8 8 match fs::read_to_string(config_path) { 9 9 Ok(path) => { 10 - path::PathBuf::from(path) 10 + let p = path::PathBuf::from(path); 11 + 12 + if fs::exists(&p).unwrap(){ 13 + p 14 + } else{ 15 + dirs::picture_dir().unwrap().join("VRChat") 16 + } 11 17 }, 12 18 Err(_) => { 13 19 let p = dirs::picture_dir().unwrap().join("VRChat");
+25 -2
src/Components/App.tsx
··· 1 - import { onMount } from "solid-js"; 1 + import { createSignal, onMount } from "solid-js"; 2 2 3 3 import PhotoList from "./PhotoList"; 4 4 import PhotoViewer from "./PhotoViewer"; 5 5 import SettingsMenu from "./SettingsMenu"; 6 - import { utils } from "animejs"; 6 + import { animate, utils } from "animejs"; 7 + import { listen } from "@tauri-apps/api/event"; 7 8 8 9 let App = () => { 10 + let [ errorText, setErrorText ] = createSignal(''); 11 + 9 12 onMount(() => { 10 13 utils.set('.settings', 11 14 { ··· 13 16 opacity: 0, 14 17 translateX: '500px' 15 18 }) 19 + 20 + listen<string>('vrcpm-error', ( ev ) => { 21 + setErrorText(ev.payload); 22 + 23 + utils.set('.error-notif', { translateX: '-50%', translateY: '-100px' }); 24 + animate('.error-notif', { 25 + ease: 'outElastic', 26 + opacity: 1, 27 + translateY: '0px' 28 + }); 29 + 30 + setTimeout(() => { 31 + animate('.error-notif', { 32 + ease: 'outElastic', 33 + opacity: 0, 34 + translateY: '-100px' 35 + }); 36 + }, 2000); 37 + }); 16 38 }) 17 39 18 40 return ( ··· 23 45 <SettingsMenu /> 24 46 25 47 <div class="copy-notif">Image Copied!</div> 48 + <div class="error-notif">{ errorText() }</div> 26 49 </div> 27 50 ); 28 51 }
+17 -14
src/Components/SettingsMenu.tsx
··· 314 314 </span> 315 315 <span style={{ display: 'none' }} ref={( el ) => finalPathConfirm = el}> 316 316 <span class="path" style={{ color: 'green' }} onClick={async () => { 317 - finalPathPreviousData = finalPathData; 318 - finalPathConfirm.style.display = 'none'; 317 + let changed = await invoke('change_final_path', { newPath: finalPathData }); 319 318 320 - await invoke('change_final_path', { newPath: finalPathData }); 321 - window.location.reload(); 319 + if(changed){ 320 + finalPathPreviousData = finalPathData; 321 + finalPathConfirm.style.display = 'none'; 322 322 323 - animate('.settings', { 324 - opacity: 0, 325 - translateX: '500px', 326 - easing: 'easeInOutQuad', 327 - duration: 250, 328 - onComplete: () => { 329 - utils.set('.settings', { display: 'none' }); 330 - } 331 - }) 323 + window.location.reload(); 324 + 325 + animate('.settings', { 326 + opacity: 0, 327 + translateX: '500px', 328 + easing: 'easeInOutQuad', 329 + duration: 250, 330 + onComplete: () => { 331 + utils.set('.settings', { display: 'none' }); 332 + } 333 + }) 332 334 333 - window.location.reload(); 335 + window.location.reload(); 336 + } 334 337 }}> 335 338 Save 336 339 </span>
+17
src/styles.css
··· 100 100 img{ 101 101 max-width: 100%; 102 102 max-height: 100%; 103 + } 104 + 105 + .error-notif{ 106 + position: fixed; 107 + top: 40px; 108 + left: 50%; 109 + color: white; 110 + transform: translateX(-50%) translateY(-100px); 111 + background: rgba(43, 43, 43, 0.76); 112 + padding: 10px 40px; 113 + backdrop-filter: blur(10px); 114 + -webkit-backdrop-filter: blur(10px); 115 + border-radius: 50px; 116 + box-shadow: #000 0 0 10px; 117 + z-index: 12; 118 + opacity: 0; 119 + pointer-events: none; 103 120 }