refactor: Ran cargo clippy & fmt

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-01-05 20:29:15 +11:00
parent 8aad64ffa7
commit 82804ebc67
31 changed files with 380 additions and 284 deletions
-2
View File
@@ -46,6 +46,4 @@ impl CompatibilityManager {
Ok(())
}
}
+34 -18
View File
@@ -1,24 +1,41 @@
use std::sync::Mutex;
use crate::{db::GameDownloadStatus, download_manager::downloadable_metadata::{DownloadType, DownloadableMetadata}, games::library::get_current_meta, AppState, DB};
use crate::{
db::GameDownloadStatus,
download_manager::downloadable_metadata::{DownloadType, DownloadableMetadata},
games::library::get_current_meta,
AppState, DB,
};
#[tauri::command]
pub fn launch_game(
id: String,
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), String> {
pub fn launch_game(id: String, state: tauri::State<'_, Mutex<AppState>>) -> Result<(), String> {
let state_lock = state.lock().unwrap();
let mut process_manager_lock = state_lock.process_manager.lock().unwrap();
let version = match DB.borrow_data().unwrap().applications.game_statuses.get(&id).cloned() {
Some(GameDownloadStatus::Installed { version_name, install_dir }) => version_name,
Some(GameDownloadStatus::SetupRequired { version_name, install_dir }) => return Err(String::from("Game setup still required")),
_ => return Err(String::from("Game not installed"))
let version = match DB
.borrow_data()
.unwrap()
.applications
.game_statuses
.get(&id)
.cloned()
{
Some(GameDownloadStatus::Installed {
version_name,
install_dir,
}) => version_name,
Some(GameDownloadStatus::SetupRequired {
version_name,
install_dir,
}) => return Err(String::from("Game setup still required")),
_ => return Err(String::from("Game not installed")),
};
let meta = DownloadableMetadata { id, version: Some(version), download_type: DownloadType::Game };
let meta = DownloadableMetadata {
id,
version: Some(version),
download_type: DownloadType::Game,
};
process_manager_lock.launch_process(meta)?;
@@ -29,12 +46,11 @@ pub fn launch_game(
}
#[tauri::command]
pub fn kill_game(
game_id: String,
state: tauri::State<'_, Mutex<AppState>>,
) -> Result<(), String> {
pub fn kill_game(game_id: String, state: tauri::State<'_, Mutex<AppState>>) -> Result<(), String> {
let meta = get_current_meta(&game_id)?;
let state_lock = state.lock().unwrap();
let mut process_manager_lock = state_lock.process_manager.lock().unwrap();
process_manager_lock.kill_game(meta).map_err(|x| x.to_string())
}
process_manager_lock
.kill_game(meta)
.map_err(|x| x.to_string())
}
+21 -8
View File
@@ -15,7 +15,11 @@ use tauri::{AppHandle, Manager};
use umu_wrapper_lib::command_builder::UmuCommandBuilder;
use crate::{
db::{GameDownloadStatus, ApplicationTransientStatus, DATA_ROOT_DIR}, download_manager::{downloadable::Downloadable, downloadable_metadata::DownloadableMetadata}, games::library::push_game_update, games::state::GameStatusManager, AppState, DB
db::{ApplicationTransientStatus, GameDownloadStatus, DATA_ROOT_DIR},
download_manager::downloadable_metadata::DownloadableMetadata,
games::library::push_game_update,
games::state::GameStatusManager,
AppState, DB,
};
pub struct ProcessManager<'a> {
@@ -85,7 +89,7 @@ impl ProcessManager<'_> {
child.kill()?;
child.wait()?;
Ok(())
},
}
None => Err(io::Error::new(
io::ErrorKind::NotFound,
"Game ID not running",
@@ -93,7 +97,11 @@ impl ProcessManager<'_> {
};
}
fn on_process_finish(&mut self, meta: DownloadableMetadata, result: Result<ExitStatus, std::io::Error>) {
fn on_process_finish(
&mut self,
meta: DownloadableMetadata,
result: Result<ExitStatus, std::io::Error>,
) {
if !self.processes.contains_key(&meta) {
warn!("process on_finish was called, but game_id is no longer valid. finished with result: {:?}", result);
return;
@@ -148,7 +156,10 @@ impl ProcessManager<'_> {
}
let mut db_lock = DB.borrow_data_mut().unwrap();
info!("Launching process {:?} with games {:?}", meta, db_lock.applications.game_versions);
info!(
"Launching process {:?} with games {:?}",
meta, db_lock.applications.game_versions
);
let game_status = db_lock
.applications
@@ -210,10 +221,12 @@ impl ProcessManager<'_> {
.truncate(true)
.read(true)
.create(true)
.open(
self.log_output_dir
.join(format!("{}-{}-{}.log", meta.id.clone(), meta.version.clone().unwrap_or_default(), current_time.timestamp())),
)
.open(self.log_output_dir.join(format!(
"{}-{}-{}.log",
meta.id.clone(),
meta.version.clone().unwrap_or_default(),
current_time.timestamp()
)))
.map_err(|v| v.to_string())?;
let error_file = OpenOptions::new()