Skip to content

Commit

Permalink
refactor: general clean up
Browse files Browse the repository at this point in the history
- ported tauri command for http client to plugin finished
  • Loading branch information
ZanzyTHEbar committed Oct 5, 2023
1 parent 8709d50 commit 7a628a6
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 318 deletions.
131 changes: 131 additions & 0 deletions GUI/ETVR/src-tauri/src/lib/splashscreen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,134 @@ mod test {
);
}
}

/*
release_id: 0,
new_release: false,
assets: [],
*/
// ! DEPRECATED - but it works ....
/*pub async fn run_gh_release_assets() -> Result<String, String> {
info!("Starting GitHub release client");
let gh_response = run_gh_release_latest().await;
let mut request_response: String = String::new();
match gh_response {
Ok(response) => {
request_response = response;
/* println!(
"[Github Release Asset]: Request Response: {:?}",
request_response
); */
}
Err(e) => println!("[Github Release Asset]: Request failed: {}", e),
}
let json_response = serde_json::from_str::<Map<String, Value>>(&request_response);
match json_response {
Ok(response) => {
println!("[Github Release]: JSON response: {:?}", response);
// check if the json object is empty
if response.is_empty() {
warn!("[Github Release]: JSON object is empty");
return Err("[Github Release]: JSON object is empty".into());
}
// check if the json object has the key "id" - and if it does check if the value is the same as the current value saved to the file
if response.contains_key("id") {
let id = response["id"].to_string();
// read the json config file and create it if it doesn't exist
let mut data = String::new();
let mut file = std::fs::OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open("config/config.json");
match file {
Ok(ref mut file) => {
file.read_to_string(&mut data).unwrap();
}
Err(e) => {
error!("[Github Release]: Unable to open config file: {}", e);
return Err("[Github Release]: Unable to open config file".into());
}
}
// if the file is empty, create a new file with the id, and assets array
if data.is_empty() {
println!("[Github Release]: File is empty - creating new file");
let mut config = Map::new();
let mut assets = Map::new();
let mut asset = Map::new();
asset.insert("id".to_string(), Value::String(id));
asset.insert("new_release".to_string(), Value::Bool(true));
let mut assets_array = Vec::new();
// get the assets array from the json response and add it to the assets_array
let assets_array_json = response["assets"].as_array();
let assets_array_json_result = match assets_array_json {
Some(assets_array_json) => assets_array_json,
None => {
error!("[Github Release]: Unable to get assets array");
return Err("[Github Release]: Unable to get assets array".into());
}
};
for asset in assets_array_json_result {
assets_array.push(asset.clone());
}
asset.insert("assets".to_string(), Value::Array(assets_array));
assets.insert("OpenIris".to_string(), Value::Object(asset));
config.insert("assets".to_string(), Value::Object(assets));
let config_json = serde_json::to_string_pretty(&config).unwrap();
std::fs::write("config/config.json", config_json).expect("Unable to write file");
return Ok("[Github Release]: Grabbed Newest Github Asset Config - Created new config file".to_string());
}
// we got hre because the file is not empty - so parse the json config file
// check if the id is the same as the one in the config file
// if the id is the same, return and do nothing
// if the id is different, update the config file with the new id and assets array
// parse the json config file
let config: serde_json::Value = serde_json::from_str(&data).map_err(|e| e.to_string())?;
debug!("[Github Release]: Current Config: {:?}", config);
if id == config["assets"]["OpenIris"]["id"] {
println!("[Github Release]: No new release - using cached config");
return Ok("[Github Release]: Grabbed Newest Github Asset Config".to_string());
}
let mut config = Map::new();
let mut assets = Map::new();
let mut asset = Map::new();
asset.insert("id".to_string(), Value::String(id));
asset.insert("new_release".to_string(), Value::Bool(true));
let mut assets_array = Vec::new();
// get the assets array from the json response and add it to the assets_array
let assets_array_json = response["assets"].as_array();
let assets_array_json_result = match assets_array_json {
Some(assets_array_json) => assets_array_json,
None => {
error!("Unable to get assets array");
return Err("Unable to get assets array".into());
}
};
for asset in assets_array_json_result {
assets_array.push(asset.clone());
}
asset.insert("assets".to_string(), Value::Array(assets_array));
assets.insert("OpenIris".to_string(), Value::Object(asset));
config.insert("assets".to_string(), Value::Object(assets));
let config_json = serde_json::to_string_pretty(&config).unwrap();
std::fs::write("config/config.json", config_json).expect("Unable to write file");
return Ok("[Github Release]: Grabbed Newest Github Asset Config".to_string());
}
}
Err(e) => println!("JSON parse failed: {}", e),
}
Ok("[Github Release]: Grabbed Newest Github Asset Config".to_string())
} */
9 changes: 9 additions & 0 deletions GUI/ETVR/src-tauri/src/lib/util/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ pub struct W<T>(pub T);
pub fn generate_plugin_path(plugin_name: &str) -> String {
f!("{}{}.ts", EXPORT_PATH_ROOT, plugin_name)
}

macro_rules! tauri_handlers {
($($name:path),+) => {{
#[cfg(debug_assertions)]
tauri_specta::ts::export(specta::collect_types![$($name),+], "../../../src/static/types/tauri_types.ts").unwrap();

tauri::generate_handler![$($name),+]
}};
}
2 changes: 1 addition & 1 deletion GUI/ETVR/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ async fn main() -> tauri::Result<()> {
//tauri_commands::close_splashscreen,
tauri_commands::run_mdns_query,
tauri_commands::get_user,
tauri_commands::do_rest_request,
tauri_commands::unzip_archive,
tauri_commands::handle_save_window_state,
tauri_commands::handle_load_window_state,
Expand All @@ -106,6 +105,7 @@ async fn main() -> tauri::Result<()> {
.plugin(tauri_plugin_upload::init())
// splashscreen support
.plugin(tauri_plugin_splashscreen::init())
.plugin(tauri_plugin_request_client::init())
// LocalHost REST Client
.plugin(tauri_plugin_request_client::init())
// save window position and size between sessions
Expand Down
1 change: 0 additions & 1 deletion GUI/ETVR/src-tauri/src/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod mdns_query;
pub mod menu;
pub mod python_backend;
pub mod rest_client;
pub mod tauri_commands;
Loading

0 comments on commit 7a628a6

Please sign in to comment.