[fix] powerplan calling with black screen
This commit is contained in:
@@ -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<i32, String>,
|
||||
@@ -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<i32, String> {
|
||||
let output = Command::new("powercfg")
|
||||
.arg("/L")
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.output()
|
||||
.map_err(|e| format!("Failed to execute powercfg command: {}", e))?;
|
||||
|
||||
|
||||
@@ -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<number>("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<number>("get_powerplan")
|
||||
tool.setPowerPlan(current)
|
||||
|
||||
if (toast) addToast({ title: "电源计划已切换 → " + PowerPlans[current].title })
|
||||
if (toast) addToast({ title: `电源计划已切换 → ${ PowerPlans[current].title}` })
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user