Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds FileType enum #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
"@tauri-apps/api": "^1.3.0",
"@types/react-redux": "^7.1.25",
"autoprefixer": "^10.4.14",
"lodash": "^4.17.21",
"postcss": "^8.4.24",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.1.1",
"tailwindcss": "^3.3.2",
"lodash": "^4.17.21"
"tailwindcss": "^3.3.2"
},
"devDependencies": {
"@types/lodash": "^4.14.195",
"@tauri-apps/cli": "^1.3.1",
"@types/lodash": "^4.14.195",
"@types/node": "^18.7.10",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
Expand Down
33 changes: 17 additions & 16 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ zstd = "0.12.3"
lazy_static = "1.4.0"
open = "5.0.0"
thiserror = "1.0.40"
serde_repr = "0.1.14"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
13 changes: 6 additions & 7 deletions src-tauri/src/filesystem/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::filesystem::{DIRECTORY, FILE};
use crate::filesystem::FileType;
use crate::{AppState, CachedPath, StateSafe, VolumeCache};
use lazy_static::lazy_static;
use notify::event::{CreateKind, ModifyKind, RenameMode};
Expand Down Expand Up @@ -50,11 +50,10 @@ impl FsEventHandler {

let filename = path.file_name().unwrap().to_string_lossy().to_string();
let file_type = match kind {
CreateKind::File => FILE,
CreateKind::Folder => DIRECTORY,
CreateKind::File => FileType::File,
CreateKind::Folder => FileType::Directory,
_ => return, // Other options are weird lol
}
.to_string();
};

let file_path = path.to_string_lossy().to_string();
current_volume.entry(filename).or_insert_with(|| vec![CachedPath {
Expand Down Expand Up @@ -97,12 +96,12 @@ impl FsEventHandler {
let current_volume = self.get_from_cache(state);

let filename = new_path.file_name().unwrap().to_string_lossy().to_string();
let file_type = if new_path.is_dir() { DIRECTORY } else { FILE };
let file_type = if new_path.is_dir() { FileType::Directory } else { FileType::File };

let path_string = new_path.to_string_lossy().to_string();
current_volume.entry(filename).or_insert_with(|| vec![CachedPath {
file_path: path_string,
file_type: String::from(file_type),
file_type: file_type,
}]);
}

Expand Down
3 changes: 1 addition & 2 deletions src-tauri/src/filesystem/explorer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::fs;
use std::fs::read_dir;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::path::Path;
use notify::event::CreateKind;
use tauri::State;
use crate::errors::Error;
use crate::filesystem::cache::FsEventHandler;
use crate::filesystem::fs_utils;
use crate::filesystem::fs_utils::get_mount_point;
use crate::filesystem::volume::DirectoryChild;
use crate::StateSafe;
Expand Down
10 changes: 8 additions & 2 deletions src-tauri/src/filesystem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use serde_repr::{Serialize_repr, Deserialize_repr};

pub mod explorer;
pub mod cache;
pub mod volume;
mod fs_utils;

pub const DIRECTORY: &str = "directory";
pub const FILE: &str = "file";
#[derive(Serialize_repr, Deserialize_repr, PartialEq)]
#[repr(u8)]
pub enum FileType{
Directory,
File
}

pub const fn bytes_to_gb(bytes: u64) -> u16 {
(bytes / (1e+9 as u64)) as u16
Expand Down
9 changes: 4 additions & 5 deletions src-tauri/src/filesystem/volume.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::filesystem::cache::{
load_system_cache, run_cache_interval, save_system_cache, FsEventHandler, CACHE_FILE_PATH,
};
use crate::filesystem::{bytes_to_gb, DIRECTORY, FILE};
use crate::filesystem::{bytes_to_gb, FileType};
use crate::{CachedPath, StateSafe};
use notify::{RecursiveMode, Watcher};
use rayon::prelude::*;
Expand Down Expand Up @@ -73,11 +73,10 @@ impl Volume {

let walkdir_filetype = entry.file_type();
let file_type = if walkdir_filetype.is_dir() {
DIRECTORY
FileType::Directory
} else {
FILE
}
.to_string();
FileType::File
};

let cache_guard = &mut system_cache.lock().unwrap();
cache_guard
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod filesystem;
mod search;
mod errors;

use filesystem::FileType;
use filesystem::explorer::{open_file, open_directory, create_file, create_directory, rename_file, delete_file};
use filesystem::volume::get_volumes;
use search::search_directory;
Expand All @@ -17,7 +18,7 @@ pub struct CachedPath {
#[serde(rename = "p")]
file_path: String,
#[serde(rename = "t")]
file_type: String,
file_type: FileType,
}

pub type VolumeCache = HashMap<String, Vec<CachedPath>>;
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/search.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::filesystem::volume::DirectoryChild;
use crate::filesystem::FileType;
use crate::StateSafe;
use fuzzy_matcher::skim::SkimMatcherV2;
use fuzzy_matcher::FuzzyMatcher;
Expand Down Expand Up @@ -92,7 +93,7 @@ pub async fn search_directory(
continue;
}

if file_type == "file" {
if *file_type == FileType::File {
check_file(
&matcher,
accept_files,
Expand Down
Loading