Merge relay debug view fixes & more strict args #711
Ken Sedgwick (5):
drive-by compiler warning fixes
drive-by clippy fixes
add derive Debug to some things
panic on unknown CLI arguments
move RelayDebugView to notedeck crate and restore --relay-debug
William Casarin (4):
clippy: fix lint
args: skip creation of vec
nix: fix android build
Link: https://github.com/damus-io/notedeck/pull/711
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
use crate::persist::{AppSizeHandler, ZoomHandler};
|
use crate::persist::{AppSizeHandler, ZoomHandler};
|
||||||
use crate::{
|
use crate::{
|
||||||
Accounts, AppContext, Args, DataPath, DataPathType, Directory, FileKeyStorage, ImageCache,
|
Accounts, AppContext, Args, DataPath, DataPathType, Directory, FileKeyStorage, ImageCache,
|
||||||
KeyStorageType, NoteCache, ThemeHandler, UnknownIds,
|
KeyStorageType, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
|
||||||
};
|
};
|
||||||
use egui::ThemePreference;
|
use egui::ThemePreference;
|
||||||
use enostr::RelayPool;
|
use enostr::RelayPool;
|
||||||
use nostrdb::{Config, Ndb, Transaction};
|
use nostrdb::{Config, Ndb, Transaction};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::collections::BTreeSet;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
@@ -29,6 +30,7 @@ pub struct Notedeck {
|
|||||||
app: Option<Rc<RefCell<dyn App>>>,
|
app: Option<Rc<RefCell<dyn App>>>,
|
||||||
zoom: ZoomHandler,
|
zoom: ZoomHandler,
|
||||||
app_size: AppSizeHandler,
|
app_size: AppSizeHandler,
|
||||||
|
unrecognized_args: BTreeSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn margin_top(narrow: bool) -> f32 {
|
fn margin_top(narrow: bool) -> f32 {
|
||||||
@@ -82,8 +84,14 @@ impl eframe::App for Notedeck {
|
|||||||
self.zoom.try_save_zoom_factor(ctx);
|
self.zoom.try_save_zoom_factor(ctx);
|
||||||
self.app_size.try_save_app_size(ctx);
|
self.app_size.try_save_app_size(ctx);
|
||||||
|
|
||||||
if self.args.relay_debug && self.pool.debug.is_none() {
|
if self.args.relay_debug {
|
||||||
self.pool.use_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")]
|
#[cfg(feature = "profiling")]
|
||||||
@@ -106,7 +114,8 @@ impl Notedeck {
|
|||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
setup_profiling();
|
setup_profiling();
|
||||||
|
|
||||||
let parsed_args = Args::parse(args);
|
// Skip the first argument, which is the program name.
|
||||||
|
let (parsed_args, unrecognized_args) = Args::parse(&args[1..]);
|
||||||
|
|
||||||
let data_path = parsed_args
|
let data_path = parsed_args
|
||||||
.datapath
|
.datapath
|
||||||
@@ -203,6 +212,7 @@ impl Notedeck {
|
|||||||
app: None,
|
app: None,
|
||||||
zoom,
|
zoom,
|
||||||
app_size,
|
app_size,
|
||||||
|
unrecognized_args,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,4 +246,8 @@ impl Notedeck {
|
|||||||
pub fn theme(&self) -> ThemePreference {
|
pub fn theme(&self) -> ThemePreference {
|
||||||
self.theme.load()
|
self.theme.load()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unrecognized_args(&self) -> &BTreeSet<String> {
|
||||||
|
&self.unrecognized_args
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use enostr::{Keypair, Pubkey, SecretKey};
|
use enostr::{Keypair, Pubkey, SecretKey};
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
@@ -18,7 +20,9 @@ pub struct Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
pub fn parse(args: &[String]) -> Self {
|
// parse arguments, return set of unrecognized args
|
||||||
|
pub fn parse(args: &[String]) -> (Self, BTreeSet<String>) {
|
||||||
|
let mut unrecognized_args = BTreeSet::new();
|
||||||
let mut res = Args {
|
let mut res = Args {
|
||||||
relays: vec![],
|
relays: vec![],
|
||||||
is_mobile: None,
|
is_mobile: None,
|
||||||
@@ -112,11 +116,13 @@ impl Args {
|
|||||||
res.use_keystore = false;
|
res.use_keystore = false;
|
||||||
} else if arg == "--relay-debug" {
|
} else if arg == "--relay-debug" {
|
||||||
res.relay_debug = true;
|
res.relay_debug = true;
|
||||||
|
} else {
|
||||||
|
unrecognized_args.insert(arg.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
(res, unrecognized_args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ mod muted;
|
|||||||
pub mod note;
|
pub mod note;
|
||||||
mod notecache;
|
mod notecache;
|
||||||
mod persist;
|
mod persist;
|
||||||
|
pub mod relay_debug;
|
||||||
pub mod relayspec;
|
pub mod relayspec;
|
||||||
mod result;
|
mod result;
|
||||||
pub mod storage;
|
pub mod storage;
|
||||||
@@ -34,6 +35,7 @@ pub use muted::{MuteFun, Muted};
|
|||||||
pub use note::{NoteRef, RootIdError, RootNoteId, RootNoteIdBuf};
|
pub use note::{NoteRef, RootIdError, RootNoteId, RootNoteIdBuf};
|
||||||
pub use notecache::{CachedNote, NoteCache};
|
pub use notecache::{CachedNote, NoteCache};
|
||||||
pub use persist::*;
|
pub use persist::*;
|
||||||
|
pub use relay_debug::RelayDebugView;
|
||||||
pub use relayspec::RelaySpec;
|
pub use relayspec::RelaySpec;
|
||||||
pub use result::Result;
|
pub use result::Result;
|
||||||
pub use storage::{
|
pub use storage::{
|
||||||
|
|||||||
@@ -60,6 +60,19 @@ pub async fn android_main(app: AndroidApp) {
|
|||||||
setup_chrome(ctx, ¬edeck.args(), notedeck.theme());
|
setup_chrome(ctx, ¬edeck.args(), notedeck.theme());
|
||||||
|
|
||||||
let damus = Damus::new(&mut notedeck.app_context(), &app_args);
|
let damus = Damus::new(&mut notedeck.app_context(), &app_args);
|
||||||
|
|
||||||
|
// ensure we recognized all the arguments
|
||||||
|
let completely_unrecognized: Vec<String> = notedeck
|
||||||
|
.unrecognized_args()
|
||||||
|
.intersection(damus.unrecognized_args())
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
assert!(
|
||||||
|
completely_unrecognized.is_empty(),
|
||||||
|
"unrecognized args: {:?}",
|
||||||
|
completely_unrecognized
|
||||||
|
);
|
||||||
|
|
||||||
notedeck.set_app(damus);
|
notedeck.set_app(damus);
|
||||||
|
|
||||||
Ok(Box::new(notedeck))
|
Ok(Box::new(notedeck))
|
||||||
|
|||||||
@@ -82,6 +82,19 @@ async fn main() {
|
|||||||
setup_chrome(ctx, notedeck.args(), notedeck.theme());
|
setup_chrome(ctx, notedeck.args(), notedeck.theme());
|
||||||
|
|
||||||
let damus = Damus::new(&mut notedeck.app_context(), &args);
|
let damus = Damus::new(&mut notedeck.app_context(), &args);
|
||||||
|
|
||||||
|
// ensure we recognized all the arguments
|
||||||
|
let completely_unrecognized: Vec<String> = 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
|
// TODO: move "chrome" frame over Damus app somehow
|
||||||
notedeck.set_app(damus);
|
notedeck.set_app(damus);
|
||||||
|
|
||||||
@@ -135,7 +148,7 @@ mod tests {
|
|||||||
async fn test_dbpath() {
|
async fn test_dbpath() {
|
||||||
let datapath = create_tmp_dir();
|
let datapath = create_tmp_dir();
|
||||||
let dbpath = create_tmp_dir();
|
let dbpath = create_tmp_dir();
|
||||||
let args: Vec<String> = vec![
|
let args: Vec<String> = [
|
||||||
"--testrunner",
|
"--testrunner",
|
||||||
"--datapath",
|
"--datapath",
|
||||||
&datapath.to_str().unwrap(),
|
&datapath.to_str().unwrap(),
|
||||||
@@ -161,7 +174,7 @@ mod tests {
|
|||||||
async fn test_column_args() {
|
async fn test_column_args() {
|
||||||
let tmpdir = create_tmp_dir();
|
let tmpdir = create_tmp_dir();
|
||||||
let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s";
|
let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s";
|
||||||
let args: Vec<String> = vec![
|
let args: Vec<String> = [
|
||||||
"--testrunner",
|
"--testrunner",
|
||||||
"--no-keystore",
|
"--no-keystore",
|
||||||
"--pub",
|
"--pub",
|
||||||
@@ -177,9 +190,21 @@ mod tests {
|
|||||||
|
|
||||||
let ctx = egui::Context::default();
|
let ctx = egui::Context::default();
|
||||||
let mut notedeck = Notedeck::new(&ctx, &tmpdir, &args);
|
let mut notedeck = Notedeck::new(&ctx, &tmpdir, &args);
|
||||||
|
let unrecognized_args = notedeck.unrecognized_args().clone();
|
||||||
let mut app_ctx = notedeck.app_context();
|
let mut app_ctx = notedeck.app_context();
|
||||||
let app = Damus::new(&mut app_ctx, &args);
|
let app = Damus::new(&mut app_ctx, &args);
|
||||||
|
|
||||||
|
// ensure we recognized all the arguments
|
||||||
|
let completely_unrecognized: Vec<String> = 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);
|
assert_eq!(app.columns(app_ctx.accounts).columns().len(), 2);
|
||||||
|
|
||||||
let tl1 = app
|
let tl1 = app
|
||||||
@@ -204,4 +229,39 @@ mod tests {
|
|||||||
|
|
||||||
rmrf(tmpdir);
|
rmrf(tmpdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_unknown_args() {
|
||||||
|
let tmpdir = create_tmp_dir();
|
||||||
|
let npub = "npub1xtscya34g58tk0z605fvr788k263gsu6cy9x0mhnm87echrgufzsevkk5s";
|
||||||
|
let args: Vec<String> = [
|
||||||
|
"--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<String> = notedeck
|
||||||
|
.unrecognized_args()
|
||||||
|
.intersection(app.unrecognized_args())
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
assert_eq!(completely_unrecognized, ["--unknown-arg"]);
|
||||||
|
|
||||||
|
rmrf(tmpdir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ impl PreviewRunner {
|
|||||||
let ctx = &cc.egui_ctx;
|
let ctx = &cc.egui_ctx;
|
||||||
|
|
||||||
let mut notedeck = Notedeck::new(ctx, &base_path, &args);
|
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());
|
setup_chrome(ctx, notedeck.args(), notedeck.theme());
|
||||||
|
|
||||||
notedeck.set_app(PreviewApp::new(preview));
|
notedeck.set_app(PreviewApp::new(preview));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use egui_extras::{Size, StripBuilder};
|
|||||||
|
|
||||||
use nostrdb::{Ndb, Transaction};
|
use nostrdb::{Ndb, Transaction};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::{BTreeSet, HashMap};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{debug, error, info, trace, warn};
|
use tracing::{debug, error, info, trace, warn};
|
||||||
@@ -51,6 +51,8 @@ pub struct Damus {
|
|||||||
pub debug: bool,
|
pub debug: bool,
|
||||||
pub since_optimize: bool,
|
pub since_optimize: bool,
|
||||||
pub textmode: bool,
|
pub textmode: bool,
|
||||||
|
|
||||||
|
pub unrecognized_args: BTreeSet<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_key_events(input: &egui::InputState, columns: &mut Columns) {
|
fn handle_key_events(input: &egui::InputState, columns: &mut Columns) {
|
||||||
@@ -358,7 +360,7 @@ impl Damus {
|
|||||||
pub fn new(ctx: &mut AppContext<'_>, args: &[String]) -> Self {
|
pub fn new(ctx: &mut AppContext<'_>, args: &[String]) -> Self {
|
||||||
// arg parsing
|
// arg parsing
|
||||||
|
|
||||||
let parsed_args = ColumnsArgs::parse(
|
let (parsed_args, unrecognized_args) = ColumnsArgs::parse(
|
||||||
args,
|
args,
|
||||||
ctx.accounts
|
ctx.accounts
|
||||||
.get_selected_account()
|
.get_selected_account()
|
||||||
@@ -434,6 +436,7 @@ impl Damus {
|
|||||||
support,
|
support,
|
||||||
decks_cache,
|
decks_cache,
|
||||||
debug,
|
debug,
|
||||||
|
unrecognized_args,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,12 +479,17 @@ impl Damus {
|
|||||||
view_state: ViewState::default(),
|
view_state: ViewState::default(),
|
||||||
support,
|
support,
|
||||||
decks_cache,
|
decks_cache,
|
||||||
|
unrecognized_args: BTreeSet::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn subscriptions(&mut self) -> &mut HashMap<String, SubKind> {
|
pub fn subscriptions(&mut self) -> &mut HashMap<String, SubKind> {
|
||||||
&mut self.subscriptions.subs
|
&mut self.subscriptions.subs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unrecognized_args(&self) -> &BTreeSet<String> {
|
||||||
|
&self.unrecognized_args
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
use crate::timeline::TimelineKind;
|
use crate::timeline::TimelineKind;
|
||||||
use enostr::{Filter, Pubkey};
|
use enostr::{Filter, Pubkey};
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
@@ -9,7 +11,8 @@ pub struct ColumnsArgs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ColumnsArgs {
|
impl ColumnsArgs {
|
||||||
pub fn parse(args: &[String], deck_author: Option<&Pubkey>) -> Self {
|
pub fn parse(args: &[String], deck_author: Option<&Pubkey>) -> (Self, BTreeSet<String>) {
|
||||||
|
let mut unrecognized_args = BTreeSet::new();
|
||||||
let mut res = Self {
|
let mut res = Self {
|
||||||
columns: vec![],
|
columns: vec![],
|
||||||
since_optimize: true,
|
since_optimize: true,
|
||||||
@@ -132,12 +135,14 @@ impl ColumnsArgs {
|
|||||||
} else {
|
} else {
|
||||||
error!("failed to parse filter in '{}'", filter_file);
|
error!("failed to parse filter in '{}'", filter_file);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
unrecognized_args.insert(arg.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
(res, unrecognized_args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use notedeck::NoteCache;
|
|||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Column {
|
pub struct Column {
|
||||||
router: Router<Route>,
|
router: Router<Route>,
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ impl Column {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug)]
|
||||||
pub struct Columns {
|
pub struct Columns {
|
||||||
/// Columns are simply routers into settings, timelines, etc
|
/// Columns are simply routers into settings, timelines, etc
|
||||||
columns: Vec<Column>,
|
columns: Vec<Column>,
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ impl Route {
|
|||||||
|
|
||||||
// TODO: add this to egui-nav so we don't have to deal with returning
|
// TODO: add this to egui-nav so we don't have to deal with returning
|
||||||
// and navigating headaches
|
// and navigating headaches
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Router<R: Clone> {
|
pub struct Router<R: Clone> {
|
||||||
routes: Vec<R>,
|
routes: Vec<R>,
|
||||||
pub returning: bool,
|
pub returning: bool,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ pub mod note;
|
|||||||
pub mod preview;
|
pub mod preview;
|
||||||
pub mod profile;
|
pub mod profile;
|
||||||
pub mod relay;
|
pub mod relay;
|
||||||
pub mod relay_debug;
|
|
||||||
pub mod search_results;
|
pub mod search_results;
|
||||||
pub mod side_panel;
|
pub mod side_panel;
|
||||||
pub mod support;
|
pub mod support;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ mkShell ({
|
|||||||
cmdline-tools-latest
|
cmdline-tools-latest
|
||||||
build-tools-34-0-0
|
build-tools-34-0-0
|
||||||
platform-tools
|
platform-tools
|
||||||
platforms-android-31
|
platforms-android-30
|
||||||
ndk-27-2-12479018
|
ndk-27-2-12479018
|
||||||
#ndk-24-0-8215888
|
#ndk-24-0-8215888
|
||||||
] ++ lib.optional android_emulator [ emulator ]);
|
] ++ lib.optional android_emulator [ emulator ]);
|
||||||
|
|||||||
Reference in New Issue
Block a user