columns: switch to bitflag app options
we're adding a ScrollToTop bool for an updating change to the toolbar, but we have too many flags now. Let's switch to bitflags Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -4,6 +4,7 @@ use crate::{
|
|||||||
decks::{Decks, DecksCache},
|
decks::{Decks, DecksCache},
|
||||||
draft::Drafts,
|
draft::Drafts,
|
||||||
nav::{self, ProcessNavResult},
|
nav::{self, ProcessNavResult},
|
||||||
|
options::AppOptions,
|
||||||
route::Route,
|
route::Route,
|
||||||
storage,
|
storage,
|
||||||
subscriptions::{SubKind, Subscriptions},
|
subscriptions::{SubKind, Subscriptions},
|
||||||
@@ -14,22 +15,18 @@ use crate::{
|
|||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use egui_extras::{Size, StripBuilder};
|
||||||
|
use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool};
|
||||||
|
use nostrdb::Transaction;
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
ui::is_narrow, Accounts, AppAction, AppContext, DataPath, DataPathType, FilterState, UnknownIds,
|
ui::is_narrow, Accounts, AppAction, AppContext, DataPath, DataPathType, FilterState, UnknownIds,
|
||||||
};
|
};
|
||||||
use notedeck_ui::{jobs::JobsCache, NoteOptions};
|
use notedeck_ui::{jobs::JobsCache, NoteOptions};
|
||||||
|
|
||||||
use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool};
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
use egui_extras::{Size, StripBuilder};
|
|
||||||
|
|
||||||
use nostrdb::Transaction;
|
|
||||||
|
|
||||||
use std::collections::{BTreeSet, 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};
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum DamusState {
|
pub enum DamusState {
|
||||||
@@ -53,9 +50,7 @@ pub struct Damus {
|
|||||||
|
|
||||||
// TODO: make these bitflags
|
// TODO: make these bitflags
|
||||||
/// Were columns loaded from the commandline? If so disable persistence.
|
/// Were columns loaded from the commandline? If so disable persistence.
|
||||||
pub tmp_columns: bool,
|
pub options: AppOptions,
|
||||||
pub debug: bool,
|
|
||||||
pub since_optimize: bool,
|
|
||||||
pub note_options: NoteOptions,
|
pub note_options: NoteOptions,
|
||||||
|
|
||||||
pub unrecognized_args: BTreeSet<String>,
|
pub unrecognized_args: BTreeSet<String>,
|
||||||
@@ -117,7 +112,7 @@ fn try_process_event(
|
|||||||
.send_initial_filters(app_ctx.pool, &ev.relay);
|
.send_initial_filters(app_ctx.pool, &ev.relay);
|
||||||
|
|
||||||
timeline::send_initial_timeline_filters(
|
timeline::send_initial_timeline_filters(
|
||||||
damus.since_optimize,
|
damus.options.contains(AppOptions::SinceOptimize),
|
||||||
&mut damus.timeline_cache,
|
&mut damus.timeline_cache,
|
||||||
&mut damus.subscriptions,
|
&mut damus.subscriptions,
|
||||||
app_ctx.pool,
|
app_ctx.pool,
|
||||||
@@ -394,7 +389,10 @@ impl Damus {
|
|||||||
let account = ctx.accounts.selected_account_pubkey_bytes();
|
let account = ctx.accounts.selected_account_pubkey_bytes();
|
||||||
|
|
||||||
let mut timeline_cache = TimelineCache::default();
|
let mut timeline_cache = TimelineCache::default();
|
||||||
|
let mut options = AppOptions::default();
|
||||||
let tmp_columns = !parsed_args.columns.is_empty();
|
let tmp_columns = !parsed_args.columns.is_empty();
|
||||||
|
options.set(AppOptions::TmpColumns, tmp_columns);
|
||||||
|
|
||||||
let decks_cache = if tmp_columns {
|
let decks_cache = if tmp_columns {
|
||||||
info!("DecksCache: loading from command line arguments");
|
info!("DecksCache: loading from command line arguments");
|
||||||
let mut columns: Columns = Columns::new();
|
let mut columns: Columns = Columns::new();
|
||||||
@@ -436,7 +434,6 @@ impl Damus {
|
|||||||
//}
|
//}
|
||||||
};
|
};
|
||||||
|
|
||||||
let debug = ctx.args.debug;
|
|
||||||
let support = Support::new(ctx.path);
|
let support = Support::new(ctx.path);
|
||||||
let mut note_options = NoteOptions::default();
|
let mut note_options = NoteOptions::default();
|
||||||
note_options.set(
|
note_options.set(
|
||||||
@@ -451,6 +448,11 @@ impl Damus {
|
|||||||
NoteOptions::HideMedia,
|
NoteOptions::HideMedia,
|
||||||
parsed_args.is_flag_set(ColumnsFlag::NoMedia),
|
parsed_args.is_flag_set(ColumnsFlag::NoMedia),
|
||||||
);
|
);
|
||||||
|
options.set(AppOptions::Debug, ctx.args.debug);
|
||||||
|
options.set(
|
||||||
|
AppOptions::SinceOptimize,
|
||||||
|
parsed_args.is_flag_set(ColumnsFlag::SinceOptimize),
|
||||||
|
);
|
||||||
|
|
||||||
let jobs = JobsCache::default();
|
let jobs = JobsCache::default();
|
||||||
|
|
||||||
@@ -458,23 +460,27 @@ impl Damus {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
subscriptions: Subscriptions::default(),
|
subscriptions: Subscriptions::default(),
|
||||||
since_optimize: parsed_args.is_flag_set(ColumnsFlag::SinceOptimize),
|
|
||||||
timeline_cache,
|
timeline_cache,
|
||||||
drafts: Drafts::default(),
|
drafts: Drafts::default(),
|
||||||
state: DamusState::Initializing,
|
state: DamusState::Initializing,
|
||||||
note_options,
|
note_options,
|
||||||
|
options,
|
||||||
//frame_history: FrameHistory::default(),
|
//frame_history: FrameHistory::default(),
|
||||||
view_state: ViewState::default(),
|
view_state: ViewState::default(),
|
||||||
tmp_columns,
|
|
||||||
support,
|
support,
|
||||||
decks_cache,
|
decks_cache,
|
||||||
debug,
|
|
||||||
unrecognized_args,
|
unrecognized_args,
|
||||||
jobs,
|
jobs,
|
||||||
threads,
|
threads,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Scroll to the top of the currently selected column. This is called
|
||||||
|
/// by the chrome when you click the toolbar
|
||||||
|
pub fn scroll_to_top(&mut self) {
|
||||||
|
self.options.insert(AppOptions::ScrollToTop)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn columns_mut(&mut self, accounts: &Accounts) -> &mut Columns {
|
pub fn columns_mut(&mut self, accounts: &Accounts) -> &mut Columns {
|
||||||
get_active_columns_mut(accounts, &mut self.decks_cache)
|
get_active_columns_mut(accounts, &mut self.decks_cache)
|
||||||
}
|
}
|
||||||
@@ -484,7 +490,7 @@ impl Damus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn gen_subid(&self, kind: &SubKind) -> String {
|
pub fn gen_subid(&self, kind: &SubKind) -> String {
|
||||||
if self.debug {
|
if self.options.contains(AppOptions::Debug) {
|
||||||
format!("{:?}", kind)
|
format!("{:?}", kind)
|
||||||
} else {
|
} else {
|
||||||
Uuid::new_v4().to_string()
|
Uuid::new_v4().to_string()
|
||||||
@@ -497,22 +503,20 @@ impl Damus {
|
|||||||
let path = DataPath::new(&data_path);
|
let path = DataPath::new(&data_path);
|
||||||
let imgcache_dir = path.path(DataPathType::Cache);
|
let imgcache_dir = path.path(DataPathType::Cache);
|
||||||
let _ = std::fs::create_dir_all(imgcache_dir.clone());
|
let _ = std::fs::create_dir_all(imgcache_dir.clone());
|
||||||
let debug = true;
|
let options = AppOptions::default() | AppOptions::Debug | AppOptions::TmpColumns;
|
||||||
|
|
||||||
let support = Support::new(&path);
|
let support = Support::new(&path);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
debug,
|
|
||||||
subscriptions: Subscriptions::default(),
|
subscriptions: Subscriptions::default(),
|
||||||
since_optimize: true,
|
|
||||||
timeline_cache: TimelineCache::default(),
|
timeline_cache: TimelineCache::default(),
|
||||||
drafts: Drafts::default(),
|
drafts: Drafts::default(),
|
||||||
state: DamusState::Initializing,
|
state: DamusState::Initializing,
|
||||||
note_options: NoteOptions::default(),
|
note_options: NoteOptions::default(),
|
||||||
tmp_columns: true,
|
|
||||||
//frame_history: FrameHistory::default(),
|
//frame_history: FrameHistory::default(),
|
||||||
view_state: ViewState::default(),
|
view_state: ViewState::default(),
|
||||||
support,
|
support,
|
||||||
|
options,
|
||||||
decks_cache,
|
decks_cache,
|
||||||
unrecognized_args: BTreeSet::default(),
|
unrecognized_args: BTreeSet::default(),
|
||||||
jobs: JobsCache::default(),
|
jobs: JobsCache::default(),
|
||||||
@@ -562,7 +566,7 @@ fn render_damus_mobile(
|
|||||||
if let Some(r) = &r {
|
if let Some(r) = &r {
|
||||||
match r {
|
match r {
|
||||||
ProcessNavResult::SwitchOccurred => {
|
ProcessNavResult::SwitchOccurred => {
|
||||||
if !app.tmp_columns {
|
if !app.options.contains(AppOptions::TmpColumns) {
|
||||||
storage::save_decks_cache(app_ctx.path, &app.decks_cache);
|
storage::save_decks_cache(app_ctx.path, &app.decks_cache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -782,7 +786,7 @@ fn timelines_view(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.tmp_columns {
|
if app.options.contains(AppOptions::TmpColumns) {
|
||||||
save_cols = false;
|
save_cols = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub mod login_manager;
|
|||||||
mod media_upload;
|
mod media_upload;
|
||||||
mod multi_subscriber;
|
mod multi_subscriber;
|
||||||
mod nav;
|
mod nav;
|
||||||
|
pub mod options;
|
||||||
mod post;
|
mod post;
|
||||||
mod profile;
|
mod profile;
|
||||||
mod route;
|
mod route;
|
||||||
|
|||||||
26
crates/notedeck_columns/src/options.rs
Normal file
26
crates/notedeck_columns/src/options.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
// Attributes can be applied to flags types
|
||||||
|
#[repr(transparent)]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct AppOptions: u64 {
|
||||||
|
/// Explicitly enable/disable column persistence for the sessions
|
||||||
|
const TmpColumns = 1 << 0;
|
||||||
|
|
||||||
|
/// Debug mode for debug ui controls
|
||||||
|
const Debug = 1 << 1;
|
||||||
|
|
||||||
|
/// Should we explicitly disable since optimization?
|
||||||
|
const SinceOptimize = 1 << 2;
|
||||||
|
|
||||||
|
/// Should we scroll to top on the active column?
|
||||||
|
const ScrollToTop = 1 << 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppOptions {
|
||||||
|
fn default() -> AppOptions {
|
||||||
|
AppOptions::SinceOptimize
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ use tracing::error;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
login_manager::AcquireKeyState,
|
login_manager::AcquireKeyState,
|
||||||
|
options::AppOptions,
|
||||||
route::Route,
|
route::Route,
|
||||||
timeline::{kind::ListKind, PubkeySource, TimelineKind},
|
timeline::{kind::ListKind, PubkeySource, TimelineKind},
|
||||||
Damus,
|
Damus,
|
||||||
@@ -622,7 +623,7 @@ pub fn render_add_column_routes(
|
|||||||
&mut app.subscriptions,
|
&mut app.subscriptions,
|
||||||
ctx.pool,
|
ctx.pool,
|
||||||
ctx.note_cache,
|
ctx.note_cache,
|
||||||
app.since_optimize,
|
app.options.contains(AppOptions::SinceOptimize),
|
||||||
ctx.accounts,
|
ctx.accounts,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -664,7 +665,7 @@ pub fn render_add_column_routes(
|
|||||||
&mut app.subscriptions,
|
&mut app.subscriptions,
|
||||||
ctx.pool,
|
ctx.pool,
|
||||||
ctx.note_cache,
|
ctx.note_cache,
|
||||||
app.since_optimize,
|
app.options.contains(AppOptions::SinceOptimize),
|
||||||
ctx.accounts,
|
ctx.accounts,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user