mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-13 16:22:43 +10:00
chore: General cleanup
- Changed some info!() statements to debug!() and warn!() - Removed most Turbofish syntax cases - Removed InvalidCodeError and replaced it with InvalidResponse Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -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<User, RemoteAccessError> {
|
||||
.send()?;
|
||||
|
||||
if response.status() != 200 {
|
||||
let data = response.json::<DropServerError>()?;
|
||||
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::<User>()?;
|
||||
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::<HandshakeResponse>()?;
|
||||
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::<DropServerError>()?;
|
||||
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<User>), ()> {
|
||||
|
||||
#[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();
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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::<DropManifest>().unwrap();
|
||||
let manifest_download: DropManifest = response.json().unwrap();
|
||||
|
||||
if let Ok(mut manifest) = self.manifest.lock() {
|
||||
*manifest = Some(manifest_download);
|
||||
|
||||
@ -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()),
|
||||
));
|
||||
|
||||
@ -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::<StoredManifest>(s, Endian::Little) {
|
||||
Ok(manifest) => manifest,
|
||||
Err(e) => {
|
||||
error!("{}", e);
|
||||
warn!("{}", e);
|
||||
StoredManifest::new(game_id, game_version, base_path)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<Vec<Game>, 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<Game> = response.json::<Vec<Game>>()?;
|
||||
let games: Vec<Game> = response.json()?;
|
||||
|
||||
let state = app.state::<Mutex<AppState>>();
|
||||
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::<Game>()?;
|
||||
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::<Vec<GameVersionOption>>()?;
|
||||
let data: Vec<GameVersionOption> = response.json()?;
|
||||
|
||||
let state_lock = state.lock().unwrap();
|
||||
let process_manager_lock = state_lock.process_manager.lock().unwrap();
|
||||
let data = data
|
||||
let data: Vec<GameVersionOption> = data
|
||||
.into_iter()
|
||||
.filter(|v| process_manager_lock.valid_platform(&v.platform).unwrap())
|
||||
.collect::<Vec<GameVersionOption>>();
|
||||
.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::<GameVersion>()?;
|
||||
let data: GameVersion = response.json()?;
|
||||
|
||||
let mut handle = DB.borrow_data_mut().unwrap();
|
||||
handle
|
||||
|
||||
@ -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<String>) {
|
||||
// let command_components = raw_command.split(" ").collect::<Vec<&str>>();
|
||||
let root = raw_command;
|
||||
|
||||
let install_dir = Path::new(install_dir);
|
||||
|
||||
@ -15,7 +15,6 @@ use crate::{AppState, AppStatus, DB};
|
||||
pub enum RemoteAccessError {
|
||||
FetchError(Arc<reqwest::Error>),
|
||||
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<ParseError> for RemoteAccessError {
|
||||
RemoteAccessError::ParsingError(err)
|
||||
}
|
||||
}
|
||||
impl From<u16> 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<AppState<'a>>>,
|
||||
) -> 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::<DropHealthcheck>().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<AppState<'a>>>,
|
||||
) -> 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());
|
||||
|
||||
Reference in New Issue
Block a user