From 345324a2f64646755e202545d1d59b6135e60b66 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Thu, 6 Feb 2025 10:01:23 -0800 Subject: [PATCH 1/8] drive-by compiler warning fixes --- crates/notedeck_chrome/src/notedeck.rs | 2 +- crates/notedeck_columns/src/timeline/route.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/notedeck_chrome/src/notedeck.rs b/crates/notedeck_chrome/src/notedeck.rs index 0ca84366..d9b3894c 100644 --- a/crates/notedeck_chrome/src/notedeck.rs +++ b/crates/notedeck_chrome/src/notedeck.rs @@ -194,7 +194,7 @@ mod tests { .timeline_id() .unwrap(); - let timelines = app.timeline_cache.timelines.len() == 2; + assert_eq!(app.timeline_cache.timelines.len(), 2); assert!(app.timeline_cache.timelines.get(&tl1).is_some()); assert!(app.timeline_cache.timelines.get(&tl2).is_some()); diff --git a/crates/notedeck_columns/src/timeline/route.rs b/crates/notedeck_columns/src/timeline/route.rs index ecbb595b..76bd13c0 100644 --- a/crates/notedeck_columns/src/timeline/route.rs +++ b/crates/notedeck_columns/src/timeline/route.rs @@ -141,7 +141,7 @@ pub fn render_profile_route( #[cfg(test)] mod tests { use enostr::NoteId; - use tokenator::{TokenParser, TokenSerializable, TokenWriter}; + use tokenator::{TokenParser, TokenWriter}; use crate::timeline::{ThreadSelection, TimelineKind}; use enostr::Pubkey; @@ -149,8 +149,6 @@ mod tests { #[test] fn test_timeline_route_serialize() { - use super::TimelineKind; - let note_id_hex = "1c54e5b0c386425f7e017d9e068ddef8962eb2ce1bb08ed27e24b93411c12e60"; let note_id = NoteId::from_hex(note_id_hex).unwrap(); let data_str = format!("thread:{}", note_id_hex); From 2ddc53faa5a82b8356b2e7dff0bf829c36bdc48a Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Wed, 5 Feb 2025 12:36:32 -0800 Subject: [PATCH 2/8] drive-by clippy fixes --- crates/notedeck_chrome/src/notedeck.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/notedeck_chrome/src/notedeck.rs b/crates/notedeck_chrome/src/notedeck.rs index d9b3894c..47706edb 100644 --- a/crates/notedeck_chrome/src/notedeck.rs +++ b/crates/notedeck_chrome/src/notedeck.rs @@ -131,7 +131,7 @@ mod tests { async fn test_dbpath() { let datapath = create_tmp_dir(); let dbpath = create_tmp_dir(); - let args: Vec = vec![ + let args: Vec = [ "--testrunner", "--datapath", &datapath.to_str().unwrap(), @@ -157,7 +157,7 @@ mod tests { async fn test_column_args() { let tmpdir = create_tmp_dir(); let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s"; - let args: Vec = vec![ + let args: Vec = [ "--testrunner", "--no-keystore", "--pub", From 201cfb2db1706cc1685a716eafeb839f7856a916 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Wed, 5 Feb 2025 14:24:57 -0800 Subject: [PATCH 3/8] add derive Debug to some things --- crates/notedeck_columns/src/column.rs | 4 ++-- crates/notedeck_columns/src/route.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/notedeck_columns/src/column.rs b/crates/notedeck_columns/src/column.rs index 546f382a..c56026c2 100644 --- a/crates/notedeck_columns/src/column.rs +++ b/crates/notedeck_columns/src/column.rs @@ -9,7 +9,7 @@ use notedeck::NoteCache; use std::iter::Iterator; use tracing::warn; -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Column { router: Router, } @@ -29,7 +29,7 @@ impl Column { } } -#[derive(Default)] +#[derive(Default, Debug)] pub struct Columns { /// Columns are simply routers into settings, timelines, etc columns: Vec, diff --git a/crates/notedeck_columns/src/route.rs b/crates/notedeck_columns/src/route.rs index bcad8096..996406a1 100644 --- a/crates/notedeck_columns/src/route.rs +++ b/crates/notedeck_columns/src/route.rs @@ -229,7 +229,7 @@ impl Route { // TODO: add this to egui-nav so we don't have to deal with returning // and navigating headaches -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct Router { routes: Vec, pub returning: bool, From 480f98eda48b4fd495fa44417c036904fcea9334 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Wed, 5 Feb 2025 10:43:21 -0800 Subject: [PATCH 4/8] panic on unknown CLI arguments Currently silently ignores which is not helpful ... --- crates/notedeck/src/app.rs | 11 ++++- crates/notedeck/src/args.rs | 10 ++++- crates/notedeck_chrome/src/android.rs | 13 ++++++ crates/notedeck_chrome/src/notedeck.rs | 60 ++++++++++++++++++++++++++ crates/notedeck_chrome/src/preview.rs | 5 +++ crates/notedeck_columns/src/app.rs | 12 +++++- crates/notedeck_columns/src/args.rs | 9 +++- 7 files changed, 113 insertions(+), 7 deletions(-) diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs index c4169fce..f59df087 100644 --- a/crates/notedeck/src/app.rs +++ b/crates/notedeck/src/app.rs @@ -7,6 +7,7 @@ use egui::ThemePreference; use enostr::RelayPool; use nostrdb::{Config, Ndb, Transaction}; use std::cell::RefCell; +use std::collections::BTreeSet; use std::path::Path; use std::rc::Rc; use tracing::{error, info}; @@ -29,6 +30,7 @@ pub struct Notedeck { app: Option>>, zoom: ZoomHandler, app_size: AppSizeHandler, + unrecognized_args: BTreeSet, } fn margin_top(narrow: bool) -> f32 { @@ -106,7 +108,9 @@ impl Notedeck { #[cfg(feature = "profiling")] setup_profiling(); - let parsed_args = Args::parse(args); + // Skip the first argument, which is the program name. + let args_to_parse: Vec = args[1..].to_vec(); + let (parsed_args, unrecognized_args) = Args::parse(&args_to_parse); let data_path = parsed_args .datapath @@ -203,6 +207,7 @@ impl Notedeck { app: None, zoom, app_size, + unrecognized_args, } } @@ -236,4 +241,8 @@ impl Notedeck { pub fn theme(&self) -> ThemePreference { self.theme.load() } + + pub fn unrecognized_args(&self) -> &BTreeSet { + &self.unrecognized_args + } } diff --git a/crates/notedeck/src/args.rs b/crates/notedeck/src/args.rs index b84aaf70..53a92224 100644 --- a/crates/notedeck/src/args.rs +++ b/crates/notedeck/src/args.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeSet; + use enostr::{Keypair, Pubkey, SecretKey}; use tracing::error; @@ -18,7 +20,9 @@ pub struct Args { } impl Args { - pub fn parse(args: &[String]) -> Self { + // parse arguments, return set of unrecognized args + pub fn parse(args: &[String]) -> (Self, BTreeSet) { + let mut unrecognized_args = BTreeSet::new(); let mut res = Args { relays: vec![], is_mobile: None, @@ -112,11 +116,13 @@ impl Args { res.use_keystore = false; } else if arg == "--relay-debug" { res.relay_debug = true; + } else { + unrecognized_args.insert(arg.clone()); } i += 1; } - res + (res, unrecognized_args) } } diff --git a/crates/notedeck_chrome/src/android.rs b/crates/notedeck_chrome/src/android.rs index 8072c59a..db274bc9 100644 --- a/crates/notedeck_chrome/src/android.rs +++ b/crates/notedeck_chrome/src/android.rs @@ -60,6 +60,19 @@ pub async fn android_main(app: AndroidApp) { setup_chrome(ctx, ¬edeck.args(), notedeck.theme()); let damus = Damus::new(&mut notedeck.app_context(), &app_args); + + // ensure we recognized all the arguments + let completely_unrecognized: Vec = notedeck + .unrecognized_args() + .intersection(damus.unrecognized_args()) + .cloned() + .collect(); + assert!( + completely_unrecognized.is_empty(), + "unrecognized args: {:?}", + completely_unrecognized + ); + notedeck.set_app(damus); Ok(Box::new(notedeck)) diff --git a/crates/notedeck_chrome/src/notedeck.rs b/crates/notedeck_chrome/src/notedeck.rs index 47706edb..9ed2d5cf 100644 --- a/crates/notedeck_chrome/src/notedeck.rs +++ b/crates/notedeck_chrome/src/notedeck.rs @@ -78,6 +78,19 @@ async fn main() { setup_chrome(ctx, notedeck.args(), notedeck.theme()); let damus = Damus::new(&mut notedeck.app_context(), &args); + + // ensure we recognized all the arguments + let completely_unrecognized: Vec = notedeck + .unrecognized_args() + .intersection(&damus.unrecognized_args()) + .cloned() + .collect(); + assert!( + completely_unrecognized.is_empty(), + "unrecognized args: {:?}", + completely_unrecognized + ); + // TODO: move "chrome" frame over Damus app somehow notedeck.set_app(damus); @@ -173,9 +186,21 @@ mod tests { let ctx = egui::Context::default(); let mut notedeck = Notedeck::new(&ctx, &tmpdir, &args); + let unrecognized_args = notedeck.unrecognized_args().clone(); let mut app_ctx = notedeck.app_context(); let app = Damus::new(&mut app_ctx, &args); + // ensure we recognized all the arguments + let completely_unrecognized: Vec = unrecognized_args + .intersection(app.unrecognized_args()) + .cloned() + .collect(); + assert!( + completely_unrecognized.is_empty(), + "unrecognized args: {:?}", + completely_unrecognized + ); + assert_eq!(app.columns(app_ctx.accounts).columns().len(), 2); let tl1 = app @@ -200,4 +225,39 @@ mod tests { rmrf(tmpdir); } + + #[tokio::test] + async fn test_unknown_args() { + let tmpdir = create_tmp_dir(); + let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s"; + let args: Vec = [ + "--testrunner", + "--no-keystore", + "--unknown-arg", // <-- UNKNOWN + "--pub", + npub, + "-c", + "notifications", + "-c", + "contacts", + ] + .iter() + .map(|s| s.to_string()) + .collect(); + + let ctx = egui::Context::default(); + let mut notedeck = Notedeck::new(&ctx, &tmpdir, &args); + let mut app_ctx = notedeck.app_context(); + let app = Damus::new(&mut app_ctx, &args); + + // ensure we recognized all the arguments + let completely_unrecognized: Vec = notedeck + .unrecognized_args() + .intersection(app.unrecognized_args()) + .cloned() + .collect(); + assert_eq!(completely_unrecognized, ["--unknown-arg"]); + + rmrf(tmpdir); + } } diff --git a/crates/notedeck_chrome/src/preview.rs b/crates/notedeck_chrome/src/preview.rs index 45ab33a5..2fdba419 100644 --- a/crates/notedeck_chrome/src/preview.rs +++ b/crates/notedeck_chrome/src/preview.rs @@ -33,6 +33,11 @@ impl PreviewRunner { let ctx = &cc.egui_ctx; let mut notedeck = Notedeck::new(ctx, &base_path, &args); + assert!( + notedeck.unrecognized_args().is_empty(), + "unrecognized args: {:?}", + notedeck.unrecognized_args() + ); setup_chrome(ctx, notedeck.args(), notedeck.theme()); notedeck.set_app(PreviewApp::new(preview)); diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs index d32edb6b..42ae4628 100644 --- a/crates/notedeck_columns/src/app.rs +++ b/crates/notedeck_columns/src/app.rs @@ -22,7 +22,7 @@ use egui_extras::{Size, StripBuilder}; use nostrdb::{Ndb, Transaction}; -use std::collections::HashMap; +use std::collections::{BTreeSet, HashMap}; use std::path::Path; use std::time::Duration; use tracing::{error, info, trace, warn}; @@ -51,6 +51,8 @@ pub struct Damus { pub debug: bool, pub since_optimize: bool, pub textmode: bool, + + pub unrecognized_args: BTreeSet, } fn handle_key_events(input: &egui::InputState, columns: &mut Columns) { @@ -357,7 +359,7 @@ impl Damus { pub fn new(ctx: &mut AppContext<'_>, args: &[String]) -> Self { // arg parsing - let parsed_args = ColumnsArgs::parse( + let (parsed_args, unrecognized_args) = ColumnsArgs::parse( args, ctx.accounts .get_selected_account() @@ -433,6 +435,7 @@ impl Damus { support, decks_cache, debug, + unrecognized_args, } } @@ -475,12 +478,17 @@ impl Damus { view_state: ViewState::default(), support, decks_cache, + unrecognized_args: BTreeSet::default(), } } pub fn subscriptions(&mut self) -> &mut HashMap { &mut self.subscriptions.subs } + + pub fn unrecognized_args(&self) -> &BTreeSet { + &self.unrecognized_args + } } /* diff --git a/crates/notedeck_columns/src/args.rs b/crates/notedeck_columns/src/args.rs index fc2905ea..4a60dc55 100644 --- a/crates/notedeck_columns/src/args.rs +++ b/crates/notedeck_columns/src/args.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeSet; + use crate::timeline::TimelineKind; use enostr::{Filter, Pubkey}; use tracing::{debug, error, info}; @@ -9,7 +11,8 @@ pub struct ColumnsArgs { } impl ColumnsArgs { - pub fn parse(args: &[String], deck_author: Option<&Pubkey>) -> Self { + pub fn parse(args: &[String], deck_author: Option<&Pubkey>) -> (Self, BTreeSet) { + let mut unrecognized_args = BTreeSet::new(); let mut res = Self { columns: vec![], since_optimize: true, @@ -132,12 +135,14 @@ impl ColumnsArgs { } else { error!("failed to parse filter in '{}'", filter_file); } + } else { + unrecognized_args.insert(arg.clone()); } i += 1; } - res + (res, unrecognized_args) } } From 091c638eb135ad276ea0b16c79af201303a3bce1 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Wed, 5 Feb 2025 12:29:55 -0800 Subject: [PATCH 5/8] move RelayDebugView to notedeck crate and restore --relay-debug --- crates/notedeck/src/app.rs | 12 +++++++++--- crates/notedeck/src/lib.rs | 2 ++ .../src/ui => notedeck/src}/relay_debug.rs | 0 crates/notedeck_columns/src/ui/mod.rs | 1 - 4 files changed, 11 insertions(+), 4 deletions(-) rename crates/{notedeck_columns/src/ui => notedeck/src}/relay_debug.rs (100%) diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs index f59df087..455508db 100644 --- a/crates/notedeck/src/app.rs +++ b/crates/notedeck/src/app.rs @@ -1,7 +1,7 @@ use crate::persist::{AppSizeHandler, ZoomHandler}; use crate::{ Accounts, AppContext, Args, DataPath, DataPathType, Directory, FileKeyStorage, ImageCache, - KeyStorageType, NoteCache, ThemeHandler, UnknownIds, + KeyStorageType, NoteCache, RelayDebugView, ThemeHandler, UnknownIds, }; use egui::ThemePreference; use enostr::RelayPool; @@ -84,8 +84,14 @@ impl eframe::App for Notedeck { self.zoom.try_save_zoom_factor(ctx); self.app_size.try_save_app_size(ctx); - if self.args.relay_debug && self.pool.debug.is_none() { - self.pool.use_debug(); + if self.args.relay_debug { + if self.pool.debug.is_none() { + self.pool.use_debug(); + } + + if let Some(debug) = &mut self.pool.debug { + RelayDebugView::window(ctx, debug); + } } #[cfg(feature = "profiling")] diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs index b176a5f9..61c31fba 100644 --- a/crates/notedeck/src/lib.rs +++ b/crates/notedeck/src/lib.rs @@ -10,6 +10,7 @@ mod muted; pub mod note; mod notecache; mod persist; +pub mod relay_debug; pub mod relayspec; mod result; pub mod storage; @@ -34,6 +35,7 @@ pub use muted::{MuteFun, Muted}; pub use note::{NoteRef, RootIdError, RootNoteId, RootNoteIdBuf}; pub use notecache::{CachedNote, NoteCache}; pub use persist::*; +pub use relay_debug::RelayDebugView; pub use relayspec::RelaySpec; pub use result::Result; pub use storage::{ diff --git a/crates/notedeck_columns/src/ui/relay_debug.rs b/crates/notedeck/src/relay_debug.rs similarity index 100% rename from crates/notedeck_columns/src/ui/relay_debug.rs rename to crates/notedeck/src/relay_debug.rs diff --git a/crates/notedeck_columns/src/ui/mod.rs b/crates/notedeck_columns/src/ui/mod.rs index dc228566..5a4bb159 100644 --- a/crates/notedeck_columns/src/ui/mod.rs +++ b/crates/notedeck_columns/src/ui/mod.rs @@ -10,7 +10,6 @@ pub mod note; pub mod preview; pub mod profile; pub mod relay; -pub mod relay_debug; pub mod side_panel; pub mod support; pub mod thread; From 44181e24db0bbfc740d68b69be63bd10f3940f71 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 10 Feb 2025 16:57:18 -0800 Subject: [PATCH 6/8] clippy: fix lint Signed-off-by: William Casarin --- crates/notedeck_chrome/src/notedeck.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/notedeck_chrome/src/notedeck.rs b/crates/notedeck_chrome/src/notedeck.rs index 9ed2d5cf..62402dfc 100644 --- a/crates/notedeck_chrome/src/notedeck.rs +++ b/crates/notedeck_chrome/src/notedeck.rs @@ -82,7 +82,7 @@ async fn main() { // ensure we recognized all the arguments let completely_unrecognized: Vec = notedeck .unrecognized_args() - .intersection(&damus.unrecognized_args()) + .intersection(damus.unrecognized_args()) .cloned() .collect(); assert!( From 6fb720e0c5c7f250f183eaece67a2d7a465f15e9 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 10 Feb 2025 16:57:50 -0800 Subject: [PATCH 7/8] args: skip creation of vec Signed-off-by: William Casarin --- crates/notedeck/src/app.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/notedeck/src/app.rs b/crates/notedeck/src/app.rs index 455508db..75026831 100644 --- a/crates/notedeck/src/app.rs +++ b/crates/notedeck/src/app.rs @@ -115,8 +115,7 @@ impl Notedeck { setup_profiling(); // Skip the first argument, which is the program name. - let args_to_parse: Vec = args[1..].to_vec(); - let (parsed_args, unrecognized_args) = Args::parse(&args_to_parse); + let (parsed_args, unrecognized_args) = Args::parse(&args[1..]); let data_path = parsed_args .datapath From 353a3c87c3cd518be3dcb875ad660181d313c72b Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 10 Feb 2025 17:01:57 -0800 Subject: [PATCH 8/8] nix: fix android build Signed-off-by: William Casarin --- shell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index 735838b0..390f58b2 100644 --- a/shell.nix +++ b/shell.nix @@ -55,7 +55,7 @@ mkShell ({ cmdline-tools-latest build-tools-34-0-0 platform-tools - platforms-android-31 + platforms-android-30 ndk-27-2-12479018 #ndk-24-0-8215888 ] ++ lib.optional android_emulator [ emulator ]);