From 4cdc4dfb2d2751dfd3d45829d1c682d191b31abd Mon Sep 17 00:00:00 2001 From: Speak2Erase Date: Wed, 28 Feb 2024 08:12:47 -0800 Subject: [PATCH] Appease clippy & don't repaint the ui on wakeup --- crates/eframe/src/native/file_storage.rs | 6 ++++-- crates/filesystem/src/trie.rs | 12 +++--------- crates/graphics/src/collision/mod.rs | 4 +--- crates/term/src/backends/process.rs | 21 +++++++-------------- crates/term/src/widget/mod.rs | 4 ++-- crates/ui/src/windows/console.rs | 7 ++----- src/app/top_bar.rs | 4 ++-- 7 files changed, 21 insertions(+), 37 deletions(-) diff --git a/crates/eframe/src/native/file_storage.rs b/crates/eframe/src/native/file_storage.rs index 79c0c97a..9652dc2f 100644 --- a/crates/eframe/src/native/file_storage.rs +++ b/crates/eframe/src/native/file_storage.rs @@ -99,11 +99,13 @@ impl crate::Storage for FileStorage { join_handle.join().ok(); } - match std::thread::Builder::new() + let result = std::thread::Builder::new() .name("eframe_persist".to_owned()) .spawn(move || { save_to_disk(&file_path, &kv); - }) { + }); + + match result { Ok(join_handle) => { self.last_save_join_handle = Some(join_handle); } diff --git a/crates/filesystem/src/trie.rs b/crates/filesystem/src/trie.rs index 5f402d28..a5641540 100644 --- a/crates/filesystem/src/trie.rs +++ b/crates/filesystem/src/trie.rs @@ -245,9 +245,7 @@ impl FileSystemTrie { /// Gets an immutable reference to the value in the file at the given path, if it exists. pub fn get_file(&self, path: impl AsRef) -> Option<&T> { let path = path.as_ref(); - let Some(filename) = path.iter().next_back() else { - return None; - }; + let filename = path.iter().next_back()?; let dir = path.parent().unwrap_or(camino::Utf8Path::new("")); self.0 .get_str(dir.as_str()) @@ -258,9 +256,7 @@ impl FileSystemTrie { /// Gets a mutable reference to the value in the file at the given path, if it exists. pub fn get_file_mut(&mut self, path: impl AsRef) -> Option<&mut T> { let path = path.as_ref(); - let Some(filename) = path.iter().next_back() else { - return None; - }; + let filename = path.iter().next_back()?; let dir = path.parent().unwrap_or(camino::Utf8Path::new("")); self.0 .get_mut_str(dir.as_str()) @@ -345,9 +341,7 @@ impl FileSystemTrie { /// Removes the file at the given path if it exists, and returns the original value. pub fn remove_file(&mut self, path: impl AsRef) -> Option { let path = path.as_ref(); - let Some(filename) = path.iter().next_back() else { - return None; - }; + let filename = path.iter().next_back()?; let dir = path.parent().unwrap_or(camino::Utf8Path::new("")); self.0 .get_mut_str(dir.as_str()) diff --git a/crates/graphics/src/collision/mod.rs b/crates/graphics/src/collision/mod.rs index 4be6b41c..7134b24d 100644 --- a/crates/graphics/src/collision/mod.rs +++ b/crates/graphics/src/collision/mod.rs @@ -65,9 +65,7 @@ pub fn calculate_passages( events .iter() .filter_map(|(_, event)| { - let Some(page) = event.pages.first() else { - return None; - }; + let page = event.pages.first()?; if page.through { return None; } diff --git a/crates/term/src/backends/process.rs b/crates/term/src/backends/process.rs index 68ebb323..b5617b28 100644 --- a/crates/term/src/backends/process.rs +++ b/crates/term/src/backends/process.rs @@ -36,30 +36,23 @@ use alacritty_terminal::{ }; pub struct Process { - term: Arc>>, + term: Arc>>, event_loop_sender: EventLoopSender, event_reciever: Receiver, } #[derive(Clone)] -pub struct WakeupEventListener(Sender, egui::Context); +pub struct ForwardEventListener(Sender); -impl alacritty_terminal::event::EventListener for WakeupEventListener { +impl alacritty_terminal::event::EventListener for ForwardEventListener { fn send_event(&self, event: Event) { println!("Recv event: {event:#?}"); - if let Event::Wakeup = event { - println!("repainting ui"); - self.1.request_repaint(); - } let _ = self.0.send(event); } } impl Process { - pub fn new( - options: &alacritty_terminal::tty::Options, - ctx: &egui::Context, - ) -> std::io::Result { + pub fn new(options: &alacritty_terminal::tty::Options) -> std::io::Result { let pty = alacritty_terminal::tty::new( options, WindowSize { @@ -72,7 +65,7 @@ impl Process { )?; let (sender, event_reciever) = std::sync::mpsc::channel(); - let event_proxy = WakeupEventListener(sender, ctx.clone()); + let event_proxy = ForwardEventListener(sender); let term_size = TermSize::new(80, 24); let term = Term::new( @@ -101,11 +94,11 @@ impl Process { } impl super::Backend for Process { - type EventListener = WakeupEventListener; + type EventListener = ForwardEventListener; fn with_term(&mut self, f: F) -> T where - F: FnOnce(&mut Term) -> T, + F: FnOnce(&mut Term) -> T, { f(&mut self.term.lock()) } diff --git a/crates/term/src/widget/mod.rs b/crates/term/src/widget/mod.rs index 0320b410..63d7bf0a 100644 --- a/crates/term/src/widget/mod.rs +++ b/crates/term/src/widget/mod.rs @@ -66,7 +66,7 @@ impl Terminal { } impl ProcessTerminal { - pub fn process(exec: ExecOptions, ctx: &egui::Context) -> std::io::Result { + pub fn process(exec: ExecOptions) -> std::io::Result { let options = alacritty_terminal::tty::Options { shell: exec .program @@ -74,7 +74,7 @@ impl ProcessTerminal { working_directory: exec.working_directory, hold: false, }; - crate::backends::Process::new(&options, ctx).map(Self::new) + crate::backends::Process::new(&options).map(Self::new) } } diff --git a/crates/ui/src/windows/console.rs b/crates/ui/src/windows/console.rs index dd542e70..08245b55 100644 --- a/crates/ui/src/windows/console.rs +++ b/crates/ui/src/windows/console.rs @@ -27,13 +27,10 @@ pub struct Window { } impl Window { - pub fn new( - ctx: &egui::Context, - exec: luminol_term::widget::ExecOptions, - ) -> std::io::Result { + pub fn new(exec: luminol_term::widget::ExecOptions) -> std::io::Result { Ok(Self { // TODO - term: luminol_term::widget::Terminal::process(exec, ctx)?, + term: luminol_term::widget::Terminal::process(exec)?, }) } } diff --git a/src/app/top_bar.rs b/src/app/top_bar.rs index 66f8356d..5ca33532 100644 --- a/src/app/top_bar.rs +++ b/src/app/top_bar.rs @@ -374,7 +374,7 @@ impl TopBar { ..Default::default() }; - match luminol_ui::windows::console::Window::new(ui.ctx(), exec.clone()) { + match luminol_ui::windows::console::Window::new(exec.clone()) { Ok(w) => update_state.edit_windows.add_window(w), Err(e) => luminol_core::error!( update_state.toasts, @@ -396,7 +396,7 @@ impl TopBar { ..Default::default() }; - match luminol_ui::windows::console::Window::new(ui.ctx(), exec) { + match luminol_ui::windows::console::Window::new(exec) { Ok(w) => update_state.edit_windows.add_window(w), Err(e) => luminol_core::error!( update_state.toasts,