this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add auto loading

phaz.uk 6f2f8a3e 195e6566

verified
+75 -58
+13
src-tauri/src/frontend_calls/load_previous_tabs.rs
···
··· 1 + use std::collections::HashMap; 2 + 3 + use tauri::State; 4 + 5 + use crate::{ structs::nodes::Node, utils::config::Config }; 6 + 7 + #[tauri::command] 8 + pub fn load_previous_tabs( conf: State<Config> ) -> HashMap<String, Vec<Node>> { 9 + let config = conf.store.lock().unwrap(); 10 + 11 + let tabs = config.loaded_tabs.clone(); 12 + tabs 13 + }
+2 -1
src-tauri/src/frontend_calls/mod.rs
··· 1 pub mod get_addresses; 2 pub mod save_graph; 3 - pub mod sync_tab;
··· 1 pub mod get_addresses; 2 pub mod save_graph; 3 + pub mod sync_tab; 4 + pub mod load_previous_tabs;
+17 -5
src-tauri/src/frontend_calls/sync_tab.rs
··· 2 3 use tauri::State; 4 5 - use crate::{ runtime::commands::RuntimeCommand, structs::nodes::Node }; 6 7 #[tauri::command] 8 - pub fn sync_tab( graph: Vec<Node>, id: String, cmd: State<Sender<RuntimeCommand>> ){ 9 - cmd.send(RuntimeCommand::AddTab(graph, id)).unwrap(); 10 } 11 12 #[tauri::command] 13 - pub fn discard_tab( id: String, cmd: State<Sender<RuntimeCommand>> ){ 14 - cmd.send(RuntimeCommand::RemoveTab(id)).unwrap(); 15 }
··· 2 3 use tauri::State; 4 5 + use crate::{ runtime::commands::RuntimeCommand, structs::nodes::Node, utils::config::Config }; 6 7 #[tauri::command] 8 + pub fn sync_tab( graph: Vec<Node>, id: String, cmd: State<Sender<RuntimeCommand>>, conf: State<Config> ){ 9 + cmd.send(RuntimeCommand::AddTab(graph.clone(), id.clone())).unwrap(); 10 + 11 + let mut config = conf.store.lock().unwrap(); 12 + config.loaded_tabs.insert(id, graph); 13 + drop(config); 14 + 15 + conf.save(); 16 } 17 18 #[tauri::command] 19 + pub fn discard_tab( id: String, cmd: State<Sender<RuntimeCommand>>, conf: State<Config> ){ 20 + cmd.send(RuntimeCommand::RemoveTab(id.clone())).unwrap(); 21 + 22 + let mut config = conf.store.lock().unwrap(); 23 + config.loaded_tabs.remove(&id); 24 + drop(config); 25 + 26 + conf.save(); 27 }
+3 -2
src-tauri/src/lib.rs
··· 16 #[tokio::main] 17 pub async fn run() { 18 // TODO: Impl background running by default 19 - // TODO: Auto loading last loaded tabs 20 21 let container_folder = dirs::config_dir().unwrap().join("VRCMacros"); 22 ··· 47 get_addresses::get_addresses, 48 save_graph::save_graph, 49 sync_tab::sync_tab, 50 - sync_tab::discard_tab 51 ]) 52 .manage(conf) 53 .manage(&ADDRESSES)
··· 16 #[tokio::main] 17 pub async fn run() { 18 // TODO: Impl background running by default 19 + // TODO: Delay close if unsaved tabs 20 21 let container_folder = dirs::config_dir().unwrap().join("VRCMacros"); 22 ··· 47 get_addresses::get_addresses, 48 save_graph::save_graph, 49 sync_tab::sync_tab, 50 + sync_tab::discard_tab, 51 + load_previous_tabs::load_previous_tabs 52 ]) 53 .manage(conf) 54 .manage(&ADDRESSES)
+2 -2
src-tauri/src/setup.rs
··· 3 4 use flate2::read::GzDecoder; 5 use serde_json::{ Map, Value }; 6 - use tauri::{ App, Emitter, Listener, Manager }; 7 8 - use crate::{ osc::{ self, OSCMessage }, runtime::{ commands::RuntimeCommand, nodes::RuntimeNodeTree, runtime, runtime_dry }, structs::parameter_types::ParameterType }; 9 10 pub fn setup( 11 app: &mut App,
··· 3 4 use flate2::read::GzDecoder; 5 use serde_json::{ Map, Value }; 6 + use tauri::{ App, Emitter, Listener, Manager, State }; 7 8 + use crate::{ osc::{ self, OSCMessage }, runtime::{ commands::RuntimeCommand, nodes::RuntimeNodeTree, runtime, runtime_dry }, structs::parameter_types::ParameterType, utils::config::Config }; 9 10 pub fn setup( 11 app: &mut App,
+4 -8
src-tauri/src/structs/nodes.rs
··· 1 use serde::{ Deserialize, Serialize }; 2 use serde_json::Value; 3 4 - #[derive(Serialize, Deserialize, Debug)] 5 pub struct Node{ 6 pub id: String, 7 pub name: String, ··· 13 pub type_id: String 14 } 15 16 - impl Node{ 17 - 18 - } 19 - 20 - #[derive(Serialize, Deserialize, Debug)] 21 pub struct NodeStatic{ 22 pub name: String, 23 ··· 26 pub value: Value 27 } 28 29 - #[derive(Serialize, Deserialize, Debug)] 30 pub struct NodeOutput{ 31 pub name: String, 32 ··· 35 pub connections: Vec<NodeOutputConnections> 36 } 37 38 - #[derive(Serialize, Deserialize, Debug)] 39 pub struct NodeOutputConnections{ 40 pub name: String, 41 pub node: String,
··· 1 use serde::{ Deserialize, Serialize }; 2 use serde_json::Value; 3 4 + #[derive(Serialize, Deserialize, Debug, Clone)] 5 pub struct Node{ 6 pub id: String, 7 pub name: String, ··· 13 pub type_id: String 14 } 15 16 + #[derive(Serialize, Deserialize, Debug, Clone)] 17 pub struct NodeStatic{ 18 pub name: String, 19 ··· 22 pub value: Value 23 } 24 25 + #[derive(Serialize, Deserialize, Debug, Clone)] 26 pub struct NodeOutput{ 27 pub name: String, 28 ··· 31 pub connections: Vec<NodeOutputConnections> 32 } 33 34 + #[derive(Serialize, Deserialize, Debug, Clone)] 35 pub struct NodeOutputConnections{ 36 pub name: String, 37 pub node: String,
+14 -34
src-tauri/src/utils/config.rs
··· 1 - use std::{ 2 - collections::HashMap, 3 - fs::File, 4 - io::{Read, Write}, 5 - path::PathBuf, 6 - sync::Mutex, 7 - }; 8 9 - use flate2::{read::GzDecoder, write::GzEncoder, Compression}; 10 - use serde_json::Value; 11 12 pub struct Config { 13 - store: Mutex<HashMap<String, Value>>, 14 path: PathBuf, 15 } 16 ··· 26 "{}".into() 27 }; 28 29 - let json: Value = serde_json::from_str(&json_string).unwrap(); 30 - 31 - let mut hashmap = HashMap::new(); 32 - 33 - let obj = json.as_object().unwrap(); 34 - for (key, val) in obj { 35 - hashmap.insert(key.clone(), val.clone()); 36 - } 37 38 Config { 39 - store: Mutex::new(hashmap), 40 path: path, 41 - } 42 - } 43 - 44 - pub fn set(&self, key: &str, value: Value) { 45 - self.store.lock().unwrap().insert(key.to_owned(), value); 46 - } 47 - 48 - pub fn get(&self, key: &str) -> Option<Value> { 49 - let store = self.store.lock().unwrap(); 50 - let val = store.get(&key.to_owned()); 51 - 52 - if val.is_none() { 53 - None 54 - } else { 55 - Some(val.unwrap().clone()) 56 } 57 } 58
··· 1 + use std::{ collections::HashMap, fs::File, io::{ Read, Write }, path::PathBuf, sync::Mutex }; 2 3 + use flate2::{ read::GzDecoder, write::GzEncoder, Compression }; 4 + use serde::{ Deserialize, Serialize }; 5 + 6 + use crate::structs::nodes::Node; 7 + 8 + #[derive(Clone, Serialize, Deserialize, Debug)] 9 + pub struct ConfigValues{ 10 + #[serde(default)] 11 + pub loaded_tabs: HashMap<String, Vec<Node>> 12 + } 13 14 pub struct Config { 15 + pub store: Mutex<ConfigValues>, 16 path: PathBuf, 17 } 18 ··· 28 "{}".into() 29 }; 30 31 + let json: ConfigValues = serde_json::from_str(&json_string).unwrap(); 32 33 Config { 34 + store: Mutex::new(json), 35 path: path, 36 } 37 } 38
+20 -6
src/Mangers/NodeManager.tsx
··· 24 NodeManager.Instance = this; 25 26 listen('load_new_tab', ( ev: any ) => { 27 - this._loadFromConfig(ev.payload.path, ev.payload.graph); 28 - }) 29 } 30 31 32 private _tabUpdateHook: ( tabs: TabHashMap ) => void = () => {}; 33 private _tabChangeHook: () => void = () => {}; 34 35 - public async AddTab( name: string ): Promise<Tab>{ 36 let [ selected, setSelected ] = createSignal(false); 37 let [ needsSave, setNeedsSave ] = createSignal(false); 38 39 let tab: Tab = { 40 name: name, 41 - id: await NodeManager.Instance.GetNewNodeId(), 42 nodes: [], 43 saveLocation: null, 44 ··· 206 if(needsSave)tab.setNeedsSave(true); 207 } 208 209 - private async _loadFromConfig( path: string, config: string ){ 210 let json = JSON.parse(config); 211 212 if( ··· 215 !json.graph 216 )return; 217 218 - let tab = await this.AddTab(json.tab_name); 219 tab.refuseSync = true; 220 tab.saveLocation = path; 221
··· 24 NodeManager.Instance = this; 25 26 listen('load_new_tab', ( ev: any ) => { 27 + this._loadFromConfig(ev.payload.path, null, ev.payload.graph); 28 + }); 29 + 30 + invoke('load_previous_tabs').then(async ( tabs: any ) => { 31 + let version = await getVersion(); 32 + 33 + for(let tab of Object.entries(tabs)){ 34 + console.log(tab); 35 + 36 + await this._loadFromConfig(null, tab[0], JSON.stringify({ 37 + tab_name: 'test', 38 + version, 39 + graph: tab[1] 40 + })); 41 + }; 42 + }); 43 } 44 45 46 private _tabUpdateHook: ( tabs: TabHashMap ) => void = () => {}; 47 private _tabChangeHook: () => void = () => {}; 48 49 + public async AddTab( name: string, id: string | null = null ): Promise<Tab>{ 50 let [ selected, setSelected ] = createSignal(false); 51 let [ needsSave, setNeedsSave ] = createSignal(false); 52 53 let tab: Tab = { 54 name: name, 55 + id: id || await NodeManager.Instance.GetNewNodeId(), 56 nodes: [], 57 saveLocation: null, 58 ··· 220 if(needsSave)tab.setNeedsSave(true); 221 } 222 223 + private async _loadFromConfig( path: string | null, id: string | null, config: string ){ 224 let json = JSON.parse(config); 225 226 if( ··· 229 !json.graph 230 )return; 231 232 + let tab = await this.AddTab(json.tab_name, id); 233 tab.refuseSync = true; 234 tab.saveLocation = path; 235