Skip to content

Commit

Permalink
Load system disks
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxcode committed Jan 21, 2024
1 parent f3abdfe commit 5025215
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ egui = "0.25.0"

# Used to fetch user folders
directories = "5.0"

# Used to fetch disks
sysinfo = { version = "0.30.5", default-features = false }
27 changes: 23 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ use std::{fs, io};
use std::path::{Path, PathBuf};

use directories::UserDirs;
use sysinfo::Disks;

pub struct FileExplorer {
user_directories: Option<UserDirs>,
system_disks: Disks,

directory_stack: Vec<PathBuf>,
directory_offset: usize,
directory_content: Vec<PathBuf>,

selected_item: Option<PathBuf>,
search_value: String
}
Expand All @@ -22,9 +26,12 @@ impl FileExplorer {
pub fn new() -> Self {
FileExplorer {
user_directories: UserDirs::new(),
system_disks: Disks::new_with_refreshed_list(),

directory_stack: vec![],
directory_offset: 0,
directory_content: vec![],

selected_item: None,
search_value: String::new()
}
Expand Down Expand Up @@ -158,10 +165,22 @@ impl FileExplorer {

ui.label("Devices");

let _ = ui.selectable_label(false, "🖴 (C:)");
let _ = ui.selectable_label(false, "🖴 Toshiba(D:)");
let _ = ui.selectable_label(false, "🖴 Samsung 980..(E:)");
let _ = ui.selectable_label(false, "🖴 (F:)");
let disks = std::mem::take(&mut self.system_disks);

for disk in &disks {
// TODO: Get display name of the devices.
// Currently on linux "/dev/sda1" is returned.
let name = match disk.name().to_str() {
Some(x) => x,
None => continue
};

if ui.selectable_label(false, format!("🖴 {}", name)).clicked() {
let _ = self.load_directory(disk.mount_point());
}
}

self.system_disks = disks;
}

fn update_bottom_panel(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
Expand Down

0 comments on commit 5025215

Please sign in to comment.