[feat] reset modal + basic auto get path + basic wrap err try

This commit is contained in:
Purp1e
2025-03-20 14:13:03 +08:00
parent 60782669ea
commit a9a48d2aba
12 changed files with 163 additions and 62 deletions

View File

@@ -1,39 +1,63 @@
use crate::steam;
use crate::tool::*;
use crate::wrap_err;
use anyhow::Result;
// pub type Result<T, String = ()> = Result<T, String>;
#[tauri::command]
pub fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
pub fn greet(name: &str) -> Result<String, String> {
Ok(format!("Hello, {}! You've been greeted from Rust!", name))
}
// 工具
#[tauri::command]
pub fn launch_game(steam_path: &str, launch_option: &str, server: &str) -> String {
steam::launch_game(steam_path, launch_option, server).expect("启动失败");
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));
format!(
Ok(format!(
"Launching game on server: {}, with launch Option {}",
server, launch_option
)
))
}
#[tauri::command]
pub fn kill_game() -> String {
common::kill("cs2.exe")
pub fn kill_game() -> Result<String, String> {
Ok(common::kill("cs2.exe"))
}
#[tauri::command]
pub fn kill_steam() -> String {
common::kill("steam.exe")
pub fn kill_steam() -> Result<String, String> {
Ok(common::kill("steam.exe"))
}
// Steam
#[tauri::command]
pub fn get_steam_path() -> String {
steam::path::get_steam_path().expect("获取Steam路径失败")
pub fn get_steam_path() -> Result<String, String> {
wrap_err!(steam::path::get_steam_path())
}
#[tauri::command]
pub fn get_cs_path(name: &str) -> Result<String, String> {
wrap_err!(steam::path::get_cs_path(name))
}
#[tauri::command]
pub fn get_powerplan() -> Result<String, String> {
#[cfg(target_os = "windows")]
let powerplan = powerplan::get_powerplan()?;
Ok(powerplan)
}
#[tauri::command]
pub fn set_powerplan(plan: &str) -> Result<String, String> {
#[cfg(target_os = "windows")]
powerplan::set_powerplan(plan)?;
Ok(format!("Set powerplan to {}", plan))
}
// TODO get_cs_path
// TODO get_powerplan
// TODO set_powerplan
@@ -44,14 +68,14 @@ pub fn get_steam_path() -> String {
// TODO fs_watch_dir
#[tauri::command]
pub fn set_auto_login_user(user: &str) -> String {
pub fn set_auto_login_user(user: &str) -> Result<String, String> {
#[cfg(target_os = "windows")]
steam::reg::set_auto_login_user(user).expect("设置自动登录用户失败");
steam::reg::set_auto_login_user(user)?;
format!("Set auto login user to {}", user)
Ok(format!("Set auto login user to {}", user))
}
#[tauri::command]
pub fn check_path(path: &str) -> bool {
std::path::Path::new(&path).exists()
pub fn check_path(path: &str) -> Result<bool, String> {
Ok(std::path::Path::new(&path).exists())
}