[feat] launch option edit and remove

This commit is contained in:
2025-07-08 11:31:43 +08:00
parent 7012f0d9fe
commit 35ecf4ce0a
7 changed files with 102 additions and 30 deletions

View File

@@ -1,13 +1,15 @@
import { useToolStore } from "@/store/tool" import { LaunchOption as iLaunchOption, useToolStore } from "@/store/tool"
import { Plus, SettingConfig, Switch } from "@icon-park/react" import { Badge, Close, Edit, Plus, Save, SettingConfig, Switch } from "@icon-park/react"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card" import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import { ToolButton } from "../window/ToolButton" import { ToolButton } from "../window/ToolButton"
import { Tooltip } from "@heroui/react" import { Button, Input, Tooltip } from "@heroui/react"
import { remove } from "@tauri-apps/plugin-fs"
const LaunchOption = () => { const LaunchOption = () => {
const tool = useToolStore() const tool = useToolStore()
const [launchOpt, setLaunchOpt] = useState(tool.state.launchOptions[tool.state.launchIndex] || "") const [launchOpt, setLaunchOpt] = useState(tool.state.launchOptions[tool.state.launchIndex] || "")
const [editMode, setEditMode] = useState(false)
useEffect(() => { useEffect(() => {
setLaunchOpt(tool.state.launchOptions[tool.state.launchIndex] || "") setLaunchOpt(tool.state.launchOptions[tool.state.launchIndex] || "")
@@ -19,22 +21,78 @@ const LaunchOption = () => {
<CardIcon> <CardIcon>
<SettingConfig /> <SettingConfig />
</CardIcon> </CardIcon>
<CardTool> <CardTool className="">
{tool.state.launchOptions.map((option, index) => ( {tool.state.launchOptions.map((option, index) =>
<ToolButton key={index} onClick={() => tool.setLaunchIndex(index)}> editMode ? (
{option.name || index + 1} <Tooltip
</ToolButton> radius="sm"
))} size="sm"
offset={-4}
crossOffset={18}
delay={300}
closeDelay={100}
placement="top-end"
color="foreground"
className="p-0 rounded-md bg-opacity-85"
content={
<button className="p-1 text-small" onClick={() => {tool.removeLaunchOption(index)}}>
<Close size={12} />
</button>
}
>
<Input
key={index}
value={option.name}
onValueChange={(value: string) => {
tool.setLaunchOption({ ...option, name: value } as iLaunchOption, index)
}}
variant="bordered"
size="sm"
placeholder="名称"
fullWidth={false}
/>
</Tooltip>
) : (
// <Input
// variant="bordered"
// size="sm"
// value={steam.state.steamDir}
// onValueChange={(value) => {
// setSteamDir(value)
// steam.setDir(value)
// }}
// description="steam.exe所在文件夹"
// errorMessage={"路径无效"}
// isInvalid={!steam.state.steamDirValid}
// />
<ToolButton key={index} onClick={() => tool.setLaunchIndex(index)}>
{option.name || index + 1}
</ToolButton>
)
)}
<ToolButton onClick={() => tool.addLaunchOption({ option: "", name: "" })}> <ToolButton onClick={() => tool.addLaunchOption({ option: "", name: "" })}>
<Plus /> <Plus />
</ToolButton> </ToolButton>
<Tooltip content="功能测试中,尚未实装" showArrow={true} delay={300}> {/* <Tooltip content="功能测试中,尚未实装" showArrow={true} delay={300}>
<ToolButton> <ToolButton>
<Switch /> <Switch />
切换模式 切换模式
</ToolButton> </ToolButton>
</Tooltip> </Tooltip> */}
<ToolButton onClick={() => setEditMode(!editMode)}>
{editMode ? (
<>
<Save />
</>
) : (
<>
<Edit />
</>
)}
</ToolButton>
</CardTool> </CardTool>
</CardHeader> </CardHeader>
<CardBody> <CardBody>

View File

@@ -66,6 +66,7 @@ export function Prepare() {
setLoading(false) setLoading(false)
}, 1200) }, 1200)
} }
// router.push("/home")
}, [inited]) }, [inited])
const handleSelectSteamDir = async () => { const handleSelectSteamDir = async () => {

View File

@@ -401,6 +401,7 @@ const VideoSetting = () => {
defaultres: value.toString(), defaultres: value.toString(),
}) })
}} }}
isDisabled={!edit}
radius="full" radius="full"
step={10} step={10}
className="max-w-28" className="max-w-28"
@@ -408,18 +409,22 @@ const VideoSetting = () => {
/> />
<NumberInput <NumberInput
aria-label="height" aria-label="height"
value={parseInt(edit ? vconfig.defaultresheight : tool.state.videoSetting.defaultresheight, 10)} value={parseInt(
edit ? vconfig.defaultresheight : tool.state.videoSetting.defaultresheight,
10
)}
onValueChange={(value) => { onValueChange={(value) => {
const _ = edit const _ = edit
? setVconfig({ ? setVconfig({
...vconfig, ...vconfig,
defaultresheight: value.toString(), defaultresheight: value.toString(),
}) })
: tool.setVideoSetting({ : tool.setVideoSetting({
...tool.state.videoSetting, ...tool.state.videoSetting,
defaultresheight: value.toString(), defaultresheight: value.toString(),
}) })
}} }}
isDisabled={!edit}
radius="full" radius="full"
step={10} step={10}
className="max-w-28" className="max-w-28"

View File

@@ -24,7 +24,7 @@ const Card = ({ children, className, ...props }: CardProps) => {
const CardHeader = ({ children }: CardProps) => { const CardHeader = ({ children }: CardProps) => {
return ( return (
<div className="flex items-center gap-1.5 tracking-wide select-none"> <div className="flex items-center gap-1.5 tracking-wide select-none flex-shrink-0">
{children} {children}
</div> </div>
) )
@@ -34,7 +34,7 @@ const CardIcon = ({ children, type, className, ...rest }: CardProps) => {
return ( return (
<div <div
className={cn( className={cn(
"flex gap-1.5 items-center font-semibold", "flex gap-1.5 items-center font-semibold flex-shrink-0",
type === "menu" && type === "menu" &&
"transition cursor-pointer hover:bg-black/5 dark:hover:bg-white/5 px-2 py-1 rounded-md active:scale-95", "transition cursor-pointer hover:bg-black/5 dark:hover:bg-white/5 px-2 py-1 rounded-md active:scale-95",
className, className,
@@ -46,9 +46,9 @@ const CardIcon = ({ children, type, className, ...rest }: CardProps) => {
) )
} }
const CardTool = ({ children }: CardProps) => { const CardTool = ({ children, className }: CardProps) => {
return ( return (
<div className="flex items-center justify-end flex-grow gap-2"> <div className={cn("flex items-center justify-end flex-grow gap-2", className)}>
{children} {children}
</div> </div>
) )

View File

@@ -118,7 +118,7 @@ const SideBar = () => {
<div className="mx-auto text-sm text-center text-zinc-500" data-tauri-drag-region> <div className="mx-auto text-sm text-center text-zinc-500" data-tauri-drag-region>
<p></p> <p></p>
<p className="py-1 text-sm text-zinc-600">{app.state.version}</p> <p className="py-1 text-xs text-zinc-600">{app.state.version}</p>
</div> </div>
</div> </div>
) )

View File

@@ -7,7 +7,7 @@ export const ToolButton = ({ children, ...rest }: ToolButtonProps) => {
return ( return (
<button <button
type="button" type="button"
className="flex gap-0.5 active:scale-95 items-center min-w-7 justify-center px-2 py-1.5 bg-black/5 transition hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10 rounded-md text-sm leading-none" className="flex flex-shrink-0 gap-0.5 active:scale-95 items-center min-w-7 justify-center px-2 py-1.5 bg-black/5 transition hover:bg-black/10 dark:bg-white/5 dark:hover:bg-white/10 rounded-md text-sm leading-none"
{...rest} {...rest}
> >
{children} {children}

View File

@@ -6,7 +6,7 @@ import { invoke } from "@tauri-apps/api/core"
import VideoSetting from "@/components/cstb/VideoSetting" import VideoSetting from "@/components/cstb/VideoSetting"
import { useSteamStore } from "./steam" import { useSteamStore } from "./steam"
interface LaunchOption { export interface LaunchOption {
option: string option: string
name: string name: string
} }
@@ -118,7 +118,7 @@ export const VideoSettingTemplate = {
const defaultValue = { const defaultValue = {
launchOptions: [ launchOptions: [
{ option: "-novid -high -freq 144 -fullscreen", name: "" }, { option: "-novid -high -freq 144 -fullscreen", name: "" },
{ option: "-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder", name: "" }, { option: "-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder", name: "test" },
{ option: "-novid -high -freq 144 -fullscreen -allow_third_party_software", name: "" }, { option: "-novid -high -freq 144 -fullscreen -allow_third_party_software", name: "" },
] as LaunchOption[], ] as LaunchOption[],
launchIndex: 0, launchIndex: 0,
@@ -182,6 +182,7 @@ export const useToolStore = () => {
setLaunchOption, setLaunchOption,
setLaunchOptions, setLaunchOptions,
setLaunchIndex, setLaunchIndex,
removeLaunchOption,
setPowerPlan, setPowerPlan,
setVideoSetting, setVideoSetting,
getVideoConfig, getVideoConfig,
@@ -208,6 +209,13 @@ const setLaunchIndex = (index: number) => {
sendCurrentLaunchOptionToTray(index) sendCurrentLaunchOptionToTray(index)
} }
const removeLaunchOption = (index: number) => {
toolStore.state.launchOptions = [
...toolStore.state.launchOptions.slice(0, index),
...toolStore.state.launchOptions.slice(index + 1),
]
}
const sendCurrentLaunchOptionToTray = (index: number) => { const sendCurrentLaunchOptionToTray = (index: number) => {
void emit("tray://get_current_launch_option", toolStore.state.launchOptions[index].name || index + 1) void emit("tray://get_current_launch_option", toolStore.state.launchOptions[index].name || index + 1)
} }
@@ -230,7 +238,7 @@ const getVideoConfig = async (steam_dir: string, steam_id32: number) => {
} }
const setVideoConfig = async (steam_dir: string, steam_id32: number, video_config: VideoSetting) => { const setVideoConfig = async (steam_dir: string, steam_id32: number, video_config: VideoSetting) => {
console.log(video_config.videocfg_hdr_detail) // console.log(video_config.videocfg_hdr_detail)
await invoke("set_cs2_video_config", { steamDir: steam_dir, steamId32: steam_id32, videoConfig: video_config }) await invoke("set_cs2_video_config", { steamDir: steam_dir, steamId32: steam_id32, videoConfig: video_config })
} }