add NotedeckOptions and feature flags, add notebook feature

This switches from bools to flags in our Args struct. We also add
notebook as an optional feature flag (--notebook) since its not ready.
This commit is contained in:
William Casarin
2025-07-31 16:03:13 -07:00
parent d12e5b363c
commit b1a5dd6cab
11 changed files with 100 additions and 46 deletions

View File

@@ -47,6 +47,7 @@ fluent-langneg = { workspace = true }
unic-langid = { workspace = true }
once_cell = { workspace = true }
md5 = { workspace = true }
bitflags = { workspace = true }
regex = "1"
[dev-dependencies]

View File

@@ -4,6 +4,7 @@ use crate::persist::{AppSizeHandler, SettingsHandler};
use crate::wallet::GlobalWallet;
use crate::zaps::Zaps;
use crate::JobPool;
use crate::NotedeckOptions;
use crate::{
frame_history::FrameHistory, AccountStorage, Accounts, AppContext, Args, DataPath,
DataPathType, Directory, Images, NoteAction, NoteCache, RelayDebugView, UnknownIds,
@@ -109,7 +110,7 @@ impl eframe::App for Notedeck {
});
self.app_size.try_save_app_size(ctx);
if self.args.relay_debug {
if self.args.options.contains(NotedeckOptions::RelayDebug) {
if self.pool.debug.is_none() {
self.pool.use_debug();
}
@@ -170,7 +171,7 @@ impl Notedeck {
let config = Config::new().set_ingester_threads(2).set_mapsize(map_size);
let keystore = if parsed_args.use_keystore {
let keystore = if parsed_args.options.contains(NotedeckOptions::UseKeystore) {
let keys_path = path.path(DataPathType::Keys);
let selected_key_path = path.path(DataPathType::SelectedKey);
Some(AccountStorage::new(
@@ -276,6 +277,10 @@ impl Notedeck {
}
}
pub fn options(&self) -> NotedeckOptions {
self.args.options
}
pub fn app<A: App + 'static>(mut self, app: A) -> Self {
self.set_app(app);
self

View File

@@ -1,23 +1,15 @@
use std::collections::BTreeSet;
use crate::NotedeckOptions;
use enostr::{Keypair, Pubkey, SecretKey};
use tracing::error;
use unic_langid::{LanguageIdentifier, LanguageIdentifierError};
pub struct Args {
pub relays: Vec<String>,
pub is_mobile: Option<bool>,
pub locale: Option<LanguageIdentifier>,
pub show_note_client: bool,
pub keys: Vec<Keypair>,
pub light: bool,
pub debug: bool,
pub relay_debug: bool,
/// Enable when running tests so we don't panic on app startup
pub tests: bool,
pub use_keystore: bool,
pub options: NotedeckOptions,
pub dbpath: Option<String>,
pub datapath: Option<String>,
}
@@ -28,14 +20,8 @@ impl Args {
let mut unrecognized_args = BTreeSet::new();
let mut res = Args {
relays: vec![],
is_mobile: None,
keys: vec![],
light: false,
show_note_client: false,
debug: false,
relay_debug: false,
tests: false,
use_keystore: true,
options: NotedeckOptions::default(),
dbpath: None,
datapath: None,
locale: None,
@@ -47,9 +33,9 @@ impl Args {
let arg = &args[i];
if arg == "--mobile" {
res.is_mobile = Some(true);
res.options.set(NotedeckOptions::Mobile, true);
} else if arg == "--light" {
res.light = true;
res.options.set(NotedeckOptions::LightTheme, true);
} else if arg == "--locale" {
i += 1;
let Some(locale) = args.get(i) else {
@@ -68,11 +54,11 @@ impl Args {
}
}
} else if arg == "--dark" {
res.light = false;
res.options.set(NotedeckOptions::LightTheme, false);
} else if arg == "--debug" {
res.debug = true;
res.options.set(NotedeckOptions::Debug, true);
} else if arg == "--testrunner" {
res.tests = true;
res.options.set(NotedeckOptions::Tests, true);
} else if arg == "--pub" || arg == "--npub" {
i += 1;
let pubstr = if let Some(next_arg) = args.get(i) {
@@ -135,11 +121,13 @@ impl Args {
};
res.relays.push(relay.clone());
} else if arg == "--no-keystore" {
res.use_keystore = false;
res.options.set(NotedeckOptions::UseKeystore, true);
} else if arg == "--relay-debug" {
res.relay_debug = true;
} else if arg == "--show-note-client" {
res.show_note_client = true;
res.options.set(NotedeckOptions::RelayDebug, true);
} else if arg == "--show-client" {
res.options.set(NotedeckOptions::ShowClient, true);
} else if arg == "--notebook" {
res.options.set(NotedeckOptions::FeatureNotebook, true);
} else {
unrecognized_args.insert(arg.clone());
}

View File

@@ -18,6 +18,7 @@ mod muted;
pub mod name;
pub mod note;
mod notecache;
mod options;
mod persist;
pub mod platform;
pub mod profile;
@@ -68,6 +69,7 @@ pub use note::{
RootIdError, RootNoteId, RootNoteIdBuf, ScrollInfo, ZapAction,
};
pub use notecache::{CachedNote, NoteCache};
pub use options::NotedeckOptions;
pub use persist::*;
pub use profile::get_profile_url;
pub use relay_debug::RelayDebugView;

View File

@@ -0,0 +1,39 @@
use bitflags::bitflags;
bitflags! {
#[repr(transparent)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NotedeckOptions: u64 {
// ===== Settings ======
/// Are we on light theme?
const LightTheme = 1 << 0;
/// Debug controls, fps stats
const Debug = 1 << 1;
/// Show relay debug window?
const RelayDebug = 1 << 2;
/// Are we running as tests?
const Tests = 1 << 3;
/// Use keystore?
const UseKeystore = 1 << 4;
/// Show client on notes?
const ShowClient = 1 << 5;
/// Simulate is_compiled_as_mobile ?
const Mobile = 1 << 6;
// ===== Feature Flags ======
/// Is notebook enabled?
const FeatureNotebook = 1 << 32;
}
}
impl Default for NotedeckOptions {
fn default() -> Self {
NotedeckOptions::UseKeystore
}
}