From 1d23c29ba8b5855c486681e5221952734c288399 Mon Sep 17 00:00:00 2001 From: Purp1e <47248616+Purple-CSGO@users.noreply.github.com> Date: Fri, 28 Mar 2025 13:22:26 +0800 Subject: [PATCH] [fix] fast launch from tray not working --- src-tauri/src/cmds.rs | 9 ++++++++- src/app/layout.tsx | 14 +++++++------- src/store/tool.ts | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/cmds.rs b/src-tauri/src/cmds.rs index 8264f72..9e95cfa 100644 --- a/src-tauri/src/cmds.rs +++ b/src-tauri/src/cmds.rs @@ -16,7 +16,14 @@ pub fn greet(name: &str) -> Result { #[tauri::command] pub fn launch_game(steam_path: &str, launch_option: &str, server: &str) -> Result { - wrap_err!(steam::launch_game(steam_path, launch_option, server)); + println!("{}: launching game on server: {}, with launch Option {}", steam_path, server, launch_option); + // wrap_err!(steam::launch_game(steam_path, launch_option, server)); + // 如果有错误,打印出来 + if let Err(e) = steam::launch_game(steam_path, launch_option, server) { + println!("Error: {}", e); + return Err(e.to_string()); + } + // steam::launch_game(steam_path, launch_option, server); Ok(format!( "Launching game on server: {}, with launch Option {}", diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 7f92ba3..5e27164 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,11 +1,11 @@ "use client" import { init } from "@/store" -import { useSteamStore } from "@/store/steam" -import { useToolStore } from "@/store/tool" +import { steamStore, useSteamStore } from "@/store/steam" +import { toolStore, 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 { useDebounce, useDebounceEffect, useDebounceFn } from "ahooks" import { useEffect } from "react" import "./globals.css" import Providers from "./providers" @@ -20,11 +20,11 @@ export default function RootLayout({ children }: { children: React.ReactNode }) void listen("tray://launch_game", async (event) => { await invoke("launch_game", { - steamPath: `${steam.state.steamDir}/steam.exe`, - launchOption: tool.state.launchOptions[tool.state.launchIndex].option || "", + steamPath: `${steamStore.state.steamDir}\\steam.exe`, + launchOption: toolStore.state.launchOptions[toolStore.state.launchIndex].option || "", server: event.payload || "worldwide", }) - addToast({ title: "启动国服成功" }) + addToast({ title: `启动${event.payload === "worldwide" ? "国际服" : "国服"}成功` }) }) void listen("tray://kill_steam", async () => { @@ -38,7 +38,7 @@ export default function RootLayout({ children }: { children: React.ReactNode }) }) void listen("tray://set_powerplan", async (event) => { - if (typeof(event.payload) === "number" && event.payload <= 0 && event.payload > 4) return + if (typeof event.payload === "number" && event.payload <= 0 && event.payload > 4) return await invoke("set_powerplan", { plan: event.payload }) const current = await invoke("get_powerplan") tool.setPowerPlan(current) diff --git a/src/store/tool.ts b/src/store/tool.ts index ea1570f..7850bc7 100644 --- a/src/store/tool.ts +++ b/src/store/tool.ts @@ -4,6 +4,7 @@ import { DEFAULT_STORE_CONFIG } from "./config" import { emit } from "@tauri-apps/api/event" import { invoke } from "@tauri-apps/api/core" import VideoSetting from "@/components/cstb/VideoSetting" +import { useSteamStore } from "./steam" interface LaunchOption { option: string