mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-17 00:29:12 +10:00
Fix v0.4.0 process handler, add override menu (#430)
* Fix Windows and Linux launch * Add process handler selector, pin Prisma * Regenerate lcofkiel * Fix torrential inclusion in image * Fix layouting * Implement tree kill for Windows * Fix server lint
This commit is contained in:
@@ -28,7 +28,8 @@ use crate::{
|
||||
format::DropFormatArgs,
|
||||
parser::{LaunchParameters, ParsedCommand},
|
||||
process_handlers::{
|
||||
AsahiMuvmLauncher, MacLauncher, UMUCompatLauncher, UMUNativeLauncher, WindowsLauncher,
|
||||
AsahiMuvmLauncher, LinuxNativeLauncher, MacLauncher, UMUCompatLauncher, UMUNativeLauncher,
|
||||
WindowsCmdLauncher, WindowsDirectLauncher, WindowsLauncher, WindowsPowershellLauncher,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -54,6 +55,13 @@ pub struct LaunchOption {
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ProcessHandlerOption {
|
||||
id: String,
|
||||
name: String,
|
||||
description: String,
|
||||
}
|
||||
|
||||
impl ProcessManager<'_> {
|
||||
pub fn new(app_handle: AppHandle) -> Self {
|
||||
let log_output_dir = DATA_ROOT_DIR.join("logs");
|
||||
@@ -76,6 +84,22 @@ impl ProcessManager<'_> {
|
||||
(Platform::Windows, Platform::Windows),
|
||||
&WindowsLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||
),
|
||||
(
|
||||
(Platform::Windows, Platform::Windows),
|
||||
&WindowsDirectLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||
),
|
||||
(
|
||||
(Platform::Windows, Platform::Windows),
|
||||
&WindowsCmdLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||
),
|
||||
(
|
||||
(Platform::Windows, Platform::Windows),
|
||||
&WindowsPowershellLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||
),
|
||||
(
|
||||
(Platform::Linux, Platform::Linux),
|
||||
&LinuxNativeLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||
),
|
||||
(
|
||||
(Platform::Linux, Platform::Linux),
|
||||
&UMUNativeLauncher {} as &(dyn ProcessHandler + Sync + Send + 'static),
|
||||
@@ -101,7 +125,7 @@ impl ProcessManager<'_> {
|
||||
match self.processes.get_mut(&game_id) {
|
||||
Some(process) => {
|
||||
process.manually_killed = true;
|
||||
process.handle.kill()?;
|
||||
kill_process_tree(&process.handle)?;
|
||||
let exit_status = process.handle.wait()?;
|
||||
info!("exit status: {:?}", exit_status);
|
||||
Ok(())
|
||||
@@ -188,7 +212,21 @@ impl ProcessManager<'_> {
|
||||
&self,
|
||||
db_lock: &Database,
|
||||
target_platform: &Platform,
|
||||
override_id: Option<&str>,
|
||||
) -> Result<&(dyn ProcessHandler + Send + Sync), ProcessError> {
|
||||
// An explicit override wins, as long as it's valid for the current platform.
|
||||
if let Some(override_id) = override_id
|
||||
&& let Some(handler) = self.game_launchers.iter().find(|e| {
|
||||
let (e_current, e_target) = e.0;
|
||||
e_current == self.current_platform
|
||||
&& e_target == *target_platform
|
||||
&& e.1.id() == override_id
|
||||
&& e.1.valid_for_platform(db_lock, target_platform)
|
||||
})
|
||||
{
|
||||
return Ok(handler.1);
|
||||
}
|
||||
|
||||
Ok(self
|
||||
.game_launchers
|
||||
.iter()
|
||||
@@ -204,10 +242,44 @@ impl ProcessManager<'_> {
|
||||
|
||||
pub fn valid_platform(&self, platform: &Platform) -> bool {
|
||||
let db_lock = borrow_db_checked();
|
||||
let process_handler = self.fetch_process_handler(&db_lock, platform);
|
||||
let process_handler = self.fetch_process_handler(&db_lock, platform, None);
|
||||
process_handler.is_ok()
|
||||
}
|
||||
|
||||
pub fn get_process_handlers(
|
||||
&self,
|
||||
game_id: String,
|
||||
) -> Result<Vec<ProcessHandlerOption>, ProcessError> {
|
||||
let db_lock = borrow_db_checked();
|
||||
|
||||
let meta = db_lock
|
||||
.applications
|
||||
.installed_game_version
|
||||
.get(&game_id)
|
||||
.cloned()
|
||||
.ok_or(ProcessError::NotInstalled)?;
|
||||
|
||||
let target_platform = meta.target_platform;
|
||||
|
||||
let handlers = self
|
||||
.game_launchers
|
||||
.iter()
|
||||
.filter(|e| {
|
||||
let (e_current, e_target) = e.0;
|
||||
e_current == self.current_platform
|
||||
&& e_target == target_platform
|
||||
&& e.1.valid_for_platform(&db_lock, &target_platform)
|
||||
})
|
||||
.map(|e| ProcessHandlerOption {
|
||||
id: e.1.id().to_string(),
|
||||
name: e.1.name().to_string(),
|
||||
description: e.1.description().to_string(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(handlers)
|
||||
}
|
||||
|
||||
pub fn get_launch_options(game_id: String) -> Result<Vec<LaunchOption>, ProcessError> {
|
||||
let db_lock = borrow_db_checked();
|
||||
|
||||
@@ -310,7 +382,12 @@ impl ProcessManager<'_> {
|
||||
|
||||
let target_platform = meta.target_platform;
|
||||
|
||||
let process_handler = self.fetch_process_handler(&db_lock, &target_platform)?;
|
||||
let process_handler = self.fetch_process_handler(
|
||||
&db_lock,
|
||||
&target_platform,
|
||||
game_version.user_configuration.override_handler.as_deref(),
|
||||
)?;
|
||||
debug!("using process handler {:?}", process_handler.id());
|
||||
|
||||
let (target_command, emulator) = match game_status {
|
||||
GameDownloadStatus::Installed {
|
||||
@@ -516,6 +593,30 @@ impl ProcessManager<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn kill_process_tree(handle: &SharedChild) -> io::Result<()> {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
// handle.kill() only terminates the launched process (often a cmd or
|
||||
// powershell wrapper), orphaning the actual game. taskkill /T kills the
|
||||
// whole process tree.
|
||||
use std::os::windows::process::CommandExt;
|
||||
const CREATE_NO_WINDOW: u32 = 0x08000000;
|
||||
let pid = handle.id().to_string();
|
||||
let killed = Command::new("taskkill")
|
||||
.args(["/F", "/T", "/PID", pid.as_str()])
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.status()
|
||||
.map(|status| status.success())
|
||||
.unwrap_or(false);
|
||||
if killed {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
handle.kill()
|
||||
}
|
||||
|
||||
pub trait ProcessHandler: Send + 'static {
|
||||
fn create_launch_process(
|
||||
&self,
|
||||
@@ -529,4 +630,8 @@ pub trait ProcessHandler: Send + 'static {
|
||||
fn valid_for_platform(&self, db: &Database, target: &Platform) -> bool;
|
||||
|
||||
fn modify_command(&self, command: &mut Command);
|
||||
|
||||
fn id(&self) -> &'static str;
|
||||
fn name(&self) -> &'static str;
|
||||
fn description(&self) -> &'static str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user