Files
cstb-next/src-tauri/src/cmds.rs

85 lines
2.0 KiB
Rust
Raw Normal View History

2024-09-20 09:52:13 +08:00
use crate::steam;
use crate::tool::*;
use crate::vdf::preset;
use crate::wrap_err;
use anyhow::Result;
// pub type Result<T, String = ()> = Result<T, String>;
2024-09-20 09:52:13 +08:00
#[tauri::command]
pub fn greet(name: &str) -> Result<String, String> {
Ok(format!("Hello, {}! You've been greeted from Rust!", name))
2024-09-20 09:52:13 +08:00
}
// 工具
#[tauri::command]
pub fn launch_game(steam_path: &str, launch_option: &str, server: &str) -> Result<String, String> {
wrap_err!(steam::launch_game(steam_path, launch_option, server));
2024-09-20 09:52:13 +08:00
Ok(format!(
2024-09-20 09:52:13 +08:00
"Launching game on server: {}, with launch Option {}",
server, launch_option
))
2024-09-20 09:52:13 +08:00
}
#[tauri::command]
pub fn kill_game() -> Result<String, String> {
Ok(common::kill("cs2.exe"))
2024-09-20 09:52:13 +08:00
}
#[tauri::command]
pub fn kill_steam() -> Result<String, String> {
Ok(common::kill("steam.exe"))
2024-09-20 09:52:13 +08:00
}
// Steam
#[tauri::command]
pub fn get_steam_path() -> Result<String, String> {
wrap_err!(steam::path::get_steam_path())
}
#[tauri::command]
pub fn get_cs_path(name: &str, steam_dir: &str) -> Result<String, String> {
wrap_err!(steam::path::get_cs_path(name, steam_dir))
2024-09-20 09:52:13 +08:00
}
#[tauri::command]
pub fn open_path(path: &str) -> Result<(), String> {
wrap_err!(common::open_path(path))
}
#[tauri::command]
pub fn get_powerplan() -> Result<i32, String> {
#[cfg(target_os = "windows")]
let powerplan = powerplan::get_powerplan()?;
Ok(powerplan)
}
#[tauri::command]
pub fn set_powerplan(plan: i32) -> Result<(), String> {
#[cfg(target_os = "windows")]
powerplan::set_powerplan(plan)?;
Ok(())
}
#[tauri::command]
pub fn get_steam_users(steam_dir: &str) -> Result<Vec<preset::User>, String> {
wrap_err!(preset::get_users(steam_dir))
}
2024-09-20 09:52:13 +08:00
#[tauri::command]
pub fn set_auto_login_user(user: &str) -> Result<String, String> {
2024-09-20 09:52:13 +08:00
#[cfg(target_os = "windows")]
steam::reg::set_auto_login_user(user)?;
2024-09-20 09:52:13 +08:00
Ok(format!("Set auto login user to {}", user))
2024-09-20 09:52:13 +08:00
}
#[tauri::command]
pub fn check_path(path: &str) -> Result<bool, String> {
Ok(std::path::Path::new(&path).exists())
2024-09-20 09:52:13 +08:00
}