chore: Remove unwraps from process_handlers

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-09-10 09:24:27 +10:00
parent 83dc773b10
commit 463c5e6f3b
4 changed files with 23 additions and 17 deletions

View File

@ -11,7 +11,8 @@ pub enum ProcessError {
IOError(Error),
FormatError(String), // String errors supremacy
InvalidPlatform,
OpenerError(tauri_plugin_opener::Error)
OpenerError(tauri_plugin_opener::Error),
InvalidArguments(String)
}
impl Display for ProcessError {
@ -23,8 +24,9 @@ impl Display for ProcessError {
ProcessError::InvalidVersion => "Invalid game version",
ProcessError::IOError(error) => &error.to_string(),
ProcessError::InvalidPlatform => "This game cannot be played on the current platform",
ProcessError::FormatError(e) => &format!("Failed to format template: {e}"),
ProcessError::OpenerError(error) => &format!("Failed to open directory: {error}"),
ProcessError::FormatError(e) => &format!("Could not format template: {e}"),
ProcessError::OpenerError(error) => &format!("Could not open directory: {error}"),
ProcessError::InvalidArguments(arguments) => &format!("Invalid arguments in command {arguments}"),
};
write!(f, "{s}")
}

View File

@ -10,6 +10,7 @@ use log::{debug, info};
use crate::{
AppState,
database::models::data::{Database, DownloadableMetadata, GameVersion},
error::process_error::ProcessError,
process::process_manager::{Platform, ProcessHandler},
};
@ -22,8 +23,8 @@ impl ProcessHandler for NativeGameLauncher {
args: Vec<String>,
_game_version: &GameVersion,
_current_dir: &str,
) -> String {
format!("\"{}\" {}", launch_command, args.join(" "))
) -> Result<String, ProcessError> {
Ok(format!("\"{}\" {}", launch_command, args.join(" ")))
}
fn valid_for_platform(&self, _db: &Database, _state: &AppState, _target: &Platform) -> bool {
@ -65,7 +66,7 @@ impl ProcessHandler for UMULauncher {
args: Vec<String>,
game_version: &GameVersion,
_current_dir: &str,
) -> String {
) -> Result<String, ProcessError> {
debug!("Game override: \"{:?}\"", &game_version.umu_id_override);
let game_id = match &game_version.umu_id_override {
Some(game_override) => {
@ -77,12 +78,12 @@ impl ProcessHandler for UMULauncher {
}
None => game_version.game_id.clone(),
};
format!(
Ok(format!(
"GAMEID={game_id} {umu:?} \"{launch}\" {args}",
umu = UMU_LAUNCHER_EXECUTABLE.as_ref().unwrap(),
umu = UMU_LAUNCHER_EXECUTABLE.as_ref().expect("Failed to get UMU_LAUNCHER_EXECUTABLE as ref"),
launch = launch_command,
args = args.join(" ")
)
))
}
fn valid_for_platform(&self, _db: &Database, state: &AppState, _target: &Platform) -> bool {
@ -102,7 +103,7 @@ impl ProcessHandler for AsahiMuvmLauncher {
args: Vec<String>,
game_version: &GameVersion,
current_dir: &str,
) -> String {
) -> Result<String, ProcessError> {
let umu_launcher = UMULauncher {};
let umu_string = umu_launcher.create_launch_process(
meta,
@ -110,15 +111,18 @@ impl ProcessHandler for AsahiMuvmLauncher {
args,
game_version,
current_dir,
);
)?;
let mut args_cmd = umu_string
.split("umu-run")
.collect::<Vec<&str>>()
.into_iter();
let args = args_cmd.next().unwrap().trim();
let cmd = format!("umu-run{}", args_cmd.next().unwrap());
let args = args_cmd
.next()
.ok_or(ProcessError::InvalidArguments(umu_string.clone()))?
.trim();
let cmd = format!("umu-run{}", args_cmd.next().ok_or(ProcessError::InvalidArguments(umu_string.clone()))?);
format!("{args} muvm -- {cmd}")
Ok(format!("{args} muvm -- {cmd}"))
}
#[allow(unreachable_code)]

View File

@ -331,7 +331,7 @@ impl ProcessManager<'_> {
args.clone(),
game_version,
install_dir,
);
)?;
let format_args = DropFormatArgs::new(
launch_string,
@ -468,7 +468,7 @@ pub trait ProcessHandler: Send + 'static {
args: Vec<String>,
game_version: &GameVersion,
current_dir: &str,
) -> String;
) -> Result<String, ProcessError>;
fn valid_for_platform(&self, db: &Database, state: &AppState, target: &Platform) -> bool;
}

View File

@ -134,7 +134,7 @@ async fn recieve_handshake_logic(app: &AppHandle, path: String) -> Result<(), Re
private: response_struct.private,
cert: response_struct.certificate,
client_id: response_struct.id,
web_token: Some(web_token), // gets created later
web_token: Some(web_token),
});
Ok(())