gardesk/garfield / cb20d1a

Browse files

ui: add mounted volumes detection to sidebar

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
cb20d1a4516ca4538e6369eabf0ddd80fd0a0016
Parents
a7977df
Tree
746a1f5

1 changed file

StatusFile+-
M garfield/src/ui/sidebar.rs 53 0
garfield/src/ui/sidebar.rsmodified
@@ -173,6 +173,59 @@ impl Sidebar {
173
                 });
173
                 });
174
             }
174
             }
175
         }
175
         }
176
+
177
+        // Mounted volumes
178
+        self.add_mounted_volumes();
179
+    }
180
+
181
+    /// Add mounted volumes from common mount points.
182
+    fn add_mounted_volumes(&mut self) {
183
+        let mount_points = [
184
+            PathBuf::from("/media"),
185
+            PathBuf::from("/mnt"),
186
+        ];
187
+
188
+        // Also check /run/media/$USER for modern systems
189
+        if let Ok(username) = std::env::var("USER") {
190
+            let user_media = PathBuf::from(format!("/run/media/{}", username));
191
+            if user_media.exists() {
192
+                self.scan_mount_point(&user_media);
193
+            }
194
+        }
195
+
196
+        for mount_point in &mount_points {
197
+            if mount_point.exists() {
198
+                self.scan_mount_point(mount_point);
199
+            }
200
+        }
201
+    }
202
+
203
+    /// Scan a mount point directory for mounted volumes.
204
+    fn scan_mount_point(&mut self, mount_point: &Path) {
205
+        if let Ok(entries) = fs::read_dir(mount_point) {
206
+            for entry in entries.filter_map(|e| e.ok()) {
207
+                let path = entry.path();
208
+                if path.is_dir() {
209
+                    let name = path
210
+                        .file_name()
211
+                        .map(|s| s.to_string_lossy().to_string())
212
+                        .unwrap_or_else(|| "Volume".to_string());
213
+
214
+                    // Skip if already in places (avoid duplicates)
215
+                    if self.places.iter().any(|p| p.path == path) {
216
+                        continue;
217
+                    }
218
+
219
+                    self.places.push(Place {
220
+                        name,
221
+                        icon: "#".to_string(), // Volume/drive icon
222
+                        path,
223
+                        bounds: Rect::new(0, 0, 0, 0),
224
+                        is_bookmark: false,
225
+                    });
226
+                }
227
+            }
228
+        }
176
     }
229
     }
177
 
230
 
178
     /// Load bookmarks from config file.
231
     /// Load bookmarks from config file.