[feat] basic open path but having issue of path with spaces

This commit is contained in:
Purp1e
2025-03-21 16:02:47 +08:00
parent 90a05017ce
commit 2e18fbdffd
5 changed files with 52 additions and 9 deletions

View File

@@ -43,6 +43,11 @@ pub fn get_cs_path(name: &str) -> Result<String, String> {
wrap_err!(steam::path::get_cs_path(name))
}
#[tauri::command]
pub fn open_path(path: &str) -> Result<(), String> {
wrap_err!(common::open_path(path))
}
#[tauri::command]
pub fn get_powerplan() -> Result<String, String> {
#[cfg(target_os = "windows")]

View File

@@ -93,6 +93,7 @@ fn main() {
cmds::kill_steam,
cmds::get_steam_path,
cmds::get_cs_path,
cmds::open_path,
cmds::get_powerplan,
cmds::set_powerplan,
cmds::set_auto_login_user,

View File

@@ -15,6 +15,7 @@ pub fn run_steam() -> std::io::Result<std::process::Output> {
.output()
}
// FIXME wmic is deprecated
pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
let command = format!("/C wmic process where name='{}' get ExecutablePath", name);
let args = command.split_whitespace().collect::<Vec<&str>>();
@@ -33,3 +34,12 @@ pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
"Failed to get executable path",
))
}
pub fn open_path(path: &str) -> Result<(), std::io::Error> {
let p = format!("file:///{}", path);
Command::new("explorer")
.args([p])
.spawn()
.expect("Failed to open path");
Ok(())
}