feat(process manager): Game kill tauri command

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2024-12-30 13:50:26 +11:00
parent 88b2505e71
commit 01e6162527
3 changed files with 22 additions and 7 deletions

View File

@ -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) {