Skip to content

Commit b567ca7

Browse files
committed
docs/clean up: clean up
1 parent 41d8177 commit b567ca7

File tree

5 files changed

+37
-26
lines changed

5 files changed

+37
-26
lines changed

rustfmt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edition = "2021"
2+
merge_imports = true # Merges multiple imports from the same crate
3+
imports_granularity = "Crate" # Merges to the crate level where possible

src/app_state.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub struct AppState {
2222

2323
impl AppState {
2424
pub fn new(config: Config, config_path: PathBuf) -> Self {
25-
let (tx, _) = broadcast::channel(2);
26-
let (txe, _) = broadcast::channel(2);
25+
let (config_tx, _) = broadcast::channel(2);
26+
let (enabled_tx, _) = broadcast::channel(2);
2727

2828
Self {
29-
config_tx: tx,
30-
enabled_tx: txe,
29+
config_tx,
30+
enabled_tx,
3131
config: Arc::new(RwLock::new(config)),
3232
config_path,
3333
enabled: Arc::new(RwLock::new(true)),
@@ -48,6 +48,7 @@ impl AppState {
4848
}
4949
});
5050
}
51+
5152
pub fn spawn_force_config(&self, value: WindowConfig) {
5253
let app_state: Arc<AppState> = Arc::new(self.clone());
5354

@@ -116,7 +117,6 @@ impl AppState {
116117
) -> Result<(), anyhow::Error> {
117118
let mut config = self.get_config_mut().await;
118119

119-
// Get the class name to use for parent lookup
120120
let lookup_class = window_config
121121
.get_old_classname()
122122
.clone()
@@ -134,6 +134,7 @@ impl AppState {
134134
window_config.refresh_config();
135135
window_config.set_old_classname(Some(lookup_class));
136136
} else {
137+
// The config is no longer being forced to remove the parent class
137138
window_config.set_window_class(&parent_class);
138139
window_config.reset_config();
139140
window_config.set_window_class(&lookup_class);
@@ -159,10 +160,8 @@ impl AppState {
159160
}
160161

161162
fn remove_existing_config(&self, config: &mut Config, window_config: &WindowConfig) {
162-
// Remove configuration by original key
163163
config.get_windows().remove(&window_config.get_key());
164164

165-
// Remove configuration by old class if it exists
166165
if let Some(old_class) = window_config.get_old_classname() {
167166
let key = format!("{}|{}", window_config.get_name(), old_class);
168167
config.get_windows().remove(&key);
@@ -181,7 +180,15 @@ impl AppState {
181180
*self.enabled.read().await
182181
}
183182

184-
pub async fn set_enable_state(&self, new_state: bool) {
183+
pub async fn enabled(&self) {
184+
self.set_enable_state(true).await
185+
}
186+
187+
pub async fn disable(&self) {
188+
self.set_enable_state(false).await
189+
}
190+
191+
async fn set_enable_state(&self, new_state: bool) {
185192
*self.enabled.write().await = new_state;
186193

187194
self.enabled_tx

src/main.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@ mod win_utils;
1313
mod window_config;
1414
use app_state::AppState;
1515
use monitor::monitor_windows;
16-
use tray::setup_tray;
16+
use tray::{setup_tray, STARTUP_ID};
1717
use util::{load_config, Message};
18-
1918
use win_utils::{change_startup, get_startup_state};
2019
slint::include_modules!();
2120

2221
#[cfg(target_os = "windows")]
2322
#[tokio::main]
2423
async fn main() -> Result<()> {
25-
use tray::STARTUP_ID;
26-
24+
let (config, config_path) = load_config();
2725
let (tx, mut rx): (UnboundedSender<Message>, UnboundedReceiver<Message>) =
2826
mpsc::unbounded_channel();
2927

30-
let (config, config_path) = load_config();
31-
3228
let mut tray = setup_tray(tx.clone())?;
3329

3430
let app_state = Arc::new(AppState::new(config, config_path));
@@ -56,13 +52,13 @@ async fn main() -> Result<()> {
5652
}
5753
}
5854
Message::Enable => {
59-
app_state.set_enable_state(true).await;
55+
app_state.enabled().await;
6056
}
6157
Message::Disable => {
62-
app_state.set_enable_state(false).await;
58+
app_state.disable().await;
6359
}
6460
Message::Startup => {
65-
let _ = change_startup(!get_startup_state());
61+
_ = change_startup(!get_startup_state());
6662
let state_string = format!("Startup - {}", get_startup_state());
6763
tray.inner_mut()
6864
.set_menu_item_label(&state_string, STARTUP_ID)?;

src/tray.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ pub fn setup_tray(tx: UnboundedSender<Message>) -> Result<TrayItem, TIError> {
3232
Ok(tray)
3333
}
3434

35+
/*
36+
Just adds another tray item. Keeps the above method clean
37+
*/
3538
fn add_tray_menu_item(
3639
tray: &mut TrayItem,
3740
label: &'static str,

src/window_config.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
use core::ffi::c_void;
22
use std::path::Path;
33

4-
use crate::win_utils::WindowInfo;
4+
use crate::{
5+
win_utils::{convert_to_full, convert_to_human, make_window_transparent, WindowInfo},
6+
TransparencyRule,
7+
};
58
use serde::{Deserialize, Serialize};
69
use windows::core::PCWSTR;
710

8-
use windows::Win32::Foundation::CloseHandle;
9-
use windows::Win32::System::ProcessStatus::GetProcessImageFileNameA;
10-
use windows::Win32::System::Threading::{OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION};
11-
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
1211
use windows::Win32::{
13-
Foundation::{BOOL, HWND, LPARAM, MAX_PATH},
12+
Foundation::{CloseHandle, BOOL, HWND, LPARAM, MAX_PATH},
13+
System::{
14+
ProcessStatus::GetProcessImageFileNameA,
15+
Threading::{OpenProcess, PROCESS_QUERY_LIMITED_INFORMATION},
16+
},
1417
UI::WindowsAndMessaging::{
1518
EnumChildWindows, EnumWindows, FindWindowExW, FindWindowW, GetClassNameW, GetParent,
19+
GetWindowThreadProcessId,
1620
},
1721
};
1822

19-
use crate::win_utils::{convert_to_full, convert_to_human, make_window_transparent};
20-
use crate::TransparencyRule;
21-
2223
#[derive(Serialize, Deserialize, Clone, Debug)]
2324
pub struct WindowConfig {
2425
#[serde(default)]
@@ -154,6 +155,7 @@ impl WindowConfig {
154155
_ = make_window_transparent(HWND(handle as *mut c_void), self.get_transparency());
155156
}
156157
}
158+
157159
/*
158160
Returns all the current handles for the classname
159161
*/

0 commit comments

Comments
 (0)