[feat] tray items with kill and launch game

todo: launch option selection + seperator
This commit is contained in:
Purp1e
2025-03-26 03:49:03 +08:00
parent ee03bf0160
commit 8f885a5412
2 changed files with 78 additions and 12 deletions

View File

@@ -1,21 +1,61 @@
"use client"
import { init } from "@/store"
import { useSteamStore } from "@/store/steam"
import { useToolStore } from "@/store/tool"
import { addToast } from "@heroui/react"
import { invoke } from "@tauri-apps/api/core"
import { listen } from "@tauri-apps/api/event"
import { useDebounce } from "ahooks"
import { useEffect } from "react"
import "./globals.css"
import Providers from "./providers"
import { init } from "@/store"
import { useDebounce } from "ahooks"
export default function RootLayout({ children }: { children: React.ReactNode }) {
const steam = useSteamStore()
const tool = useToolStore()
useEffect(() => {
void init()
void listen<string>("tray://launch_game", async (event) => {
await invoke("launch_game", {
steamPath: `${steam.state.steamDir}/steam.exe`,
launchOption: tool.state.launchOptions[tool.state.launchIndex].option || "",
server: event.payload || "worldwide",
})
addToast({ title: "启动国服成功" })
})
void listen<string>("tray://kill_steam", async () => {
await invoke("kill_steam")
addToast({ title: "已关闭Steam" })
})
void listen<string>("tray://kill_game", async () => {
await invoke("kill_game")
addToast({ title: "已关闭CS2" })
})
})
// 检测steam路径和游戏路径是否有效
const steam = useSteamStore()
const debounceSteamDir = useDebounce(steam.state.steamDir, {wait: 500, leading: true, trailing: true, maxWait: 2500})
const debounceCs2Dir = useDebounce(steam.state.cs2Dir, {wait: 500, leading: true, trailing: true, maxWait: 2500})
const debounceSteamDirValid = useDebounce(steam.state.steamDirValid, {wait: 500, leading: true, trailing: true, maxWait: 2500})
const debounceSteamDir = useDebounce(steam.state.steamDir, {
wait: 500,
leading: true,
trailing: true,
maxWait: 2500,
})
const debounceCs2Dir = useDebounce(steam.state.cs2Dir, {
wait: 500,
leading: true,
trailing: true,
maxWait: 2500,
})
const debounceSteamDirValid = useDebounce(steam.state.steamDirValid, {
wait: 500,
leading: true,
trailing: true,
maxWait: 2500,
})
useEffect(() => {
void steam.checkSteamDirValid()
}, [debounceSteamDir])