From ad5a1bd8709211f7c1f3b72f53574bccb324e62e Mon Sep 17 00:00:00 2001 From: Purp1e <47248616+Purple-CSGO@users.noreply.github.com> Date: Sat, 22 Mar 2025 21:44:27 +0800 Subject: [PATCH] [fix] powerplan calling with black screen --- src-tauri/src/tool/powerplan.rs | 6 ++++++ src/components/cstb/PowerPlan.tsx | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/tool/powerplan.rs b/src-tauri/src/tool/powerplan.rs index be70f53..c8a2e36 100644 --- a/src-tauri/src/tool/powerplan.rs +++ b/src-tauri/src/tool/powerplan.rs @@ -1,5 +1,9 @@ use std::collections::HashMap; use std::process::Command; +use std::os::windows::process::CommandExt; + +const CREATE_NO_WINDOW: u32 = 0x08000000; +// const DETACHED_PROCESS: u32 = 0x00000008; pub struct PowerPlan { power_plan_map: HashMap, @@ -37,6 +41,7 @@ impl PowerPlan { let output = Command::new("powercfg") .arg("/S") .arg(guid) + .creation_flags(CREATE_NO_WINDOW) .output() .map_err(|e| format!("Failed to execute powercfg command: {}", e))?; @@ -53,6 +58,7 @@ impl PowerPlan { pub fn get(&self) -> Result { let output = Command::new("powercfg") .arg("/L") + .creation_flags(CREATE_NO_WINDOW) .output() .map_err(|e| format!("Failed to execute powercfg command: {}", e))?; diff --git a/src/components/cstb/PowerPlan.tsx b/src/components/cstb/PowerPlan.tsx index 6909673..37beae7 100644 --- a/src/components/cstb/PowerPlan.tsx +++ b/src/components/cstb/PowerPlan.tsx @@ -34,13 +34,13 @@ const PowerPlan = () => { const tool = useToolStore() const setPowerPlan = async (key: Key) => { await tool.store.start() - const plan: number = Number(key) + const plan = Number(key) await invoke("set_powerplan", { plan: plan }) const current = await invoke("get_powerplan") tool.setPowerPlan(current) - addToast({ title: "电源计划已切换 → " + PowerPlans[current].title }) + addToast({ title: `电源计划已切换 → ${ PowerPlans[current].title}` }) } const getPowerPlan = async (toast: boolean) => { @@ -48,7 +48,7 @@ const PowerPlan = () => { const current = await invoke("get_powerplan") tool.setPowerPlan(current) - if (toast) addToast({ title: "电源计划已切换 → " + PowerPlans[current].title }) + if (toast) addToast({ title: `电源计划已切换 → ${ PowerPlans[current].title}` }) } useEffect(() => {