From 6257a2e68cec10f27b9a519f2cc483eaecc995c6 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Tue, 26 Jul 2022 20:37:39 -0700 Subject: [PATCH] non-blocking commands for reshade --- src-tauri/src/system_helpers.rs | 18 +++++++++++++----- src/ui/components/menu/ExtrasMenu.tsx | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index 58b3080..55ff962 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -1,13 +1,13 @@ use duct::cmd; #[tauri::command] -pub fn run_program(path: String) { +pub fn run_program(path: String, args: Option) { // Without unwrap_or, this can crash when UAC prompt is denied - open::that(&path).unwrap_or(()); + open::that(format!("{} {}", &path, &args.unwrap_or("".into()))).unwrap_or(()); } #[tauri::command] -pub fn run_program_relative(path: String) { +pub fn run_program_relative(path: String, args: Option) { // Save the current working directory let cwd = std::env::current_dir().unwrap(); @@ -18,8 +18,10 @@ pub fn run_program_relative(path: String) { // Set new working directory std::env::set_current_dir(&path_buf).unwrap(); + println!("Opening {} {}", &path, args.clone().unwrap_or("".into())); + // Without unwrap_or, this can crash when UAC prompt is denied - open::that(&path).unwrap_or(()); + open::that(format!("{} {}", &path, args.unwrap_or("".into()))).unwrap_or(()); // Restore the original working directory std::env::set_current_dir(&cwd).unwrap(); @@ -27,7 +29,13 @@ pub fn run_program_relative(path: String) { #[tauri::command] pub fn run_command(program: &str, args: Vec<&str>) { - cmd(program, args).run().expect("Failed to run command"); + let prog = program.to_string(); + let args = args.iter().map(|s| s.to_string()).collect::>(); + + // Commands should not block (this is for the reshade injector mostly) + std::thread::spawn(move || { + cmd(prog, args).run().unwrap(); + }); } #[tauri::command] diff --git a/src/ui/components/menu/ExtrasMenu.tsx b/src/ui/components/menu/ExtrasMenu.tsx index 122e9a4..24eefbc 100644 --- a/src/ui/components/menu/ExtrasMenu.tsx +++ b/src/ui/components/menu/ExtrasMenu.tsx @@ -7,6 +7,7 @@ import './ExtrasMenu.css' import BigButton from '../common/BigButton' import { invoke } from '@tauri-apps/api' import Tr from '../../../utils/language' +import { getGameExecutable } from '../../../utils/game' interface IProps { children: React.ReactNode | React.ReactNode[] @@ -108,7 +109,10 @@ export class ExtrasMenu extends React.Component { if (!config.reshade_path) return alert('Reshade not installed or set!') - await invoke('run_program_relative', { path: config.reshade_path }) + await invoke('run_command', { + program: config.reshade_path, + args: [await getGameExecutable()], + }) } toggleMigoto() {