[feat] basic open path but having issue of path with spaces
This commit is contained in:
@@ -43,6 +43,11 @@ pub fn get_cs_path(name: &str) -> Result<String, String> {
|
|||||||
wrap_err!(steam::path::get_cs_path(name))
|
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]
|
#[tauri::command]
|
||||||
pub fn get_powerplan() -> Result<String, String> {
|
pub fn get_powerplan() -> Result<String, String> {
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ fn main() {
|
|||||||
cmds::kill_steam,
|
cmds::kill_steam,
|
||||||
cmds::get_steam_path,
|
cmds::get_steam_path,
|
||||||
cmds::get_cs_path,
|
cmds::get_cs_path,
|
||||||
|
cmds::open_path,
|
||||||
cmds::get_powerplan,
|
cmds::get_powerplan,
|
||||||
cmds::set_powerplan,
|
cmds::set_powerplan,
|
||||||
cmds::set_auto_login_user,
|
cmds::set_auto_login_user,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub fn run_steam() -> std::io::Result<std::process::Output> {
|
|||||||
.output()
|
.output()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME wmic is deprecated
|
||||||
pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
|
pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
|
||||||
let command = format!("/C wmic process where name='{}' get ExecutablePath", name);
|
let command = format!("/C wmic process where name='{}' get ExecutablePath", name);
|
||||||
let args = command.split_whitespace().collect::<Vec<&str>>();
|
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",
|
"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(())
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
import { ToolButton } from "@/components/window/ToolButton"
|
import { ToolButton } from "@/components/window/ToolButton"
|
||||||
import { Chip } from "@heroui/react"
|
import { Chip } from "@heroui/react"
|
||||||
import { Refresh, SettingConfig } from "@icon-park/react"
|
import { Refresh, SettingConfig } from "@icon-park/react"
|
||||||
|
import { version } from "@tauri-apps/plugin-os"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { type AllSystemInfo, allSysInfo } from "tauri-plugin-system-info-api"
|
import { type AllSystemInfo, allSysInfo } from "tauri-plugin-system-info-api"
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
@@ -42,6 +43,8 @@ function HardwareInfo() {
|
|||||||
// const [staticData, setStaticData] = useState("")
|
// const [staticData, setStaticData] = useState("")
|
||||||
// const [cpuData, setCpuData] = useState("")
|
// const [cpuData, setCpuData] = useState("")
|
||||||
// const [batteryData, setBatteryData] = useState("")
|
// const [batteryData, setBatteryData] = useState("")
|
||||||
|
const osVersion = version()
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
@@ -62,7 +65,7 @@ function HardwareInfo() {
|
|||||||
<Chip>CPU型号: {allSysData?.cpus[0]?.brand}</Chip>
|
<Chip>CPU型号: {allSysData?.cpus[0]?.brand}</Chip>
|
||||||
<Chip>线程数: {allSysData?.cpu_count}</Chip>
|
<Chip>线程数: {allSysData?.cpu_count}</Chip>
|
||||||
<Chip>
|
<Chip>
|
||||||
系统: {allSysData?.name} {allSysData?.os_version}
|
系统: {allSysData?.name} {allSysData?.os_version} {osVersion}
|
||||||
</Chip>
|
</Chip>
|
||||||
<Chip>
|
<Chip>
|
||||||
内存:
|
内存:
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { addToast } from "@heroui/react"
|
import { addToast } from "@heroui/react"
|
||||||
import { FolderFocusOne } from "@icon-park/react"
|
import { FolderFocusOne } from "@icon-park/react"
|
||||||
import { Card, CardBody, CardHeader, CardIcon } from "../window/Card"
|
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 {
|
interface RoundedButtonProps {
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
@@ -22,6 +26,8 @@ const RoundedButton = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const CommonDir = () => {
|
const CommonDir = () => {
|
||||||
|
const steam = useSteamStore()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
@@ -32,50 +38,68 @@ const CommonDir = () => {
|
|||||||
<CardBody>
|
<CardBody>
|
||||||
<div className="flex gap-1.5">
|
<div className="flex gap-1.5">
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
// 调用 tauri api open steam.Dir
|
await invoke("open_path", {
|
||||||
|
path: steam.state.steamDir,
|
||||||
|
})
|
||||||
addToast({ title: "Steam安装位置" })
|
addToast({ title: "Steam安装位置" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Steam安装位置
|
Steam安装位置
|
||||||
</RoundedButton>
|
</RoundedButton>
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
await invoke("open_path", {
|
||||||
|
path: path.join(steam.state.cs2Dir, "game", "csgo", "cfg"),
|
||||||
|
})
|
||||||
addToast({ title: "CS2游戏目录" })
|
addToast({ title: "CS2游戏目录" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
CS2游戏目录
|
CS2游戏目录
|
||||||
</RoundedButton>
|
</RoundedButton>
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
await invoke("open_path", {
|
||||||
|
path: path.join(steam.state.cs2Dir, "game", "csgo", "maps"),
|
||||||
|
})
|
||||||
addToast({ title: "地图文件" })
|
addToast({ title: "地图文件" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
地图文件
|
地图文件
|
||||||
</RoundedButton>
|
</RoundedButton>
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
await invoke("open_path", {
|
||||||
|
path: path.join(steam.state.cs2Dir, "game", "csgo", "cfg"),
|
||||||
|
})
|
||||||
addToast({ title: "游戏CFG目录" })
|
addToast({ title: "游戏CFG目录" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
游戏CFG目录
|
游戏CFG目录
|
||||||
</RoundedButton>
|
</RoundedButton>
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
await invoke("open_path", {
|
||||||
|
path: path.join(steam.state.steamDir, "userdata"),
|
||||||
|
})
|
||||||
addToast({ title: "个人CFG目录" })
|
addToast({ title: "个人CFG目录" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
个人CFG目录
|
个人CFG目录
|
||||||
</RoundedButton>
|
</RoundedButton>
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
const appDataDirPath = await configDir()
|
||||||
|
await invoke("open_path", { path: `${appDataDirPath}/Wmpvp/demo` })
|
||||||
addToast({ title: "完美平台录像" })
|
addToast({ title: "完美平台录像" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
完美平台录像
|
完美平台录像
|
||||||
</RoundedButton>
|
</RoundedButton>
|
||||||
<RoundedButton
|
<RoundedButton
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
|
const appDataDirPath = await configDir()
|
||||||
|
await invoke("open_path", { path: `${appDataDirPath}/5E对战平台/demo` })
|
||||||
addToast({ title: "5E平台录像" })
|
addToast({ title: "5E平台录像" })
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user