[feat] better store saving logic + more launch options

This commit is contained in:
Purp1e
2025-03-13 22:04:27 +08:00
parent 7195bad731
commit 0bd15a80cd
4 changed files with 22 additions and 12 deletions

View File

@@ -10,7 +10,6 @@ body {
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
border-radius: 10px;
background: transparent;
}

View File

@@ -1,4 +1,4 @@
import { setLaunchIndex, setLaunchOption, toolStore } from "@/store/tool"
import { addLaunchOption, setLaunchIndex, setLaunchOption, toolStore } from "@/store/tool"
import { Plus, SettingConfig, Switch } from "@icon-park/react"
import { useSnapshot } from "valtio"
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
@@ -15,10 +15,12 @@ const LaunchOption = () => {
<SettingConfig />
</CardIcon>
<CardTool>
<ToolButton onClick={() => setLaunchIndex(0)}>1</ToolButton>
<ToolButton onClick={() => setLaunchIndex(1)}>2</ToolButton>
<ToolButton onClick={() => setLaunchIndex(2)}>3</ToolButton>
<ToolButton>
{launchOptions.map((option, index) => (
<ToolButton key={index} onClick={() => setLaunchIndex(index)}>
{index+1}
</ToolButton>
))}
<ToolButton onClick={() => addLaunchOption("")}>
<Plus />
</ToolButton>
@@ -32,9 +34,7 @@ const LaunchOption = () => {
<textarea
placeholder="请输入启动选项"
value={launchOptions[launchIndex] || ""}
onChange={(e) =>
launchIndex !== -1 && setLaunchOption(e.target.value, launchIndex)
}
onChange={(e) => launchIndex !== -1 && setLaunchOption(e.target.value, launchIndex)}
className="w-full font-mono text-base bg-transparent outline-none resize-none min-h-20"
/>
</CardBody>

View File

@@ -16,19 +16,19 @@ import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
import { useTheme } from "next-themes"
// import { platform } from "@tauri-apps/plugin-os"
import { usePathname, useRouter } from "next/navigation"
import { saveAll } from "tauri-plugin-valtio"
import { saveAllNow } from "tauri-plugin-valtio"
const Nav = () => {
const { theme, setTheme } = useTheme()
const close = async () => {
// (await window.hideOnClose) ? getCurrent().hide() : exit();
await saveAll()
await saveAllNow()
await exit()
}
const minimize = async () => {
await saveAll()
await saveAllNow()
await getCurrentWindow().minimize()
}

View File

@@ -37,6 +37,17 @@ export const setPowerPlan = (plan: number) => {
toolStore.state.powerPlan = plan
}
export const addLaunchOption = (option: string) => {
// 限制最高10个
if (toolStore.state.launchOptions.length >= 10) {
return
}
toolStore.state.launchOptions = [
...toolStore.state.launchOptions,
option,
]
}
export const resetToolStore = () => {
toolStore.state.launchOptions = defaultValue.launchOptions
toolStore.state.launchIndex = defaultValue.launchIndex