better stopping, better file pre-selecting

This commit is contained in:
Joe Ardent 2025-08-08 16:51:33 -07:00
parent 7eccbaeb9e
commit d84a046ec9
5 changed files with 14 additions and 11 deletions

2
Cargo.lock generated
View file

@ -1324,7 +1324,7 @@ dependencies = [
[[package]] [[package]]
name = "jocalsend" name = "jocalsend"
version = "0.1.0" version = "1.0.0"
dependencies = [ dependencies = [
"axum", "axum",
"axum-server", "axum-server",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "jocalsend" name = "jocalsend"
version = "0.1.0" version = "1.0.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]

View file

@ -134,7 +134,7 @@ impl App {
| CurrentScreen::Sending(SendingScreen::Files) | CurrentScreen::Sending(SendingScreen::Files)
| CurrentScreen::Sending(SendingScreen::Peers) => match code { | CurrentScreen::Sending(SendingScreen::Peers) => match code {
KeyCode::Esc => self.pop(), KeyCode::Esc => self.pop(),
KeyCode::Char('q') => self.exit(), KeyCode::Char('q') => self.exit().await,
KeyCode::Char('s') => self.send(), KeyCode::Char('s') => self.send(),
KeyCode::Char('r') => self.recv(), KeyCode::Char('r') => self.recv(),
KeyCode::Char('l') => self.logs(), KeyCode::Char('l') => self.logs(),
@ -206,8 +206,9 @@ impl App {
frame.render_widget(self, frame.area()); frame.render_widget(self, frame.area());
} }
pub fn exit(&mut self) { pub async fn exit(&mut self) {
self.screen.push(CurrentScreen::Stopping); self.screen.push(CurrentScreen::Stopping);
self.service.stop().await;
} }
pub fn send(&mut self) { pub fn send(&mut self) {

View file

@ -136,7 +136,7 @@ impl Widget for &mut App {
// one element in `self.screen`; see the `self.pop()` method // one element in `self.screen`; see the `self.pop()` method
let current_screen = self.screen(); let current_screen = self.screen();
match current_screen { match current_screen {
CurrentScreen::Main => { CurrentScreen::Main | CurrentScreen::Stopping => {
let rx_reqs: Vec<_> = self.receive_requests.values().collect(); let rx_reqs: Vec<_> = self.receive_requests.values().collect();
outer_frame(&current_screen, &MAIN_MENU, area, buf); outer_frame(&current_screen, &MAIN_MENU, area, buf);
logger(header_right.inner(header_margin), buf); logger(header_right.inner(header_margin), buf);
@ -213,9 +213,6 @@ impl Widget for &mut App {
// function // function
} }
} }
_ => {
outer_frame(&current_screen, &MAIN_MENU, area, buf);
}
} }
} }
} }

View file

@ -64,7 +64,6 @@ async fn start_and_run(terminal: &mut DefaultTerminal, config: Config) -> Result
app.handle_events().await?; app.handle_events().await?;
if app.screen() == CurrentScreen::Stopping { if app.screen() == CurrentScreen::Stopping {
app.service.stop().await;
break; break;
} }
@ -128,11 +127,17 @@ fn set_file_selection(path: &Path, explorer: &mut FileExplorer) {
let parent = path.parent().map(|f| f.to_path_buf()).unwrap_or("/".into()); let parent = path.parent().map(|f| f.to_path_buf()).unwrap_or("/".into());
let _ = explorer.set_cwd(parent); let _ = explorer.set_cwd(parent);
}; };
let files = explorer.files().clone();
let files = explorer.files();
let mut idx = None;
for (i, f) in files.iter().enumerate() { for (i, f) in files.iter().enumerate() {
if f.name() == path.file_name().unwrap().to_string_lossy() { if f.name() == path.file_name().unwrap().to_string_lossy() {
explorer.set_selected_idx(i); idx = Some(i);
break; break;
} }
} }
if let Some(idx) = idx {
explorer.set_selected_idx(idx);
}
} }