Skip to content

Commit

Permalink
Appease clippy & don't repaint the ui on wakeup
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Feb 28, 2024
1 parent 893bad2 commit 4cdc4df
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 37 deletions.
6 changes: 4 additions & 2 deletions crates/eframe/src/native/file_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 3 additions & 9 deletions crates/filesystem/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ impl<T> FileSystemTrie<T> {
/// 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<camino::Utf8Path>) -> 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())
Expand All @@ -258,9 +256,7 @@ impl<T> FileSystemTrie<T> {
/// 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<camino::Utf8Path>) -> 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())
Expand Down Expand Up @@ -345,9 +341,7 @@ impl<T> FileSystemTrie<T> {
/// Removes the file at the given path if it exists, and returns the original value.
pub fn remove_file(&mut self, path: impl AsRef<camino::Utf8Path>) -> 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_mut_str(dir.as_str())
Expand Down
4 changes: 1 addition & 3 deletions crates/graphics/src/collision/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 7 additions & 14 deletions crates/term/src/backends/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,23 @@ use alacritty_terminal::{
};

pub struct Process {
term: Arc<FairMutex<Term<WakeupEventListener>>>,
term: Arc<FairMutex<Term<ForwardEventListener>>>,
event_loop_sender: EventLoopSender,
event_reciever: Receiver<Event>,
}

#[derive(Clone)]
pub struct WakeupEventListener(Sender<Event>, egui::Context);
pub struct ForwardEventListener(Sender<Event>);

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<Self> {
pub fn new(options: &alacritty_terminal::tty::Options) -> std::io::Result<Self> {
let pty = alacritty_terminal::tty::new(
options,
WindowSize {
Expand All @@ -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(
Expand Down Expand Up @@ -101,11 +94,11 @@ impl Process {
}

impl super::Backend for Process {
type EventListener = WakeupEventListener;
type EventListener = ForwardEventListener;

fn with_term<T, F>(&mut self, f: F) -> T
where
F: FnOnce(&mut Term<WakeupEventListener>) -> T,
F: FnOnce(&mut Term<ForwardEventListener>) -> T,
{
f(&mut self.term.lock())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/term/src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ impl<T> Terminal<T> {
}

impl ProcessTerminal {
pub fn process(exec: ExecOptions, ctx: &egui::Context) -> std::io::Result<Self> {
pub fn process(exec: ExecOptions) -> std::io::Result<Self> {
let options = alacritty_terminal::tty::Options {
shell: exec
.program
.map(|program| alacritty_terminal::tty::Shell::new(program, exec.args)),
working_directory: exec.working_directory,
hold: false,
};
crate::backends::Process::new(&options, ctx).map(Self::new)
crate::backends::Process::new(&options).map(Self::new)
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/ui/src/windows/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ pub struct Window {
}

impl Window {
pub fn new(
ctx: &egui::Context,
exec: luminol_term::widget::ExecOptions,
) -> std::io::Result<Self> {
pub fn new(exec: luminol_term::widget::ExecOptions) -> std::io::Result<Self> {
Ok(Self {
// TODO
term: luminol_term::widget::Terminal::process(exec, ctx)?,
term: luminol_term::widget::Terminal::process(exec)?,
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/top_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 4cdc4df

Please sign in to comment.