Skip to content

Commit a5de9fc

Browse files
committed
enhance: skip throtting last process if found full screen app in foreground
1 parent 1b652b6 commit a5de9fc

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ windows = { version = "0.61", features = [
2929
"Win32_UI_WindowsAndMessaging",
3030
# enable SeDebugPrivilege for SYSTEM processes
3131
"Win32_Security",
32+
# SHQueryUserNotificationStat
33+
"Win32_UI_Shell",
3234
] }
3335
windows-version = "0.1.4"
3436

src/main.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22
use std::ffi::OsString;
33

44
use ahash::AHashSet;
5-
use spdlog::{Level, LevelFilter, debug, error, info, warn};
5+
use spdlog::{Level, LevelFilter, debug, error, info, trace, warn};
66
use win32_ecoqos::process::toggle_efficiency_mode;
77

88
use rustystar::bypass::whitelisted;
@@ -12,6 +12,9 @@ use rustystar::logging::log_error;
1212
use rustystar::privilege::try_enable_se_debug_privilege;
1313
use rustystar::utils::{process_child_process, toggle_all};
1414
use rustystar::{PID_SENDER, WHITELIST};
15+
use windows::Win32::UI::Shell::{
16+
QUNS_BUSY, QUNS_RUNNING_D3D_FULL_SCREEN, SHQueryUserNotificationState,
17+
};
1518

1619
#[compio::main]
1720
async fn main() -> Result<(), Box<dyn Error>> {
@@ -97,19 +100,25 @@ async fn main() -> Result<(), Box<dyn Error>> {
97100
let mut last_pid = None;
98101

99102
while let Ok(pid) = rx.recv().await {
100-
debug!("received: {pid}");
103+
trace!("received: {pid}");
101104

102105
match last_pid {
103106
// skip boosting
104107
Some(last) if last == pid => {
105108
continue;
106109
}
107-
Some(last_pid) => {
108-
_ = compio::runtime::spawn_blocking(move || {
109-
process_child_process(Some(true), last_pid)
110-
})
111-
.await;
112-
}
110+
Some(last_pid) => match unsafe { SHQueryUserNotificationState() } {
111+
Ok(QUNS_BUSY) | Ok(QUNS_RUNNING_D3D_FULL_SCREEN) => {
112+
debug!("detected full screen app! skip throttling");
113+
}
114+
_ => {
115+
_ = compio::runtime::spawn_blocking(move || {
116+
process_child_process(Some(true), last_pid)
117+
})
118+
.await;
119+
}
120+
},
121+
113122
None => {}
114123
}
115124

src/utils/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::BTreeMap;
22

33
use rustc_hash::FxHashSet;
4-
use spdlog::{info, warn};
4+
use spdlog::{debug, info, warn};
55
use win32_ecoqos::{
66
process::toggle_efficiency_mode,
77
utils::{Process, Processes},
@@ -13,7 +13,7 @@ use crate::bypass::whitelisted;
1313
pub fn process_child_process(enable: Option<bool>, main_pid: u32) -> windows_result::Result<()> {
1414
let action = match enable {
1515
Some(true) => "throtting",
16-
Some(false) => "boosting ",
16+
Some(false) => "boosting",
1717
None => "recovering",
1818
};
1919

@@ -23,13 +23,13 @@ pub fn process_child_process(enable: Option<bool>, main_pid: u32) -> windows_res
2323
.find(|Process { process_id, .. }| process_id == &main_pid)
2424
{
2525
if whitelisted(process_name) {
26-
info!("skipping whitelisted process: {process_name:?}");
26+
debug!("[{action:^10}] skipping {process_name:?}");
2727
return Ok(());
2828
}
2929

30-
info!("{action} process {main_pid:6}: {process_name:?}");
30+
info!("[{action:^10}] process {main_pid:6}: {process_name:?}");
3131
} else {
32-
info!("{action} process {main_pid:6}");
32+
info!("[{action:^10}] process {main_pid:6}");
3333
}
3434

3535
let relations = BTreeMap::from_iter(procs.iter().map(

0 commit comments

Comments
 (0)