Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

.yarn
node_modules
dist
dist-ssr
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "file-explorer"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
version = "1.0.0"
description = "File Explorer"
authors = ["Conaticus", "ProtogenDelta", ]
license = ""
repository = ""
edition = "2021"
Expand Down
31 changes: 14 additions & 17 deletions src-tauri/src/filesystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,24 @@ pub const fn bytes_to_gb(bytes: u64) -> u16 {

/// Searches and returns the files in a given directory. This is not recursive.
#[tauri::command]
pub fn open_directory(path: String) -> Vec<DirectoryChild> {
let mut dir_children = Vec::new();

pub async fn open_directory(path: String) -> Result<Vec<DirectoryChild>, ()> {
let Ok(directory) = read_dir(path) else {
return dir_children;
return Ok(Vec::new());
};

for entry in directory {
let entry = entry.unwrap();

let file_name = entry.file_name().to_str().unwrap().to_string();
let entry_is_file = entry.file_type().unwrap().is_file();
let entry = entry.path().to_str().unwrap().to_string();
Ok(directory
.map(|entry| {
let entry = entry.unwrap();

if entry_is_file {
dir_children.push(DirectoryChild::File(file_name, entry));
continue;
}
let file_name = entry.file_name().to_string_lossy().to_string();
let entry_is_file = entry.file_type().unwrap().is_file();
let entry = entry.path().to_string_lossy().to_string();

dir_children.push(DirectoryChild::Directory(file_name, entry));
}
if entry_is_file {
return DirectoryChild::File(file_name, entry);
}

dir_children
DirectoryChild::Directory(file_name, entry)
})
.collect())
}
84 changes: 14 additions & 70 deletions src-tauri/src/filesystem/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,6 @@ pub struct Volume {
available_gb: u16,
used_gb: u16,
total_gb: u16,
fs: VolumeFileSystem,
}

#[derive(Serialize)]
pub struct VolumeFileSystem {
root: PathBuf,
documents: PathBuf,
downloads: PathBuf,
pictures: PathBuf,
videos: PathBuf,
home: PathBuf,
audio: PathBuf,
desktop: PathBuf,
}

impl VolumeFileSystem {
fn try_new() -> Result<Self, ()> {
macro_rules! handle_err {
($func:expr) => {
match $func {
Some(dir) => dir,
None => return Err(()),
}
};
}

let documents = handle_err!(dirs::document_dir());
let downloads = handle_err!(dirs::download_dir());
let pictures = handle_err!(dirs::picture_dir());
let videos = handle_err!(dirs::video_dir());
let home = handle_err!(dirs::home_dir());
let audio = handle_err!(dirs::audio_dir());
let desktop = handle_err!(dirs::desktop_dir());
let root: PathBuf = {
#[cfg(target_family = "unix")]
{
"/".into()
}
#[cfg(target_family = "windows")]
{
"C:".into()
}
};

Ok(Self {
root,
documents,
downloads,
pictures,
videos,
home,
audio,
desktop,
})
}
}

impl Volume {
Expand All @@ -98,14 +43,11 @@ impl Volume {

let mountpoint = disk.mount_point().to_path_buf();

let fs = VolumeFileSystem::try_new().unwrap();

Self {
name,
available_gb,
used_gb,
total_gb,
fs,
mountpoint,
}
}
Expand Down Expand Up @@ -179,9 +121,7 @@ pub enum DirectoryChild {
/// If there is a cache stored on volume it is loaded.
/// If there is no cache stored on volume, one is created as well as stored in memory.
#[tauri::command]
pub fn get_volumes(state_mux: State<StateSafe>) -> Vec<Volume> {
let mut volumes = Vec::new();

pub async fn get_volumes(state_mux: State<'_, StateSafe>) -> Result<Vec<Volume>, ()> {
let mut sys = System::new_all();
sys.refresh_all();

Expand All @@ -192,19 +132,23 @@ pub fn get_volumes(state_mux: State<StateSafe>) -> Vec<Volume> {
File::create(&CACHE_FILE_PATH[..]).unwrap();
}

for disk in sys.disks() {
let volume = Volume::from(disk);
let volumes = sys
.disks()
.iter()
.map(|disk| {
let volume = Volume::from(disk);

if !cache_exists {
volume.create_cache(&state_mux);
}
if !cache_exists {
volume.create_cache(&state_mux);
}

volume.watch_changes(&state_mux);
volumes.push(volume);
}
volume.watch_changes(&state_mux);
volume
})
.collect();

save_system_cache(&state_mux);
run_cache_interval(&state_mux);

volumes
Ok(volumes)
}
10 changes: 5 additions & 5 deletions src-tauri/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ fn check_file(
/// Takes into account the filters provided.
/// Returns the results ONLY when the entire volume is searched
#[tauri::command]
pub fn search_directory(
state_mux: State<StateSafe>,
pub async fn search_directory(
state_mux: State<'_, StateSafe>,
query: String,
search_directory: String,
mount_pnt: String,
extension: String,
accept_files: bool,
accept_directories: bool,
) -> Vec<DirectoryChild> {
) -> Result<Vec<DirectoryChild>, ()> {
let start_time = Instant::now();

let mut results: Vec<_> = Vec::new();
Expand Down Expand Up @@ -131,8 +131,8 @@ pub fn search_directory(
let mut tuples: Vec<(usize, _)> = fuzzy_scores.iter().enumerate().collect();
tuples.sort_by(|a, b| b.1.cmp(a.1));

tuples
Ok(tuples
.into_iter()
.map(|(index, _)| results[index].clone())
.collect()
.collect())
}
7 changes: 7 additions & 0 deletions src/components/MainBody/Util/LoadingPlaceholder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function LoadingPlaceholder() {
return (
<div>
<h2>Loading...</h2>
</div>
)
}
4 changes: 3 additions & 1 deletion src/components/MainBody/Volumes/VolumeList.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import VolumeComponent from "./VolumeComponent";
import {Volume} from "../../../types";
import LoadingPlaceholder from "../Util/LoadingPlaceholder";

interface Props {
volumes: Volume[];
onClick: (mountpoint: string) => any;
}

export default function VolumeList({ volumes, onClick }: Props) {
console.log(volumes)
return (
<div className="space-x-4">
{volumes.map((volume, idx) => (
{volumes.length == 0 ? <LoadingPlaceholder/> : volumes.map((volume, idx) => (
<VolumeComponent
onClick={() => onClick(volume.mountpoint)}
volume={volume}
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ h3 {
@apply text-2xl font-bold;
}

h2 {
@apply text-3xl font-bold;
}

progress[value] {
background-color: blue;
}
Loading