Skip to content

Commit 5effe50

Browse files
committed
clippy
1 parent 9199ff4 commit 5effe50

File tree

8 files changed

+23
-19
lines changed

8 files changed

+23
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords =["transparency", "windows"]
66
name ="win_alpha"
77
readme ="readme.md"
88
repository ="https://github.com/tadghh/transparent-windows"
9-
version ="1.2.8"
9+
version ="1.2.9"
1010

1111
[[bin]]
1212
name="win_alpha"

src/app_state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl AppState {
104104
let config_json = serde_json::to_string_pretty(&config.to_owned())?;
105105
self.config_tx.send(config.to_owned())?;
106106

107-
fs::write(&self.get_config_path(), config_json)?;
107+
fs::write(self.get_config_path(), config_json)?;
108108

109109
Ok(())
110110
}
@@ -152,7 +152,7 @@ impl AppState {
152152
let config_json = serde_json::to_string_pretty(&config.to_owned())?;
153153
self.config_tx.send(config.to_owned())?;
154154

155-
fs::write(&self.get_config_path(), config_json)?;
155+
fs::write(self.get_config_path(), config_json)?;
156156

157157
Ok(())
158158
}

src/monitor.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ use crate::{app_state::AppState, util::Config, win_utils::make_window_transparen
22
use core::time::Duration;
33
use std::{collections::HashMap, os::raw::c_void, sync::Arc};
44
use windows::Win32::{Foundation::HWND, UI::WindowsAndMessaging::IsWindow};
5+
6+
// Delays between window monitor runs
7+
// new windows, window updates etc.
8+
const MONITOR_DELAY: u64 = 120;
9+
510
#[derive(Eq, PartialEq, Clone, Debug)]
611
struct WindowHandleState {
712
handle: isize,
@@ -47,7 +52,7 @@ impl WindowHandleState {
4752

4853
pub fn update_window(&mut self, mut new_transparency: u8, enabled: bool) {
4954
let real_transparency = new_transparency;
50-
if enabled == false {
55+
if !enabled {
5156
new_transparency = 255;
5257
}
5358
if make_window_transparent(self.get_handle(), new_transparency).is_ok() {
@@ -61,7 +66,7 @@ impl WindowHandleState {
6166
*/
6267
#[inline(always)]
6368
pub async fn monitor_windows(app_state: Arc<AppState>) {
64-
let refresh_interval = Duration::from_millis(160);
69+
let refresh_interval = Duration::from_millis(MONITOR_DELAY);
6570

6671
let mut config = app_state.get_config().await;
6772
let mut is_enabled = app_state.is_enabled().await;

src/tray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn add_tray_menu_item(
4141
message: Message,
4242
) -> Result<(), TIError> {
4343
let tx_clone = tx.clone();
44-
tray.add_menu_item(&label, move || {
44+
tray.add_menu_item(label, move || {
4545
if let Err(e) = tx_clone.send(message.clone()) {
4646
eprintln!("Failed to send {} message: {}", label, e);
4747
}

src/util.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,19 @@ pub fn create_config_error_window(config_path: PathBuf) -> Result<(), Error> {
100100
if let Ok(config_json) = serde_json::to_string_pretty(&[serde_json::json!({})])
101101
&& let Ok(config_clone) = config_clone.lock()
102102
{
103-
fs::write(&config_clone.as_str(), config_json).expect("better not.");
103+
fs::write(config_clone.as_str(), config_json).expect("better not.");
104104
} else {
105105
_ = anyhow!("AHHHHH failed to lock/write config!!!");
106106
}
107107
}
108108
});
109109

110110
window.on_cancel(move || {
111-
if !*action_taken_clone.lock().unwrap() {
112-
if let Ok(config_clone) = config_clone_cancel.lock()
113-
&& let Ok(config_json) = serde_json::to_string_pretty(&[serde_json::json!({})])
114-
{
115-
fs::write(config_clone.as_str(), config_json).expect("better not.");
116-
}
111+
if !*action_taken_clone.lock().unwrap()
112+
&& let Ok(config_clone) = config_clone_cancel.lock()
113+
&& let Ok(config_json) = serde_json::to_string_pretty(&[serde_json::json!({})])
114+
{
115+
fs::write(config_clone.as_str(), config_json).expect("better not.");
117116
}
118117

119118
if let Some(handle) = window_handle.upgrade() {

src/win_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ fn is_elevated(point: POINT) -> bool {
315315

316316
unsafe {
317317
let hwnd = WindowFromPoint(point);
318-
if hwnd.0 == std::ptr::null_mut() {
318+
if hwnd.0.is_null() {
319319
return false;
320320
}
321321

@@ -362,7 +362,7 @@ fn is_running_as_admin() -> bool {
362362
size,
363363
&mut size,
364364
)
365-
.map_or(false, |_| elevation.TokenIsElevated != 0)
365+
.is_ok_and(|_| elevation.TokenIsElevated != 0)
366366
}
367367
}
368368

@@ -448,6 +448,6 @@ pub fn get_startup_state() -> bool {
448448
Some(&mut size),
449449
);
450450

451-
return result == ERROR_SUCCESS;
451+
result == ERROR_SUCCESS
452452
}
453453
}

src/window_config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn find_window_by_class(target_class: &str) -> windows::core::Result<Option<HWND
221221
unsafe extern "system" fn enum_windows_proc(parent_hwnd: HWND, lparam: LPARAM) -> BOOL {
222222
let state = &mut *(lparam.0 as *mut SearchState);
223223
let _ = EnumChildWindows(Some(parent_hwnd), Some(enum_child_windows_proc), lparam);
224-
(!state.found_hwnd.is_some()).into()
224+
(state.found_hwnd.is_none()).into()
225225
}
226226

227227
fn find_topmost_parent(hwnd: HWND) -> Option<HWND> {
@@ -282,7 +282,7 @@ impl From<TransparencyRule> for WindowConfig {
282282
WindowConfig {
283283
process_name: config.process_name.to_owned().into(),
284284
window_class: config.window_class.to_owned().into(),
285-
transparency: convert_to_full(config.transparency.try_into().unwrap_or(100)),
285+
transparency: convert_to_full(config.transparency),
286286
enabled: config.enabled,
287287
force: config.force,
288288
old_class: if config.old_class.is_empty() {

0 commit comments

Comments
 (0)