diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 3df0113..343dc59 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -43,6 +43,11 @@ pub fn get_cs_path(name: &str) -> Result { 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 { #[cfg(target_os = "windows")] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b016a65..9697010 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -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, diff --git a/src-tauri/src/tool/common.rs b/src-tauri/src/tool/common.rs index edd418e..ad9c3eb 100644 --- a/src-tauri/src/tool/common.rs +++ b/src-tauri/src/tool/common.rs @@ -15,6 +15,7 @@ pub fn run_steam() -> std::io::Result { .output() } +// FIXME wmic is deprecated pub fn get_exe_path(name: &str) -> Result { let command = format!("/C wmic process where name='{}' get ExecutablePath", name); let args = command.split_whitespace().collect::>(); @@ -33,3 +34,12 @@ pub fn get_exe_path(name: &str) -> Result { "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(()) +} diff --git a/src/app/(main)/gear/page.tsx b/src/app/(main)/gear/page.tsx index 069a29d..b5492dd 100644 --- a/src/app/(main)/gear/page.tsx +++ b/src/app/(main)/gear/page.tsx @@ -9,6 +9,7 @@ import { import { ToolButton } from "@/components/window/ToolButton" import { Chip } from "@heroui/react" import { Refresh, SettingConfig } from "@icon-park/react" +import { version } from "@tauri-apps/plugin-os" import { useEffect, useState } from "react" import { type AllSystemInfo, allSysInfo } from "tauri-plugin-system-info-api" export default function Page() { @@ -42,6 +43,8 @@ function HardwareInfo() { // const [staticData, setStaticData] = useState("") // const [cpuData, setCpuData] = useState("") // const [batteryData, setBatteryData] = useState("") + const osVersion = version() + useEffect(() => { const fetchData = async () => { @@ -62,7 +65,7 @@ function HardwareInfo() { CPU型号: {allSysData?.cpus[0]?.brand} 线程数: {allSysData?.cpu_count} - 系统: {allSysData?.name} {allSysData?.os_version} + 系统: {allSysData?.name} {allSysData?.os_version} {osVersion} 内存: diff --git a/src/components/cstb/CommonDir.tsx b/src/components/cstb/CommonDir.tsx index 0448981..59cae0c 100644 --- a/src/components/cstb/CommonDir.tsx +++ b/src/components/cstb/CommonDir.tsx @@ -1,6 +1,10 @@ import { addToast } from "@heroui/react" import { FolderFocusOne } from "@icon-park/react" import { Card, CardBody, CardHeader, CardIcon } from "../window/Card" +import { invoke } from "@tauri-apps/api/core" +import { configDir } from "@tauri-apps/api/path" +import { useSteamStore } from "@/store/steam" +import path from "path" interface RoundedButtonProps { children?: React.ReactNode @@ -22,6 +26,8 @@ const RoundedButton = ({ } const CommonDir = () => { + const steam = useSteamStore() + return ( @@ -32,50 +38,68 @@ const CommonDir = () => {
{ - // 调用 tauri api open steam.Dir + onClick={async () => { + await invoke("open_path", { + path: steam.state.steamDir, + }) addToast({ title: "Steam安装位置" }) }} > Steam安装位置 { + onClick={async () => { + await invoke("open_path", { + path: path.join(steam.state.cs2Dir, "game", "csgo", "cfg"), + }) addToast({ title: "CS2游戏目录" }) }} > CS2游戏目录 { + onClick={async () => { + await invoke("open_path", { + path: path.join(steam.state.cs2Dir, "game", "csgo", "maps"), + }) addToast({ title: "地图文件" }) }} > 地图文件 { + onClick={async () => { + await invoke("open_path", { + path: path.join(steam.state.cs2Dir, "game", "csgo", "cfg"), + }) addToast({ title: "游戏CFG目录" }) }} > 游戏CFG目录 { + onClick={async () => { + await invoke("open_path", { + path: path.join(steam.state.steamDir, "userdata"), + }) addToast({ title: "个人CFG目录" }) }} > 个人CFG目录 { + onClick={async () => { + const appDataDirPath = await configDir() + await invoke("open_path", { path: `${appDataDirPath}/Wmpvp/demo` }) addToast({ title: "完美平台录像" }) }} > 完美平台录像 { + onClick={async () => { + const appDataDirPath = await configDir() + await invoke("open_path", { path: `${appDataDirPath}/5E对战平台/demo` }) addToast({ title: "5E平台录像" }) }} >