mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 08:41:21 +10:00
feat(process manager): Game kill tauri command
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@ -32,7 +32,7 @@ use log4rs::config::{Appender, Root};
|
||||
use log4rs::encode::pattern::PatternEncoder;
|
||||
use log4rs::Config;
|
||||
use process::compat::CompatibilityManager;
|
||||
use process::process_commands::launch_game;
|
||||
use process::process_commands::{kill_game, launch_game};
|
||||
use process::process_manager::ProcessManager;
|
||||
use remote::{gen_drop_url, use_remote};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -234,6 +234,7 @@ pub fn run() {
|
||||
uninstall_game,
|
||||
// Processes
|
||||
launch_game,
|
||||
kill_game
|
||||
])
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
|
||||
@ -17,3 +17,13 @@ pub fn launch_game(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn kill_game(
|
||||
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();
|
||||
process_manager_lock.terminate_child(game_id).map_err(|x| x.to_string())
|
||||
}
|
||||
@ -1,10 +1,5 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::{File, OpenOptions},
|
||||
path::{Path, PathBuf},
|
||||
process::{Child, Command, ExitStatus},
|
||||
sync::{Arc, Mutex},
|
||||
thread::spawn,
|
||||
collections::HashMap, fs::{File, OpenOptions}, io, path::{Path, PathBuf}, process::{Child, Command, ExitStatus}, sync::{Arc, Mutex}, thread::spawn
|
||||
};
|
||||
|
||||
use log::{info, warn};
|
||||
@ -80,6 +75,15 @@ impl ProcessManager<'_> {
|
||||
*/
|
||||
(absolute_exe, Vec::new())
|
||||
}
|
||||
pub fn terminate_child(&mut self, game_id: String) -> Result<(), io::Error> {
|
||||
return match self.processes.get(&game_id) {
|
||||
Some(child) => {
|
||||
let mut lock = child.lock().unwrap();
|
||||
lock.kill()
|
||||
},
|
||||
None => Err(io::Error::new(io::ErrorKind::NotFound, "Game ID not running")),
|
||||
}
|
||||
}
|
||||
|
||||
fn on_process_finish(&mut self, game_id: String, result: Result<ExitStatus, std::io::Error>) {
|
||||
if !self.processes.contains_key(&game_id) {
|
||||
|
||||
Reference in New Issue
Block a user