60ab211
commit 60ab211
4 files changed
+44 -54
Showing 4 changed files+44-54
▼src/image_cache.rs
+13-17
| @@ -75,21 +75,21 @@ pub fn download_image_from_api() -> Result<(), Box<dyn std::error::Error>> { | ||
75 | 75 | pub fn detect_and_use_wallpaper() -> Option<PathBuf> { |
76 | 76 | // Try Hyprland wallpaper detection |
77 | 77 | if let Some(wallpaper) = get_hyprland_wallpaper() { |
78 | - if let Ok(_) = copy_image_to_cache(&wallpaper) { | |
78 | + if copy_image_to_cache(&wallpaper).is_ok() { | |
79 | 79 | return Some(cached_image_path()); |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Try GNOME wallpaper |
84 | 84 | if let Some(wallpaper) = get_gnome_wallpaper() { |
85 | - if let Ok(_) = copy_image_to_cache(&wallpaper) { | |
85 | + if copy_image_to_cache(&wallpaper).is_ok() { | |
86 | 86 | return Some(cached_image_path()); |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | 90 | // Try KDE wallpaper |
91 | 91 | if let Some(wallpaper) = get_kde_wallpaper() { |
92 | - if let Ok(_) = copy_image_to_cache(&wallpaper) { | |
92 | + if copy_image_to_cache(&wallpaper).is_ok() { | |
93 | 93 | return Some(cached_image_path()); |
94 | 94 | } |
95 | 95 | } |
| @@ -97,10 +97,8 @@ pub fn detect_and_use_wallpaper() -> Option<PathBuf> { | ||
97 | 97 | // Try from environment variable |
98 | 98 | if let Ok(wallpaper_path) = std::env::var("WALLPAPER") { |
99 | 99 | let path = PathBuf::from(wallpaper_path); |
100 | - if path.exists() { | |
101 | - if let Ok(_) = copy_image_to_cache(&path) { | |
102 | - return Some(cached_image_path()); | |
103 | - } | |
100 | + if path.exists() && copy_image_to_cache(&path).is_ok() { | |
101 | + return Some(cached_image_path()); | |
104 | 102 | } |
105 | 103 | } |
106 | 104 | |
| @@ -111,7 +109,7 @@ pub fn detect_and_use_wallpaper() -> Option<PathBuf> { | ||
111 | 109 | fn get_hyprland_wallpaper() -> Option<PathBuf> { |
112 | 110 | // Try hyprctl command first |
113 | 111 | if let Ok(output) = Command::new("hyprctl") |
114 | - .args(&["hyprpaper", "wallpapers"]) | |
112 | + .args(["hyprpaper", "wallpapers"]) | |
115 | 113 | .output() |
116 | 114 | { |
117 | 115 | if let Ok(stdout) = String::from_utf8(output.stdout) { |
| @@ -148,7 +146,7 @@ fn get_hyprland_wallpaper() -> Option<PathBuf> { | ||
148 | 146 | /// Get GNOME wallpaper from dconf |
149 | 147 | fn get_gnome_wallpaper() -> Option<PathBuf> { |
150 | 148 | let output = Command::new("dconf") |
151 | - .args(&["read", "/org/gnome/desktop/background/picture-uri-dark"]) | |
149 | + .args(["read", "/org/gnome/desktop/background/picture-uri-dark"]) | |
152 | 150 | .output() |
153 | 151 | .ok()?; |
154 | 152 | |
| @@ -198,7 +196,7 @@ fn copy_image_to_cache(source: &PathBuf) -> Result<(), Box<dyn std::error::Error | ||
198 | 196 | } |
199 | 197 | |
200 | 198 | /// Check if a file is likely an image |
201 | -fn is_image_file(path: &PathBuf) -> bool { | |
199 | +fn is_image_file(path: &std::path::Path) -> bool { | |
202 | 200 | let extensions = ["png", "jpg", "jpeg", "webp", "gif", "bmp"]; |
203 | 201 | if let Some(ext) = path |
204 | 202 | .extension() |
| @@ -255,13 +253,11 @@ pub fn detect_terminal_capabilities() -> TerminalCapabilities { | ||
255 | 253 | } |
256 | 254 | |
257 | 255 | // Check for sixel support |
258 | - if term.contains("xterm-kitty") || colorterm.contains("truecolor") { | |
259 | - if check_sixel_support() { | |
260 | - return TerminalCapabilities { | |
261 | - supports_graphics: true, | |
262 | - backend: "sixel".to_string(), | |
263 | - }; | |
264 | - } | |
256 | + if (term.contains("xterm-kitty") || colorterm.contains("truecolor")) && check_sixel_support() { | |
257 | + return TerminalCapabilities { | |
258 | + supports_graphics: true, | |
259 | + backend: "sixel".to_string(), | |
260 | + }; | |
265 | 261 | } |
266 | 262 | |
267 | 263 | // Check for w3m (X11) |
268 | 264 | |
▼src/main.rs
+14-16
| @@ -321,19 +321,17 @@ fn select_image_interactive() { | ||
321 | 321 | dirs::home_dir().map(|h| h.join("Desktop")), |
322 | 322 | ]; |
323 | 323 | |
324 | - for dir_opt in search_dirs { | |
325 | - if let Some(dir) = dir_opt { | |
326 | - if let Ok(entries) = fs::read_dir(&dir) { | |
327 | - for entry in entries.flatten() { | |
328 | - let path = entry.path(); | |
329 | - if let Some(ext) = path.extension().and_then(|e| e.to_str()) { | |
330 | - if matches!( | |
331 | - ext.to_lowercase().as_str(), | |
332 | - "png" | "jpg" | "jpeg" | "gif" | "webp" | "bmp" | |
333 | - ) { | |
334 | - if let Some(path_str) = path.to_str() { | |
335 | - image_paths.push(path_str.to_string()); | |
336 | - } | |
324 | + for dir in search_dirs.into_iter().flatten() { | |
325 | + if let Ok(entries) = fs::read_dir(&dir) { | |
326 | + for entry in entries.flatten() { | |
327 | + let path = entry.path(); | |
328 | + if let Some(ext) = path.extension().and_then(|e| e.to_str()) { | |
329 | + if matches!( | |
330 | + ext.to_lowercase().as_str(), | |
331 | + "png" | "jpg" | "jpeg" | "gif" | "webp" | "bmp" | |
332 | + ) { | |
333 | + if let Some(path_str) = path.to_str() { | |
334 | + image_paths.push(path_str.to_string()); | |
337 | 335 | } |
338 | 336 | } |
339 | 337 | } |
| @@ -534,16 +532,16 @@ fn init_api_image_config() { | ||
534 | 532 | match fs::write(&config_path, updated) { |
535 | 533 | Ok(_) => { |
536 | 534 | println!("✓ Config initialized with API image fetching!"); |
537 | - println!(""); | |
535 | + println!(); | |
538 | 536 | println!("Settings applied:"); |
539 | 537 | println!(" • image_backend = \"auto\" (terminal auto-detection)"); |
540 | 538 | println!(" • image_source = \"auto\" (API + smart 6-hour caching)"); |
541 | - println!(""); | |
539 | + println!(); | |
542 | 540 | println!("Next steps:"); |
543 | 541 | println!(" 1. Run 'fetch' to see API wallpaper"); |
544 | 542 | println!(" 2. Run 'fetch' again after a few seconds to see cached image"); |
545 | 543 | println!(" 3. First run downloads image in background without blocking"); |
546 | - println!(""); | |
544 | + println!(); | |
547 | 545 | println!("Cache location: ~/.cache/fetchx/current_image.png"); |
548 | 546 | } |
549 | 547 | Err(e) => { |
550 | 548 | |
▼src/system/mod.rs
+11-11
| @@ -471,7 +471,7 @@ fn get_shell() -> String { | ||
471 | 471 | return "Unknown".to_string(); |
472 | 472 | } |
473 | 473 | |
474 | - let shell_name = shell_path.split('/').last().unwrap_or("Unknown"); | |
474 | + let shell_name = shell_path.split('/').next_back().unwrap_or("Unknown"); | |
475 | 475 | |
476 | 476 | // Get version |
477 | 477 | let version = match shell_name { |
| @@ -573,7 +573,7 @@ fn get_resolution() -> String { | ||
573 | 573 | if found_monitor && trimmed.contains('@') && trimmed.contains('x') { |
574 | 574 | if let Some(res) = trimmed.split('@').next() { |
575 | 575 | let res = res.trim(); |
576 | - if res.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
576 | + if res.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
577 | 577 | resolutions.push(res.to_string()); |
578 | 578 | found_monitor = false; // Only first resolution per monitor |
579 | 579 | } |
| @@ -597,7 +597,7 @@ fn get_resolution() -> String { | ||
597 | 597 | // Find resolution pattern like "1920x1080+0+0" |
598 | 598 | for word in line.split_whitespace() { |
599 | 599 | if word.contains('x') |
600 | - && word.chars().next().map_or(false, |c| c.is_ascii_digit()) | |
600 | + && word.chars().next().is_some_and(|c| c.is_ascii_digit()) | |
601 | 601 | { |
602 | 602 | let res = word.split('+').next().unwrap_or(word); |
603 | 603 | resolutions.push(res.to_string()); |
| @@ -686,7 +686,7 @@ fn get_de_version(de: &str) -> String { | ||
686 | 686 | let out = run_cmd("gnome-shell", &["--version"]); |
687 | 687 | // "GNOME Shell 45.2" → "45.2" |
688 | 688 | if let Some(v) = out.split_whitespace().last() { |
689 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
689 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
690 | 690 | return v.to_string(); |
691 | 691 | } |
692 | 692 | } |
| @@ -695,7 +695,7 @@ fn get_de_version(de: &str) -> String { | ||
695 | 695 | let out = run_cmd("plasmashell", &["--version"]); |
696 | 696 | // "plasmashell 5.27.10" or "plasmashell 6.0.2" |
697 | 697 | if let Some(v) = out.split_whitespace().last() { |
698 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
698 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
699 | 699 | return v.to_string(); |
700 | 700 | } |
701 | 701 | } |
| @@ -705,7 +705,7 @@ fn get_de_version(de: &str) -> String { | ||
705 | 705 | for line in out.lines() { |
706 | 706 | if line.contains("xfce4-session") || line.contains("xfce") { |
707 | 707 | if let Some(v) = line.split_whitespace().last() { |
708 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
708 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
709 | 709 | return v.to_string(); |
710 | 710 | } |
711 | 711 | } |
| @@ -715,7 +715,7 @@ fn get_de_version(de: &str) -> String { | ||
715 | 715 | if de_lower.contains("cinnamon") { |
716 | 716 | let out = run_cmd("cinnamon", &["--version"]); |
717 | 717 | if let Some(v) = out.split_whitespace().last() { |
718 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
718 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
719 | 719 | return v.to_string(); |
720 | 720 | } |
721 | 721 | } |
| @@ -723,7 +723,7 @@ fn get_de_version(de: &str) -> String { | ||
723 | 723 | if de_lower.contains("mate") { |
724 | 724 | let out = run_cmd("mate-session", &["--version"]); |
725 | 725 | if let Some(v) = out.split_whitespace().last() { |
726 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
726 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
727 | 727 | return v.to_string(); |
728 | 728 | } |
729 | 729 | } |
| @@ -731,7 +731,7 @@ fn get_de_version(de: &str) -> String { | ||
731 | 731 | if de_lower.contains("lxqt") { |
732 | 732 | let out = run_cmd("lxqt-about", &["--version"]); |
733 | 733 | if let Some(v) = out.split_whitespace().last() { |
734 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
734 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
735 | 735 | return v.to_string(); |
736 | 736 | } |
737 | 737 | } |
| @@ -739,7 +739,7 @@ fn get_de_version(de: &str) -> String { | ||
739 | 739 | if de_lower.contains("budgie") { |
740 | 740 | let out = run_cmd("budgie-desktop", &["--version"]); |
741 | 741 | if let Some(v) = out.split_whitespace().last() { |
742 | - if v.chars().next().map_or(false, |c| c.is_ascii_digit()) { | |
742 | + if v.chars().next().is_some_and(|c| c.is_ascii_digit()) { | |
743 | 743 | return v.to_string(); |
744 | 744 | } |
745 | 745 | } |
| @@ -993,7 +993,7 @@ fn get_term_font() -> String { | ||
993 | 993 | let profile_dir = format!("{}/.local/share/konsole", crate::utils::home_dir()); |
994 | 994 | if let Ok(entries) = std::fs::read_dir(&profile_dir) { |
995 | 995 | for entry in entries.flatten() { |
996 | - if entry.path().extension().map_or(false, |e| e == "profile") { | |
996 | + if entry.path().extension().is_some_and(|e| e == "profile") { | |
997 | 997 | let content = read_file(entry.path().to_str().unwrap_or("")); |
998 | 998 | for line in content.lines() { |
999 | 999 | if let Some(val) = line.strip_prefix("Font=") { |
1000 | 1000 | |
▼src/utils/mod.rs
+6-10
| @@ -85,11 +85,9 @@ pub fn strip_ansi(s: &str) -> String { | ||
85 | 85 | if c == '\x07' { |
86 | 86 | break; // BEL terminator |
87 | 87 | } |
88 | - if c == '\x1b' { | |
89 | - if chars.peek() == Some(&'\\') { | |
90 | - chars.next(); // consume '\\' | |
91 | - break; | |
92 | - } | |
88 | + if c == '\x1b' && chars.peek() == Some(&'\\') { | |
89 | + chars.next(); // consume '\\' | |
90 | + break; | |
93 | 91 | } |
94 | 92 | } |
95 | 93 | } |
| @@ -154,11 +152,9 @@ pub fn truncate_to_width(s: &str, max_width: usize) -> String { | ||
154 | 152 | if c == '\x07' { |
155 | 153 | break; |
156 | 154 | } |
157 | - if c == '\x1b' { | |
158 | - if chars.peek() == Some(&'\\') { | |
159 | - result.push(chars.next().unwrap()); | |
160 | - break; | |
161 | - } | |
155 | + if c == '\x1b' && chars.peek() == Some(&'\\') { | |
156 | + result.push(chars.next().unwrap()); | |
157 | + break; | |
162 | 158 | } |
163 | 159 | } |
164 | 160 | } |
165 | 161 | |