Skip to content

Commit 54ec9df

Browse files
committed
feat: configurable behaviour
1 parent 592254c commit 54ec9df

File tree

8 files changed

+286
-102
lines changed

8 files changed

+286
-102
lines changed

Cargo.lock

Lines changed: 51 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ description = "EcoQoS throtting tool."
77
[dependencies]
88
ahash = "0.8.11"
99
ctrlc = "3.4.6"
10+
directories = "6.0.0"
1011
kanal = "0.1.1"
1112
listen-new-proc = { git = "https://github.com/RustyStarX/fitgirl-ecoqos", version = "0.1.0" }
13+
serde = { version = "1.0.219", features = ["derive"] }
1214
spdlog-rs = "0.4.2"
1315
tokio = { version = "1.44.2", default-features = false, features = [
1416
"rt-multi-thread",
1517
"macros",
1618
] }
19+
toml = "0.8.22"
1720
win32-ecoqos = "0.5.0"
1821
windows = { version = "0.61", features = [
1922
# UI event hook

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ EnergyStar alernative in Rust.
1212

1313
## I only want to throttle blacklisted ones
1414

15-
See [fitgirl-ecoqos](https://github.com/RustyStarX/fitgirl-ecoqos),
16-
a tool that forces FitGirl repack unpacker processes to run on E-cores
17-
(Efficiency cores) for better system resource management.
15+
RustyStar now supports configuration.
1816

19-
You can customize it's blacklist. It's by default a set of decompressors.
17+
Locate to `%AppData%/RustyStarX/RustyStar/config` and open `config.toml`,
18+
19+
disable `listen_foreground_events` and switch mode of `listen_new_process` to `"blacklist_only"`, configure the blacklist.
2020

2121
## Roadmap
2222

@@ -28,11 +28,11 @@ You can customize it's blacklist. It's by default a set of decompressors.
2828
- [x] Event-based throttle for all new processes
2929
- [x] Recover processes on exit
3030
- [x] Ctrl-C handle
31-
- [ ] windows terminate handle
31+
- [ ] windows wm_close event handle
3232
- [x] Support UWP applications
3333
- [x] Support `SYSTEM` privileged processes
3434
> You must run `RustyStar.exe` as administrator to throttle them!
35-
- [ ] Configurable whitelist and blacklist
35+
- [x] Configurable whitelist and blacklist
3636

3737
## What is the efficiency mode?
3838

src/bypass/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ffi::OsStr;
22

33
use crate::WHITELIST;
44

5-
pub fn should_bypass(proc_name: impl AsRef<OsStr>) -> bool {
5+
pub fn whitelisted(proc_name: impl AsRef<OsStr>) -> bool {
66
WHITELIST
77
.get()
88
.is_some_and(|bypass| bypass.contains(proc_name.as_ref()))

src/config/mod.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
use std::{error::Error, fs, path::PathBuf};
2+
3+
use serde::{Deserialize, Serialize};
4+
use spdlog::warn;
5+
6+
#[derive(Debug, Serialize, Deserialize)]
7+
#[serde(default)]
8+
pub struct ListenForegroundEvents {
9+
pub enabled: bool,
10+
}
11+
12+
#[derive(Debug, Serialize, Deserialize, Default)]
13+
#[serde(rename_all = "snake_case")]
14+
pub enum ListenNewProcessMode {
15+
#[default]
16+
Normal,
17+
BlacklistOnly,
18+
}
19+
20+
#[derive(Debug, Serialize, Deserialize)]
21+
#[serde(default)]
22+
pub struct ListenNewProcess {
23+
pub enabled: bool,
24+
pub mode: ListenNewProcessMode,
25+
pub blacklist: Vec<String>,
26+
}
27+
28+
#[derive(Debug, Serialize, Deserialize)]
29+
#[serde(default)]
30+
pub struct Config {
31+
pub listen_new_process: ListenNewProcess,
32+
pub listen_foreground_events: ListenForegroundEvents,
33+
pub throttle_all_startup: bool,
34+
pub system_process: bool,
35+
pub whitelist: Vec<String>,
36+
}
37+
38+
impl Config {
39+
pub fn from_profile() -> Result<Self, Box<dyn Error + Send + Sync>> {
40+
let config_dir = directories::ProjectDirs::from("io", "RustyStarX", "RustyStar")
41+
.map(|d| d.config_dir().to_path_buf())
42+
.unwrap_or(PathBuf::from("."));
43+
fs::create_dir_all(&config_dir)?;
44+
45+
let config_path = config_dir.join("config.toml");
46+
if config_path.exists() {
47+
Ok(toml::from_str(&fs::read_to_string(&config_path)?)?)
48+
} else {
49+
warn!("config not existing! falling back to default...");
50+
let config = Self::default();
51+
let serialized = toml::to_string_pretty(&config)?;
52+
_ = fs::write(config_path, serialized).inspect_err(|e| {
53+
warn!("failed to write default config: {e}");
54+
});
55+
Ok(config)
56+
}
57+
}
58+
}
59+
60+
impl Default for Config {
61+
fn default() -> Self {
62+
Self {
63+
listen_new_process: ListenNewProcess::default(),
64+
listen_foreground_events: ListenForegroundEvents::default(),
65+
throttle_all_startup: true,
66+
system_process: true,
67+
whitelist: [
68+
// ourself
69+
"RustyStar.exe",
70+
// System processes
71+
"explorer.exe",
72+
// Windows Manager of Windows
73+
"dwm.exe",
74+
// CSRSS core process
75+
"csrss.exe",
76+
// Windows services process
77+
"svchost.exe",
78+
// Task Manager
79+
"Taskmgr.exe",
80+
// Session Manager Subsystem
81+
"smss.exe",
82+
// Chinese input method
83+
"ChsIME.exe",
84+
// Speech-To-Text, Screen keyboard, handwrite input, e.g.
85+
"ctfmon.exe",
86+
// Windows User Mode Driver Framework
87+
"WUDFRd.exe",
88+
"WUDFHost.exe",
89+
// Edge is energy aware
90+
"msedge.exe",
91+
// UWP special handle
92+
"ApplicationFrameHost.exe",
93+
// system itself
94+
"[System Process]",
95+
"System",
96+
"Registry",
97+
// parent of "services.exe"
98+
"wininit.exe",
99+
// parent of "svchost.exe", "wudfhost.exe", e.g.
100+
"services.exe",
101+
// Local Security Authority Subsystem Service
102+
"lsass.exe",
103+
// part of the Windows Security Center,
104+
// responsible for monitoring and reporting the security status of your system
105+
"SecurityHealthService.exe",
106+
]
107+
.map(str::to_string)
108+
.to_vec(),
109+
}
110+
}
111+
}
112+
113+
impl Default for ListenForegroundEvents {
114+
fn default() -> Self {
115+
Self { enabled: true }
116+
}
117+
}
118+
119+
impl Default for ListenNewProcess {
120+
fn default() -> Self {
121+
Self {
122+
enabled: true,
123+
mode: ListenNewProcessMode::default(),
124+
blacklist: vec![],
125+
}
126+
}
127+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ahash::AHashSet;
44
use kanal::Sender;
55

66
pub mod bypass;
7+
pub mod config;
78
pub mod events;
89
pub mod logging;
910
pub mod privilege;

0 commit comments

Comments
 (0)