diff --git a/src-tauri/src/auth.rs b/src-tauri/src/auth.rs index d398cc6..eb1b000 100644 --- a/src-tauri/src/auth.rs +++ b/src-tauri/src/auth.rs @@ -1,7 +1,7 @@ use std::{env, sync::Mutex}; use chrono::Utc; -use log::{info, warn}; +use log::{debug, error, info, warn}; use openssl::{ec::EcKey, hash::MessageDigest, pkey::PKey, sign::Signer}; use serde::{Deserialize, Serialize}; use tauri::{AppHandle, Emitter, Manager}; @@ -74,17 +74,17 @@ pub fn fetch_user() -> Result { .send()?; if response.status() != 200 { - let data = response.json::()?; - info!("Could not fetch user: {}", data.status_message); + let err: DropServerError = response.json().unwrap(); + warn!("{:?}", err); - if data.status_message == "Nonce expired" { + if err.status_message == "Nonce expired" { return Err(RemoteAccessError::OutOfSync); } - return Err(RemoteAccessError::InvalidCodeError(0)); + return Err(RemoteAccessError::InvalidResponse(err)); } - let user = response.json::()?; + let user = response.json()?; Ok(user) } @@ -113,8 +113,8 @@ fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), RemoteAc let endpoint = base_url.join("/api/v1/client/auth/handshake")?; let client = reqwest::blocking::Client::new(); let response = client.post(endpoint).json(&body).send()?; - info!("{}", response.status().as_u16()); - let response_struct = response.json::()?; + debug!("Handshake responsded with {}", response.status().as_u16()); + let response_struct: HandshakeResponse = response.json()?; { let mut handle = DB.borrow_data_mut().unwrap(); @@ -173,8 +173,8 @@ fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { let response = client.post(endpoint.to_string()).json(&body).send()?; if response.status() != 200 { - let data = response.json::()?; - info!("Could not start handshake: {}", data.status_message); + let data: DropServerError = response.json()?; + error!("Could not start handshake: {}", data.status_message); return Err(RemoteAccessError::HandshakeFailed(data.status_message)); } @@ -182,7 +182,7 @@ fn auth_initiate_wrapper() -> Result<(), RemoteAccessError> { let redir_url = response.text()?; let complete_redir_url = base_url.join(&redir_url)?; - info!("opening web browser to continue authentication"); + debug!("opening web browser to continue authentication"); webbrowser::open(complete_redir_url.as_ref()).unwrap(); Ok(()) @@ -235,8 +235,6 @@ pub fn setup() -> Result<(AppStatus, Option), ()> { #[tauri::command] pub fn sign_out(app: AppHandle) -> Result<(), String> { - info!("Signing out user"); - // Clear auth from database { let mut handle = DB.borrow_data_mut().unwrap(); diff --git a/src-tauri/src/autostart.rs b/src-tauri/src/autostart.rs index 5b7c1ba..aa41fcb 100644 --- a/src-tauri/src/autostart.rs +++ b/src-tauri/src/autostart.rs @@ -1,5 +1,5 @@ use crate::DB; -use log::info; +use log::debug; use tauri::AppHandle; use tauri_plugin_autostart::ManagerExt; @@ -8,10 +8,10 @@ pub async fn toggle_autostart(app: AppHandle, enabled: bool) -> Result<(), Strin let manager = app.autolaunch(); if enabled { manager.enable().map_err(|e| e.to_string())?; - info!("Enabled autostart"); + debug!("Enabled autostart"); } else { manager.disable().map_err(|e| e.to_string())?; - info!("Disabled autostart"); + debug!("Disabled autostart"); } // Store the state in DB @@ -58,10 +58,10 @@ pub fn sync_autostart_on_startup(app: &AppHandle) -> Result<(), String> { if current_state != should_be_enabled { if should_be_enabled { manager.enable().map_err(|e| e.to_string())?; - info!("Synced autostart: enabled"); + debug!("Synced autostart: enabled"); } else { manager.disable().map_err(|e| e.to_string())?; - info!("Synced autostart: disabled"); + debug!("Synced autostart: disabled"); } } diff --git a/src-tauri/src/cleanup.rs b/src-tauri/src/cleanup.rs index 327d9f1..d8817ae 100644 --- a/src-tauri/src/cleanup.rs +++ b/src-tauri/src/cleanup.rs @@ -1,4 +1,4 @@ -use log::info; +use log::{debug, info}; use tauri::AppHandle; #[tauri::command] @@ -7,7 +7,7 @@ pub fn quit(app: tauri::AppHandle) { } pub fn cleanup_and_exit(app: &AppHandle) { - info!("exiting drop application..."); + debug!("Cleaning up and exiting application"); app.exit(0); } diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index 2481ece..647a377 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -126,9 +126,7 @@ impl DatabaseImpls for DatabaseInterface { debug!("Creating data directory at {:?}", data_root_dir); create_dir_all(data_root_dir.clone()).unwrap(); - debug!("Creating games directory"); create_dir_all(games_base_dir.clone()).unwrap(); - debug!("Creating logs directory"); create_dir_all(logs_root_dir.clone()).unwrap(); let exists = fs::exists(db_path.clone()).unwrap(); diff --git a/src-tauri/src/games/downloads/download_agent.rs b/src-tauri/src/games/downloads/download_agent.rs index 44e6e60..934260a 100644 --- a/src-tauri/src/games/downloads/download_agent.rs +++ b/src-tauri/src/games/downloads/download_agent.rs @@ -15,6 +15,7 @@ use crate::DB; use log::{debug, error, info}; use rayon::ThreadPoolBuilder; use slice_deque::SliceDeque; +use std::collections::HashMap; use std::fs::{create_dir_all, File}; use std::path::Path; use std::sync::mpsc::Sender; @@ -157,7 +158,7 @@ impl GameDownloadAgent { )); } - let manifest_download = response.json::().unwrap(); + let manifest_download: DropManifest = response.json().unwrap(); if let Ok(mut manifest) = self.manifest.lock() { *manifest = Some(manifest_download); diff --git a/src-tauri/src/games/downloads/download_logic.rs b/src-tauri/src/games/downloads/download_logic.rs index 800c275..3c9ca60 100644 --- a/src-tauri/src/games/downloads/download_logic.rs +++ b/src-tauri/src/games/downloads/download_logic.rs @@ -134,9 +134,10 @@ pub fn download_game_chunk( .map_err(|e| ApplicationDownloadError::Communication(e.into()))?; if response.status() != 200 { - warn!("{}", response.text().unwrap()); + let err = response.json().unwrap(); + warn!("{:?}", err); return Err(ApplicationDownloadError::Communication( - RemoteAccessError::InvalidCodeError(400), + RemoteAccessError::InvalidResponse(err), )); } @@ -150,7 +151,7 @@ pub fn download_game_chunk( let content_length = response.content_length(); if content_length.is_none() { - error!("Recieved 0 length content from server"); + warn!("Recieved 0 length content from server"); return Err(ApplicationDownloadError::Communication( RemoteAccessError::InvalidResponse(response.json().unwrap()), )); diff --git a/src-tauri/src/games/downloads/stored_manifest.rs b/src-tauri/src/games/downloads/stored_manifest.rs index b02821c..fdc232b 100644 --- a/src-tauri/src/games/downloads/stored_manifest.rs +++ b/src-tauri/src/games/downloads/stored_manifest.rs @@ -5,7 +5,7 @@ use std::{ sync::Mutex, }; -use log::error; +use log::{error, warn}; use serde::{Deserialize, Serialize}; use serde_binary::binary_stream::Endian; @@ -46,7 +46,7 @@ impl StoredManifest { match serde_binary::from_vec::(s, Endian::Little) { Ok(manifest) => manifest, Err(e) => { - error!("{}", e); + warn!("{}", e); StoredManifest::new(game_id, game_version, base_path) } } diff --git a/src-tauri/src/games/library.rs b/src-tauri/src/games/library.rs index d2340ee..baa8fb9 100644 --- a/src-tauri/src/games/library.rs +++ b/src-tauri/src/games/library.rs @@ -2,7 +2,7 @@ use std::fs::remove_dir_all; use std::sync::Mutex; use std::thread::spawn; -use log::{error, info}; +use log::{error, info, warn}; use serde::{Deserialize, Serialize}; use tauri::Emitter; use tauri::{AppHandle, Manager}; @@ -91,10 +91,12 @@ fn fetch_library_logic(app: AppHandle) -> Result, RemoteAccessError> { .send()?; if response.status() != 200 { - return Err(response.status().as_u16().into()); + let err = response.json().unwrap(); + warn!("{:?}", err); + return Err(RemoteAccessError::InvalidResponse(err)); } - let games: Vec = response.json::>()?; + let games: Vec = response.json()?; let state = app.state::>(); let mut handle = state.lock().unwrap(); @@ -155,12 +157,12 @@ fn fetch_game_logic( return Err(RemoteAccessError::GameNotFound); } if response.status() != 200 { - return Err(RemoteAccessError::InvalidCodeError( - response.status().into(), - )); + let err = response.json().unwrap(); + warn!("{:?}", err); + return Err(RemoteAccessError::InvalidResponse(err)); } - let game = response.json::()?; + let game: Game = response.json()?; state_handle.games.insert(id.clone(), game.clone()); let mut db_handle = DB.borrow_data_mut().unwrap(); @@ -217,19 +219,19 @@ fn fetch_game_verion_options_logic( .send()?; if response.status() != 200 { - return Err(RemoteAccessError::InvalidCodeError( - response.status().into(), - )); + let err = response.json().unwrap(); + warn!("{:?}", err); + return Err(RemoteAccessError::InvalidResponse(err)); } - let data = response.json::>()?; + let data: Vec = response.json()?; let state_lock = state.lock().unwrap(); let process_manager_lock = state_lock.process_manager.lock().unwrap(); - let data = data + let data: Vec = data .into_iter() .filter(|v| process_manager_lock.valid_platform(&v.platform).unwrap()) - .collect::>(); + .collect(); drop(process_manager_lock); drop(state_lock); @@ -363,7 +365,7 @@ pub fn on_game_complete( .header("Authorization", header) .send()?; - let data = response.json::()?; + let data: GameVersion = response.json()?; let mut handle = DB.borrow_data_mut().unwrap(); handle diff --git a/src-tauri/src/process/process_manager.rs b/src-tauri/src/process/process_manager.rs index 51e59fd..ec52c1d 100644 --- a/src-tauri/src/process/process_manager.rs +++ b/src-tauri/src/process/process_manager.rs @@ -69,7 +69,6 @@ impl ProcessManager<'_> { // I think if we just join the install_dir to whatever the user provides us, we'll be alright // In future, we should have a separate field for executable name and it's arguments fn process_command(&self, install_dir: &String, raw_command: String) -> (PathBuf, Vec) { - // let command_components = raw_command.split(" ").collect::>(); let root = raw_command; let install_dir = Path::new(install_dir); diff --git a/src-tauri/src/remote.rs b/src-tauri/src/remote.rs index 5a4d12e..1048df1 100644 --- a/src-tauri/src/remote.rs +++ b/src-tauri/src/remote.rs @@ -15,7 +15,6 @@ use crate::{AppState, AppStatus, DB}; pub enum RemoteAccessError { FetchError(Arc), ParsingError(ParseError), - InvalidCodeError(u16), InvalidEndpoint, HandshakeFailed(String), GameNotFound, @@ -42,7 +41,6 @@ impl Display for RemoteAccessError { RemoteAccessError::ParsingError(parse_error) => { write!(f, "{}", parse_error) } - RemoteAccessError::InvalidCodeError(error) => write!(f, "Invalid HTTP code {}", error), RemoteAccessError::InvalidEndpoint => write!(f, "Invalid drop endpoint"), RemoteAccessError::HandshakeFailed(message) => write!(f, "Failed to complete handshake: {}", message), RemoteAccessError::GameNotFound => write!(f, "Could not find game on server"), @@ -69,11 +67,6 @@ impl From for RemoteAccessError { RemoteAccessError::ParsingError(err) } } -impl From for RemoteAccessError { - fn from(err: u16) -> Self { - RemoteAccessError::InvalidCodeError(err) - } -} impl std::error::Error for RemoteAccessError {} @@ -92,7 +85,7 @@ struct DropHealthcheck { app_name: String, } -async fn use_remote_logic<'a>( +fn use_remote_logic<'a>( url: String, state: tauri::State<'_, Mutex>>, ) -> Result<(), RemoteAccessError> { @@ -101,9 +94,9 @@ async fn use_remote_logic<'a>( // Test Drop url let test_endpoint = base_url.join("/api/v1")?; - let response = reqwest::get(test_endpoint.to_string()).await?; + let response = reqwest::blocking::get(test_endpoint.to_string())?; - let result = response.json::().await?; + let result: DropHealthcheck = response.json()?; if result.app_name != "Drop" { warn!("user entered drop endpoint that connected, but wasn't identified as Drop"); @@ -124,11 +117,11 @@ async fn use_remote_logic<'a>( } #[tauri::command] -pub async fn use_remote<'a>( +pub fn use_remote<'a>( url: String, state: tauri::State<'_, Mutex>>, ) -> Result<(), String> { - let result = use_remote_logic(url, state).await; + let result = use_remote_logic(url, state); if result.is_err() { return Err(result.err().unwrap().to_string());