feat(cache): add download_image_from_api with format conversion
Swadhin Biswas committed 7 months ago
f450829
1 parent 2c5b128
commit f450829
1 file changed
+50 -0
Showing 1 changed file+50-0
▼src/image_cache.rs
+50-0
| @@ -98,3 +98,53 @@ pub fn detect_and_use_wallpaper() -> Option<PathBuf> { | ||
98 | 98 | if let Ok(wallpaper_path) = std::env::var("WALLPAPER") { |
99 | 99 | let path = PathBuf::from(wallpaper_path); |
100 | 100 | if path.exists() { |
101 | + if let Ok(_) = copy_image_to_cache(&path) { | |
102 | + return Some(cached_image_path()); | |
103 | + } | |
104 | + } | |
105 | + } | |
106 | + | |
107 | + None | |
108 | +} | |
109 | + | |
110 | +/// Get Hyprland wallpaper (check hyprctl output and config files) | |
111 | +fn get_hyprland_wallpaper() -> Option<PathBuf> { | |
112 | + // Try hyprctl command first | |
113 | + if let Ok(output) = Command::new("hyprctl") | |
114 | + .args(&["hyprpaper", "wallpapers"]) | |
115 | + .output() | |
116 | + { | |
117 | + if let Ok(stdout) = String::from_utf8(output.stdout) { | |
118 | + for line in stdout.lines() { | |
119 | + let path = line.trim(); | |
120 | + let file_path = PathBuf::from(path); | |
121 | + if file_path.exists() && is_image_file(&file_path) { | |
122 | + return Some(file_path); | |
123 | + } | |
124 | + } | |
125 | + } | |
126 | + } | |
127 | + | |
128 | + // Try hyprpaper config | |
129 | + let hyprpaper_config = dirs::config_dir() | |
130 | + .map(|d| d.join("hypr/hyprpaper.conf"))?; | |
131 | + | |
132 | + if let Ok(content) = fs::read_to_string(&hyprpaper_config) { | |
133 | + for line in content.lines() { | |
134 | + if line.starts_with("preload") || line.starts_with("wallpaper") { | |
135 | + if let Some(path_str) = line.split('=').nth(1) { | |
136 | + let path_str = path_str.trim().trim_matches('"').trim_matches('\''); | |
137 | + let path = expand_path(path_str); | |
138 | + if path.exists() && is_image_file(&path) { | |
139 | + return Some(path); | |
140 | + } | |
141 | + } | |
142 | + } | |
143 | + } | |
144 | + } | |
145 | + | |
146 | + None | |
147 | +} | |
148 | + | |
149 | +/// Get GNOME wallpaper from dconf | |
150 | +fn get_gnome_wallpaper() -> Option<PathBuf> { | |
101 | 151 | |