9185089c99
* 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
68 lines
1.8 KiB
Rust
68 lines
1.8 KiB
Rust
use std::sync::Arc;
|
|
|
|
use process::{
|
|
PROCESS_MANAGER,
|
|
error::ProcessError,
|
|
process_manager::{LaunchOption, ProcessHandlerOption, ProcessManager},
|
|
};
|
|
use serde::Serialize;
|
|
use tauri::AppHandle;
|
|
use tauri_plugin_opener::OpenerExt;
|
|
|
|
#[tauri::command]
|
|
pub fn get_launch_options(id: String) -> Result<Vec<LaunchOption>, ProcessError> {
|
|
let launch_options = ProcessManager::get_launch_options(id)?;
|
|
|
|
Ok(launch_options)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn get_process_handlers(id: String) -> Result<Vec<ProcessHandlerOption>, ProcessError> {
|
|
PROCESS_MANAGER.lock().get_process_handlers(id)
|
|
}
|
|
|
|
#[derive(Serialize)]
|
|
#[serde(tag = "result", content = "data")]
|
|
pub enum LaunchResult {
|
|
Success,
|
|
InstallRequired(String, String),
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn launch_game(id: String, index: usize) -> Result<LaunchResult, ProcessError> {
|
|
let result = {
|
|
let mut process_manager_lock = PROCESS_MANAGER.lock();
|
|
|
|
process_manager_lock.launch_process(id, index)
|
|
};
|
|
|
|
if let Err(err) = &result
|
|
&& let ProcessError::RequiredDependency(game_id, version_id) = err
|
|
{
|
|
return Ok(LaunchResult::InstallRequired(
|
|
game_id.to_string(),
|
|
version_id.to_string(),
|
|
));
|
|
}
|
|
|
|
result?;
|
|
|
|
Ok(LaunchResult::Success)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn kill_game(game_id: String) -> Result<(), ProcessError> {
|
|
Ok(PROCESS_MANAGER.lock().kill_game(game_id)?)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub fn open_process_logs(game_id: String, app_handle: AppHandle) -> Result<(), ProcessError> {
|
|
let process_manager_lock = PROCESS_MANAGER.lock();
|
|
|
|
let dir = process_manager_lock.get_log_dir(game_id);
|
|
app_handle
|
|
.opener()
|
|
.open_path(dir.display().to_string(), None::<&str>)
|
|
.map_err(|v| ProcessError::OpenerError(Arc::new(v)))
|
|
}
|