diff --git a/Cargo.lock b/Cargo.lock index b4988ad..7296280 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,12 +44,6 @@ version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" -[[package]] -name = "cfg-if" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" - [[package]] name = "cfg-if" version = "1.0.0" @@ -87,7 +81,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "crossbeam-utils", ] @@ -97,7 +91,7 @@ version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -106,7 +100,7 @@ version = "0.8.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -139,18 +133,6 @@ dependencies = [ "instant", ] -[[package]] -name = "filetime" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.16", - "windows-sys 0.48.0", -] - [[package]] name = "fltk" version = "1.4.3" @@ -203,41 +185,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fsevent" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" -dependencies = [ - "bitflags 1.3.2", - "fsevent-sys", -] - -[[package]] -name = "fsevent-sys" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41b048a94555da0f42f1d632e2e19510084fb8e303b0daa2816e733fb3644a0" -dependencies = [ - "libc", -] - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags 1.3.2", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - [[package]] name = "futures-channel" version = "0.3.28" @@ -279,10 +226,9 @@ dependencies = [ [[package]] name = "get_paper_rs" -version = "0.1.0" +version = "0.2.0" dependencies = [ "fltk", - "hotwatch", "open", "reqwest", "serde", @@ -332,16 +278,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" -[[package]] -name = "hotwatch" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39301670a6f5798b75f36a1b149a379a50df5aa7c71be50f4b41ec6eab445cb8" -dependencies = [ - "log", - "notify", -] - [[package]] name = "http" version = "0.2.9" @@ -433,33 +369,13 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "inotify" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4816c66d2c8ae673df83366c18341538f234a26d65a9ecea5c348b453ac1d02f" -dependencies = [ - "bitflags 1.3.2", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -473,15 +389,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - [[package]] name = "ipnet" version = "2.7.2" @@ -522,28 +429,12 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" version = "0.2.144" @@ -572,7 +463,7 @@ version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", ] [[package]] @@ -581,25 +472,6 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", - "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - [[package]] name = "mio" version = "0.8.6" @@ -612,30 +484,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "mio-extras" -version = "2.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" -dependencies = [ - "lazycell", - "log", - "mio 0.6.23", - "slab", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - [[package]] name = "native-tls" version = "0.2.11" @@ -654,35 +502,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "net2" -version = "0.2.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", -] - -[[package]] -name = "notify" -version = "4.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae03c8c853dba7bfd23e571ff0cff7bc9dceb40a4cd684cd1681824183f45257" -dependencies = [ - "bitflags 1.3.2", - "filetime", - "fsevent", - "fsevent-sys", - "inotify", - "libc", - "mio 0.6.23", - "mio-extras", - "walkdir", - "winapi 0.3.9", -] - [[package]] name = "num_cpus" version = "1.15.0" @@ -716,7 +535,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01b8574602df80f7b85fdfc5392fa884a4e3b3f4f35402c070ab34c3d3f78d56" dependencies = [ "bitflags 1.3.2", - "cfg-if 1.0.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -769,7 +588,7 @@ version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", "redox_syscall 0.2.16", "smallvec", @@ -1023,7 +842,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1043,7 +862,7 @@ version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", "redox_syscall 0.3.5", "rustix", @@ -1074,7 +893,7 @@ dependencies = [ "autocfg", "bytes", "libc", - "mio 0.8.6", + "mio", "num_cpus", "parking_lot", "pin-project-lite", @@ -1131,7 +950,7 @@ version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "pin-project-lite", "tracing-core", ] @@ -1227,7 +1046,7 @@ version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] @@ -1252,7 +1071,7 @@ version = "0.4.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -1297,12 +1116,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -1313,12 +1126,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -1331,7 +1138,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] @@ -1493,15 +1300,5 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ - "winapi 0.3.9", -] - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", + "winapi", ] diff --git a/Cargo.toml b/Cargo.toml index 18543ac..ae3e15f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "get_paper_rs" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -14,4 +14,3 @@ serde_derive = "*" serde_json = "*" walkdir = "2.3.3" open = "*" -hotwatch = "0.4.6" diff --git a/src/main.rs b/src/main.rs index d36b6b2..79b0155 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,38 +2,9 @@ use fltk::prelude::*; use ui::Message; mod ui; -fn get_result_path(changed_path: std::path::PathBuf) -> String { - let path_str = changed_path.to_str().unwrap(); - let split_path: Vec<&str> = path_str.split('/').collect(); - let mut result_path = std::string::String::from(ui::data::SAVE_DIR); - let mut save_dir_level = split_path.len(); - for path_level in 0..split_path.len() { - // 如果到了那一级,那就标记为这个位置 - if split_path[path_level] == ui::data::SAVE_DIR { - save_dir_level = path_level; - } - // 如果在后面就表示要加进去了 - if path_level > save_dir_level { - result_path.push_str(format!("/{}", split_path[path_level]).as_str()); - } - } - // println!("Result Path: {}", result_path); - result_path -} - -#[derive(Clone, Copy)] -enum FileSystemOperation { - Create, - Remove, - None -} - -static mut FILE_SYSTEM_REFRESH_PATH: String = std::string::String::new(); -static mut FILE_SYSTEM_OPERATION: FileSystemOperation = FileSystemOperation::None; - // main -#[tokio::main] +#[tokio::main(worker_threads = 3)] async fn main() { // 初始化一些东西 let save_path = std::path::Path::new(ui::data::SAVE_DIR); @@ -49,56 +20,24 @@ async fn main() { let mut buffer: ui::Buffer = ui::add_widgets(&mut root, sender); - let mut watcher = hotwatch::Hotwatch::new().expect("Failed to initialize hotwatch!"); - watcher.watch(ui::data::SAVE_DIR, - |e: hotwatch::Event| { - println!("{:?}", e); - if let hotwatch::Event::Create(changed_path) = e { - // 如果是写入文件 - unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(changed_path) }; - unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Create }; - } else if let hotwatch::Event::Remove(changed_path) = e { - unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(changed_path) }; - unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Remove }; - } else if let hotwatch::Event::Rename(original_path, target_path) = e { - unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(original_path) }; - unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Remove }; - unsafe { FILE_SYSTEM_REFRESH_PATH = get_result_path(target_path) }; - unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::Create }; - } - } - ).unwrap(); - root.show(); // app.run().unwrap(); while app.wait() { + app.redraw(); // 刷新状态栏 buffer.status_bar.set_value(unsafe { &ui::STATUS_BAR_CONTENT }); - // 文件系统刷新机制 - if unsafe { !FILE_SYSTEM_REFRESH_PATH.is_empty() } { - println!("Refresh Path: {}", unsafe { FILE_SYSTEM_REFRESH_PATH.as_str() }); - let file_system_refresh_path = unsafe { FILE_SYSTEM_REFRESH_PATH.as_str() }; - match unsafe { FILE_SYSTEM_OPERATION } { - FileSystemOperation::Create => { - buffer.refresh_file_system(file_system_refresh_path); - }, - FileSystemOperation::Remove => { - buffer.remove_file_system_node(file_system_refresh_path); - }, - FileSystemOperation::None => {} - } - unsafe { FILE_SYSTEM_REFRESH_PATH.clear() }; - unsafe { FILE_SYSTEM_OPERATION = FileSystemOperation::None }; - } + // 刷新文件系统 + buffer.refresh_file_system(ui::data::SAVE_DIR); if let Some(msg) = receiver.recv() { match msg { Message::Start => { let buffer_clone = buffer.clone(); println!("Start"); - tokio::spawn(async move { + + tokio::spawn( async { ui::network::start(buffer_clone).await; }); } diff --git a/src/ui.rs b/src/ui.rs index fb6073d..96488eb 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -47,15 +47,6 @@ impl Buffer { } } - pub fn remove_file_system_node(&mut self, node_path: &str) { - let items = self.file_system.get_items().unwrap(); - for item in items { - if self.file_system.item_pathname(&item).unwrap() == node_path { - self.file_system.remove(&item).unwrap(); - } - } - } - pub fn close_all_nodes(&mut self) { let nodes = self.file_system.get_items().unwrap(); for mut node in nodes {