From ced31c7ea052d4cc1719f487d3949fc9efb8c1de Mon Sep 17 00:00:00 2001 From: Ricky Dane Date: Sun, 21 Jan 2024 17:07:49 +0100 Subject: [PATCH 1/2] some tweaks --- src-tauri/Cargo.lock | 129 +++++++++++++++++++++++++++++++++++++++++ src-tauri/Cargo.toml | 2 + src-tauri/src/main.rs | 46 ++++++++------- src-tauri/src/utils.rs | 6 +- ui/main_logic.js | 43 ++++++++------ ui/style.css | 8 +-- 6 files changed, 192 insertions(+), 42 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 273e7eb..778e897 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2,6 +2,22 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ab_glyph" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80179d7dd5d7e8c285d67c4a1e652972a92de7475beddfb92028c76463b13225" +dependencies = [ + "ab_glyph_rasterizer", + "owned_ttf_parser", +] + +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" + [[package]] name = "addr2line" version = "0.21.0" @@ -28,6 +44,18 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "ahash" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", + "version_check 0.9.4", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "0.5.3" @@ -90,9 +118,11 @@ dependencies = [ "async_ftp", "base64 0.21.7", "chrono 0.4.31", + "color-print", "copy_dir", "dateparser", "dialog", + "egui", "ftp", "get_sys_info", "lazy_static 1.4.0", @@ -694,6 +724,27 @@ dependencies = [ "objc", ] +[[package]] +name = "color-print" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a858372ff14bab9b1b30ea504f2a4bc534582aee3e42ba2d41d2a7baba63d5d" +dependencies = [ + "color-print-proc-macro", +] + +[[package]] +name = "color-print-proc-macro" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e37866456a721d0a404439a1adae37a31be4e0055590d053dfe6981e05003f" +dependencies = [ + "nom 7.1.3", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -1063,12 +1114,35 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +[[package]] +name = "ecolor" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57539aabcdbb733b6806ef421b66dec158dc1582107ad6d51913db3600303354" + +[[package]] +name = "egui" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0bf640ed7f3bf3d14ebf00d73bacc09c886443ee84ca6494bde37953012c9e3" +dependencies = [ + "ahash", + "epaint", + "nohash-hasher", +] + [[package]] name = "either" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "emath" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ee58355767587db7ba3738930d93cad3052cd834c2b48b9ef6ef26fe4823b7e" + [[package]] name = "embed-resource" version = "2.4.1" @@ -1098,6 +1172,20 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "epaint" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e638cb066bff0903bbb6143116cfd134a42279c7d68f19c0352a94f15a402de7" +dependencies = [ + "ab_glyph", + "ahash", + "ecolor", + "emath", + "nohash-hasher", + "parking_lot", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -2355,6 +2443,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + [[package]] name = "nom" version = "4.2.3" @@ -2601,6 +2695,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "owned_ttf_parser" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4586edfe4c648c71797a74c84bacb32b52b212eff5dfe2bb9f2c599844023e7" +dependencies = [ + "ttf-parser", +] + [[package]] name = "pango" version = "0.15.10" @@ -4476,6 +4579,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "ttf-parser" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" + [[package]] name = "typenum" version = "1.17.0" @@ -5307,6 +5416,26 @@ dependencies = [ "rustix 0.38.30", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zip" version = "0.6.6" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 1c96ddc..9ca1d67 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -35,6 +35,8 @@ lazy_static = "1.4.0" ftp = "3.0.1" async-std = "1.10.0" sysinfo = "0.30.5" +color-print = "0.3.5" +egui = "0.25.0" [features] # this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled. diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 831e5b0..58d32dd 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -6,7 +6,7 @@ use std::io::{BufRead, BufReader, BufWriter, Error, ErrorKind, Write, Read}; use std::fs::{self, ReadDir}; #[allow(unused_imports)] use async_std::io::Cursor; -use rust_search::SearchBuilder; +use rust_search::{SearchBuilder, similarity_sort}; use serde_json::Value; use tauri::{api::path::{home_dir, picture_dir, download_dir, desktop_dir, video_dir, audio_dir, document_dir, app_config_dir, config_dir}, Config}; use stopwatch::Stopwatch; @@ -24,7 +24,7 @@ use async_ftp::types::FileType::{Ascii, Binary, Ebcdic, Image, Local}; #[allow(unused_imports)] use async_ftp::FtpError; mod utils; -use utils::{dbg_log, err_log}; +use utils::{dbg_log, err_log, wng_log}; use sysinfo::{Components, Disks, Networks}; static mut HOSTNAME: String = String::new(); @@ -565,10 +565,10 @@ async fn get_current_connection() -> FtpStream { #[tauri::command] async fn open_in_terminal() { #[cfg(target_os = "linux")] - // Open the terminal on linux pc + // Open the terminal on linux let _ = Command::new("gnome-terminal").arg(current_dir().unwrap()).spawn(); #[cfg(target_os = "windows")] - // Open the terminal on windows pc + // Open the terminal on windows let _ = Command::new("cmd").arg("/c").arg("start").arg(current_dir().unwrap()).spawn(); #[cfg(target_os = "macos")] // Open the terminal on mac @@ -584,14 +584,15 @@ async fn go_home() -> Vec { #[tauri::command] async fn search_for(file_name: String, max_items: i32, search_depth: i32, file_content: String) -> Vec { let mut file_ext = ".".to_string().to_owned()+file_name.split(".").nth(file_name.split(".").count() - 1).unwrap_or(""); + println!(""); dbg_log(format!("Start searching for {} - {}", &file_name.strip_suffix(&file_ext).unwrap_or(&file_name), &file_ext)); let sw = Stopwatch::start_new(); - let search: Vec; + let mut search: Vec; if file_ext != ".".to_string().to_owned()+&file_name { dbg_log(format!("{}{}", &file_name, &file_ext)); search = SearchBuilder::default() .location(current_dir().unwrap()) - .search_input(file_name.strip_suffix(&file_ext).unwrap()) + .search_input(*&file_name.strip_suffix(&file_ext).unwrap()) .ignore_case( ) .depth(search_depth.clone() as usize) .ext(&file_ext) @@ -603,7 +604,7 @@ async fn search_for(file_name: String, max_items: i32, search_depth: i32, file_c else { search = SearchBuilder::default() .location(current_dir().unwrap()) - .search_input(file_name) + .search_input(&file_name) .ignore_case() .depth(search_depth as usize) .hidden() @@ -611,6 +612,12 @@ async fn search_for(file_name: String, max_items: i32, search_depth: i32, file_c .build() .collect(); } + + // Sorting search results by input + let sw2 = Stopwatch::start_new(); + similarity_sort(&mut search, &file_name); + dbg_log(format!("Sorting took: {:?}", sw2.elapsed())); + let mut dir_list: Vec = Vec::new(); for item in search { file_ext = ".".to_string().to_owned()+item.split(".").nth(item.split(".").count() - 1).unwrap_or(""); @@ -621,28 +628,24 @@ async fn search_for(file_name: String, max_items: i32, search_depth: i32, file_c let temp_file = fs::metadata(&item); let file_size: String; let file_date: DateTime; + if &temp_file.is_ok() == &true { file_size = String::from(fs::metadata(&item).unwrap().len().to_string()); file_date = fs::metadata(&item).unwrap().modified().unwrap().clone().into(); } else { - file_size = "0".to_string(); - file_date = TimeZone::from_utc_datetime(&Utc, &NaiveDateTime::from_timestamp_opt(61, 0).unwrap()); - } - let is_dir: bool; - if &temp_file.is_ok() == &true { - is_dir = *&temp_file.unwrap().is_dir(); - } - else { - is_dir = false; + continue; } + + // Check if the item is a directory let is_dir_int; - if is_dir.to_owned() { + if &temp_file.is_ok() == &true && *&temp_file.unwrap().is_dir() { is_dir_int = 1; } else { is_dir_int = 0; } + // Don't include the directory searched in if path == current_dir().unwrap().to_str().unwrap() { continue; @@ -652,7 +655,7 @@ async fn search_for(file_name: String, max_items: i32, search_depth: i32, file_c if &file_content != "" { let file = fs::File::open(&path).unwrap(); let mut reader = BufReader::new(&file); - let mut contents: String = "".to_string(); + let mut contents = String::from(""); dbg_log(format!("Checking {}", &path)); if &file.metadata().unwrap().is_dir() == &false { @@ -688,7 +691,10 @@ async fn search_for(file_name: String, max_items: i32, search_depth: i32, file_c }); } } - dbg_log(format!("{}", sw.elapsed_ms())); + if dir_list.len() == 0 { + wng_log("No item found ".into()); + } + dbg_log(format!("Search took: {:?}", sw.elapsed())); dbg_log(format!("{} items found", dir_list.len())); return dir_list; } @@ -828,7 +834,7 @@ async fn extract_item(from_path: String) -> Vec { #[tauri::command] async fn open_item(path: String) { - dbg_log(format!("{}", &path)); + dbg_log(format!("Opening: {}", &path)); let _ = open::that_detached(path); } diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 29fbb2e..52f9bac 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -1,8 +1,12 @@ use chrono::prelude::*; +use color_print::cprintln; pub fn dbg_log(msg: String) { println!("[{:?} DBG] {}", Local::now().format("%H:%M:%S").to_string(), msg); } +pub fn wng_log(msg: String) { + cprintln!("[{:?} WNG] {}", Local::now().format("%H:%M:%S").to_string(), msg); +} pub fn err_log(msg: String) { - eprintln!("[{:?} ERR] {}", Local::now().format("%H:%M:%S").to_string(), msg); + cprintln!("[{:?} ERR] {}", Local::now().format("%H:%M:%S").to_string(), msg); } \ No newline at end of file diff --git a/ui/main_logic.js b/ui/main_logic.js index 6e88688..7a0746d 100644 --- a/ui/main_logic.js +++ b/ui/main_logic.js @@ -116,15 +116,18 @@ document.addEventListener("keyup", (e) => { if (e.keyCode === 27) { // Close all popups etc. ContextMenu.style.display = "none"; - closeSearchBar(); - closeSettings(); - closeInputDialog(); - closeFullSearchContainer(); - closeFtpConfig(); - closeInputPopup(); + closeAllPopups(); } }); +function closeAllPopups() { + closeSearchBar(); + closeSettings(); + closeInputDialog(); + closeFullSearchContainer(); + closeFtpConfig(); + closeInputPopup(); +} // Close context menu or new folder input dialog when click elsewhere document.addEventListener("mousedown", (e) => { @@ -166,6 +169,7 @@ document.addEventListener("mousedown", (e) => { ContextMenu.children[7].classList.add("c-item-disabled"); ContextMenu.children[8].setAttribute("disabled", "true"); ContextMenu.children[8].classList.add("c-item-disabled"); + closeAllPopups(); } }); @@ -330,18 +334,12 @@ document.onkeydown = async (e) => { renameElementInputPrompt(null, SelectedElement); } if (IsPopUpOpen == false) { - // check if alt + f7 is pressed + // check if f8 is pressed if (e.keyCode == 119) { openFullSearchContainer(); e.preventDefault(); e.stopPropagation(); } - // check if strg + f is pressed - if (e.ctrlKey && e.keyCode == 70) { - openSearchBar(); - e.preventDefault(); - e.stopPropagation(); - } } } @@ -352,6 +350,11 @@ document.onkeydown = async (e) => { e.stopPropagation(); } + // check if ctrl + v is pressed + if (e.ctrlKey && e.key == "v") { + pasteItem(); + } + if (IsPopUpOpen == false) { // check if ctrl + g is pressed | Path input if (e.ctrlKey && e.key == "g") { @@ -373,6 +376,13 @@ document.onkeydown = async (e) => { e.preventDefault(); e.stopPropagation(); } + + // check if strg + f is pressed + if (e.ctrlKey && e.keyCode == 70) { + openSearchBar(); + e.preventDefault(); + e.stopPropagation(); + } } } @@ -839,7 +849,7 @@ function showInputPopup(msg) { let popup = document.createElement("div"); popup.innerHTML = `

${msg}

- + `; popup.className = "input-popup" popup.children[1].addEventListener("keyup", async (e) => { @@ -1492,9 +1502,8 @@ document.querySelector(".dualpane-search-input").addEventListener("keyup", (e) = if (e.keyCode === 13) { closeSearchBar(); } - else if (IsQuickSearchOpen == true) { - let fileName = document.querySelector(".dualpane-search-input").value; - searchFor(fileName, 999999, 1, true); + else if (IsQuickSearchOpen == true && e.ctrlKey == false) { + searchFor($(".dualpane-search-input").val(), 999999, 1, true); } }); diff --git a/ui/style.css b/ui/style.css index 1bf96cd..9f364ea 100644 --- a/ui/style.css +++ b/ui/style.css @@ -61,14 +61,14 @@ body { border-right: 2px solid var(--transparentColor); width: 50%; max-width: 50%; - padding: 15px; + padding: 5px; min-height: 100vh - 110px; overflow: auto; } .dual-pane-right { border-left: 2px solid var(--transparentColor); width: 50%; - padding: 15px; + padding: 5px; overflow: auto; } .dual-pane-left > div > button, .dual-pane-right > div > button { @@ -616,7 +616,7 @@ label { height: fit-content; background: var(--primaryColor); padding: 10px; - border-radius: 5px; + border-radius: 10px; box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.2); } .text-input { @@ -732,7 +732,7 @@ label { flex-flow: column !important; justify-content: center; align-items: center; - height: calc(100vh - 110px); + height: calc(100vh - 100px); } From f3a9a2959527f021192b169cccaa214712fc0db4 Mon Sep 17 00:00:00 2001 From: Ricky Dane Date: Sun, 21 Jan 2024 18:12:21 +0100 Subject: [PATCH 2/2] Version 0.2.5 --- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 778e897..18721ad 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -112,7 +112,7 @@ checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "app" -version = "0.2.4" +version = "0.2.5" dependencies = [ "async-std", "async_ftp", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 9ca1d67..893274b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "app" -version = "0.2.4" +version = "0.2.5" description = "A simple file explorer" authors = ["Ricky Dane Perlick"] license = "none" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c1f1e3b..dc3a95e 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "rdpFX", - "version": "0.2.4" + "version": "0.2.5" }, "tauri": { "allowlist": {