Skip to content
This repository was archived by the owner on Jan 25, 2026. It is now read-only.

Commit a011cf5

Browse files
committed
♻️ refactor(pages): extract format_size function
- remove the inline format_size function for better reusability - import the format_size utility from utils instead - ensure correct handling of format_size return type in init function
1 parent 337fb22 commit a011cf5

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

src/pages/everysup.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use crate::slint_generated::{MainWindow, AppLogic};
88
use crate::pages::features::FileSearcher;
9+
use crate::utils::format_size;
910
use slint::{ComponentHandle, Weak};
1011
use parking_lot::Mutex;
1112
use chrono;
@@ -14,21 +15,6 @@ use std::sync::atomic::{AtomicBool, Ordering};
1415
use std::sync::Arc;
1516
use std::thread;
1617

17-
fn format_size(size: u64) -> String {
18-
const KB: u64 = 1024;
19-
const MB: u64 = KB * 1024;
20-
const GB: u64 = MB * 1024;
21-
22-
if size >= GB {
23-
format!("{:.1} GB", size as f64 / GB as f64)
24-
} else if size >= MB {
25-
format!("{:.1} MB", size as f64 / MB as f64)
26-
} else if size >= KB {
27-
format!("{:.1} KB", size as f64 / KB as f64)
28-
} else {
29-
format!("{} B", size)
30-
}
31-
}
3218

3319
// fn init_searcher(window: &Weak<MainWindow>) -> Arc<FileSearcher> {
3420
// println!("=== Initialisation du moteur de recherche ===");
@@ -123,7 +109,7 @@ pub fn init(window: &Weak<MainWindow>) {
123109

124110
{
125111
let (ref last_value, ref last_time) = *last_query.lock();
126-
if now.duration_since(*last_time) < Duration::from_millis(20)
112+
if now.duration_since(*last_time) < Duration::from_millis(1)
127113
|| value_string == *last_value {
128114
return;
129115
}
@@ -152,7 +138,7 @@ pub fn init(window: &Weak<MainWindow>) {
152138
let row = vec![
153139
result.name,
154140
result.path,
155-
format_size(result.size),
141+
format_size(result.size).to_string(),
156142
if result.is_dir { "Folder".into() } else { "File".into() },
157143
format_time(result.modified),
158144
];

0 commit comments

Comments
 (0)