Skip to content

Commit 471fc9e

Browse files
committed
Refactor config loading and clean up code
Simplified the Bangla ordinal suffix match in bangla_date.rs. Refactored Config::load in config.rs to use let-chains for cleaner logic. Updated screensaver.rs to use a const thread-local buffer and improved ScreensaverMode argument handling. Fixed button style casting and added a clippy allow in settings.rs. Removed the unused build.ps1 script.
1 parent 21133ed commit 471fc9e

5 files changed

Lines changed: 13 additions & 41 deletions

File tree

build.ps1

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/bangla_date.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ fn get_bangla_ordinal_suffix(day: u8) -> &'static str {
5050
1 => "লা",
5151
2 | 3 => "রা",
5252
4 => "ঠা",
53-
5 | 6 => "ই",
54-
7 => "ই",
55-
8 | 9 | 10 => "ই",
56-
11 | 12 => "ই",
53+
5..=12 => "ই",
5754
_ => "ই",
5855
}
5956
}

src/config.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,12 @@ impl Config {
162162

163163
/// Load configuration from file, or create default if not exists
164164
pub fn load() -> Self {
165-
if let Some(path) = Self::config_path() {
166-
if path.exists() {
167-
if let Ok(content) = fs::read_to_string(&path) {
168-
if let Ok(config) = serde_json::from_str(&content) {
169-
return config;
170-
}
171-
}
172-
}
165+
if let Some(path) = Self::config_path()
166+
&& path.exists()
167+
&& let Ok(content) = fs::read_to_string(&path)
168+
&& let Ok(config) = serde_json::from_str(&content)
169+
{
170+
return config;
173171
}
174172
let config = Self::default();
175173
config.save(); // Save default config

src/screensaver.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static RENDERER: OnceLock<Mutex<Renderer>> = OnceLock::new();
3030

3131
// Thread-local buffer for rendering to avoid per-frame allocations
3232
thread_local! {
33-
static RENDER_BUFFER: RefCell<Vec<u8>> = RefCell::new(Vec::new());
33+
static RENDER_BUFFER: RefCell<Vec<u8>> = const { RefCell::new(Vec::new()) };
3434
}
3535

3636
/// Screensaver operating mode
@@ -74,9 +74,8 @@ impl ScreensaverMode {
7474
0
7575
};
7676
ScreensaverMode::Preview(hwnd)
77-
} else if arg.starts_with("/s") || arg.starts_with("-s") {
78-
ScreensaverMode::Screensaver
7977
} else {
78+
// Default to Screensaver mode for /s, -s, or any other argument
8079
ScreensaverMode::Screensaver
8180
}
8281
}
@@ -304,7 +303,7 @@ fn render_clock_content(dc: HDC, width: u32, height: u32) {
304303
}
305304

306305
// Calculate total content height for vertical centering
307-
let time_height = (time_font_size * 1.3) as f32;
306+
let time_height = time_font_size * 1.3;
308307
let mut total_height = time_height;
309308

310309
if config.show_time_period {

src/settings.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ fn create_settings_controls(hwnd: HWND) {
240240
.encode_utf16()
241241
.chain(std::iter::once(0))
242242
.collect();
243-
let btn_style = WS_CHILD | WS_VISIBLE | WINDOW_STYLE(BS_PUSHBUTTON as u32);
243+
let btn_style = WS_CHILD | WS_VISIBLE | WINDOW_STYLE(BS_PUSHBUTTON);
244244
let _ = CreateWindowExW(
245245
WINDOW_EX_STYLE::default(),
246246
w!("BUTTON"),
@@ -293,6 +293,7 @@ fn create_settings_controls(hwnd: HWND) {
293293
}
294294

295295
/// Create a toggle button with ON/OFF indicator
296+
#[allow(clippy::too_many_arguments)]
296297
fn create_toggle_button(
297298
hwnd: HWND,
298299
instance: HINSTANCE,
@@ -313,7 +314,7 @@ fn create_toggle_button(
313314
WINDOW_EX_STYLE::default(),
314315
w!("BUTTON"),
315316
PCWSTR(text_wide.as_ptr()),
316-
WS_CHILD | WS_VISIBLE | WINDOW_STYLE(BS_PUSHBUTTON as u32 | BS_LEFT as u32),
317+
WS_CHILD | WS_VISIBLE | WINDOW_STYLE(BS_PUSHBUTTON | BS_LEFT),
317318
x,
318319
y,
319320
width,

0 commit comments

Comments
 (0)