Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions src-tauri/process/src/process_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::create_dir_all, path::PathBuf};
use std::{fs::create_dir_all, path::PathBuf, process::Command};

use client::compat::{COMPAT_INFO, UMU_LAUNCHER_EXECUTABLE};
use database::{
Expand All @@ -7,8 +7,8 @@ use database::{

use crate::{error::ProcessError, process_manager::ProcessHandler};

pub struct NativeGameLauncher;
impl ProcessHandler for NativeGameLauncher {
pub struct MacLauncher;
impl ProcessHandler for MacLauncher {
fn create_launch_process(
&self,
_meta: &DownloadableMetadata,
Expand All @@ -23,6 +23,37 @@ impl ProcessHandler for NativeGameLauncher {
fn valid_for_platform(&self, _db: &Database, _target: &Platform) -> bool {
true
}

fn modify_command(&self, _command: &mut Command) {}
}

#[allow(dead_code)]
const CREATE_NO_WINDOW: u32 = 0x08000000;

pub struct WindowsLauncher;
impl ProcessHandler for WindowsLauncher {
fn create_launch_process(
&self,
_meta: &DownloadableMetadata,
launch_command: String,
_game_version: &GameVersion,
_current_dir: &str,
_database: &Database,
) -> Result<String, ProcessError> {
Ok(format!("cmd /C \"{}\"", launch_command))
}

fn valid_for_platform(&self, _db: &Database, _target: &Platform) -> bool {
true
}

#[allow(unused_variables)]
fn modify_command(&self, command: &mut Command) {
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
#[cfg(target_os = "windows")]
command.creation_flags(CREATE_NO_WINDOW);
}
}

pub struct UMUNativeLauncher;
Expand Down Expand Up @@ -68,6 +99,8 @@ impl ProcessHandler for UMUNativeLauncher {
};
compat_info.umu_installed
}

fn modify_command(&self, _command: &mut Command) {}
}

pub struct UMUCompatLauncher;
Expand Down Expand Up @@ -133,6 +166,8 @@ impl ProcessHandler for UMUCompatLauncher {
};
compat_info.umu_installed
}

fn modify_command(&self, _command: &mut Command) {}
}

pub struct AsahiMuvmLauncher;
Expand Down Expand Up @@ -191,4 +226,6 @@ impl ProcessHandler for AsahiMuvmLauncher {

compat_info.umu_installed
}

fn modify_command(&self, _command: &mut Command) {}
}
15 changes: 8 additions & 7 deletions src-tauri/process/src/process_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
format::DropFormatArgs,
parser::{LaunchParameters, ParsedCommand},
process_handlers::{
AsahiMuvmLauncher, NativeGameLauncher, UMUCompatLauncher, UMUNativeLauncher,
AsahiMuvmLauncher, MacLauncher, UMUCompatLauncher, UMUNativeLauncher, WindowsLauncher,
},
};

Expand Down Expand Up @@ -74,15 +74,15 @@ impl ProcessManager<'_> {
// Current platform to target platform
(
(Platform::Windows, Platform::Windows),
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
&WindowsLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
),
(
(Platform::Linux, Platform::Linux),
&UMUNativeLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
),
(
(Platform::macOS, Platform::macOS),
&NativeGameLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
&MacLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
),
(
(Platform::Linux, Platform::Windows),
Expand Down Expand Up @@ -149,10 +149,7 @@ impl ProcessManager<'_> {
db_handle.applications.transient_statuses.remove(&meta);

let current_state = db_handle.applications.game_statuses.get_mut(&game_id);
if let Some(GameDownloadStatus::Installed {
install_type,
..
}) = current_state
if let Some(GameDownloadStatus::Installed { install_type, .. }) = current_state
&& let Ok(exit_code) = result
&& exit_code.success()
{
Expand Down Expand Up @@ -479,6 +476,8 @@ impl ProcessManager<'_> {
.env_remove("RUST_LOG")
.current_dir(launch_parameters.1);

process_handler.modify_command(&mut command);

let child = command.spawn()?;

let launch_process_handle = Arc::new(SharedChild::new(child)?);
Expand Down Expand Up @@ -528,4 +527,6 @@ pub trait ProcessHandler: Send + 'static {
) -> Result<String, ProcessError>;

fn valid_for_platform(&self, db: &Database, target: &Platform) -> bool;

fn modify_command(&self, command: &mut Command);
}
Loading