notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 0dcf70bc15c04ee22a665587bafba97725e6c799
parent 0fc8e70180a334fd62745380c0431a114678b027
Author: Fernando López Guevara <fernando.lguevara@gmail.com>
Date:   Tue, 29 Jul 2025 21:02:18 -0300

feat(settings): persist settings to storage

Diffstat:
Mcrates/notedeck_columns/src/app.rs | 8+++-----
Mcrates/notedeck_columns/src/nav.rs | 6++----
Mcrates/notedeck_columns/src/ui/mod.rs | 2+-
Mcrates/notedeck_columns/src/ui/settings.rs | 46+++++++++++++++++++++++-----------------------
4 files changed, 29 insertions(+), 33 deletions(-)

diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs @@ -10,13 +10,11 @@ use crate::{ subscriptions::{SubKind, Subscriptions}, support::Support, timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind}, - ui::{self, DesktopSidePanel, SidePanelAction}, + ui::{self, DesktopSidePanel, ShowSourceClientOption, SidePanelAction}, view_state::ViewState, Result, }; -use crate::ui::settings::ShowNoteClientOption; - use egui_extras::{Size, StripBuilder}; use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool}; use nostrdb::Transaction; @@ -506,12 +504,12 @@ impl Damus { ); note_options.set( NoteOptions::ShowNoteClientTop, - ShowNoteClientOption::Top == app_context.settings_handler.show_source_client().into() + ShowSourceClientOption::Top == app_context.settings_handler.show_source_client().into() || parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientTop), ); note_options.set( NoteOptions::ShowNoteClientBottom, - ShowNoteClientOption::Bottom + ShowSourceClientOption::Bottom == app_context.settings_handler.show_source_client().into() || parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientBottom), ); diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs @@ -21,7 +21,7 @@ use crate::{ note::{custom_zap::CustomZapView, NewPostAction, PostAction, PostType, QuoteRepostView}, profile::EditProfileView, search::{FocusState, SearchView}, - settings::SettingsAction, + settings::{SettingsAction, ShowSourceClientOption}, support::SupportView, wallet::{get_default_zap_state, WalletAction, WalletState, WalletView}, AccountsView, PostReplyView, PostView, ProfileView, RelayView, SettingsView, ThreadView, @@ -30,8 +30,6 @@ use crate::{ Damus, }; -use crate::ui::settings::ShowNoteClientOption; - use egui_nav::{Nav, NavAction, NavResponse, NavUiType, Percent, PopupResponse, PopupSheet}; use enostr::ProfileState; use nostrdb::{Filter, Ndb, Transaction}; @@ -588,7 +586,7 @@ fn render_nav_body( .map(RenderNavAction::RelayAction), Route::Settings => { - let mut show_note_client: ShowNoteClientOption = app.note_options.into(); + let mut show_note_client: ShowSourceClientOption = app.note_options.into(); let mut theme: String = (if ui.visuals().dark_mode { "Dark" diff --git a/crates/notedeck_columns/src/ui/mod.rs b/crates/notedeck_columns/src/ui/mod.rs @@ -26,7 +26,7 @@ pub use preview::{Preview, PreviewApp, PreviewConfig}; pub use profile::ProfileView; pub use relay::RelayView; pub use settings::SettingsView; -pub use settings::ShowNoteClientOption; +pub use settings::ShowSourceClientOption; pub use side_panel::{DesktopSidePanel, SidePanelAction}; pub use thread::ThreadView; pub use timeline::TimelineView; diff --git a/crates/notedeck_columns/src/ui/settings.rs b/crates/notedeck_columns/src/ui/settings.rs @@ -6,35 +6,35 @@ use strum::Display; use crate::{nav::RouterAction, Damus, Route}; #[derive(Clone, Copy, PartialEq, Eq, Display)] -pub enum ShowNoteClientOption { +pub enum ShowSourceClientOption { Hide, Top, Bottom, } -impl From<ShowNoteClientOption> for String { - fn from(value: ShowNoteClientOption) -> Self { - match value { - ShowNoteClientOption::Hide => "hide".to_string(), - ShowNoteClientOption::Top => "top".to_string(), - ShowNoteClientOption::Bottom => "bottom".to_string(), +impl Into<String> for ShowSourceClientOption { + fn into(self) -> String { + match self { + Self::Hide => "hide".to_string(), + Self::Top => "top".to_string(), + Self::Bottom => "bottom".to_string(), } } } -impl From<NoteOptions> for ShowNoteClientOption { +impl From<NoteOptions> for ShowSourceClientOption { fn from(note_options: NoteOptions) -> Self { if note_options.contains(NoteOptions::ShowNoteClientTop) { - ShowNoteClientOption::Top + ShowSourceClientOption::Top } else if note_options.contains(NoteOptions::ShowNoteClientBottom) { - ShowNoteClientOption::Bottom + ShowSourceClientOption::Bottom } else { - ShowNoteClientOption::Hide + ShowSourceClientOption::Hide } } } -impl From<String> for ShowNoteClientOption { +impl From<String> for ShowSourceClientOption { fn from(s: String) -> Self { match s.to_lowercase().as_str() { "hide" => Self::Hide, @@ -45,7 +45,7 @@ impl From<String> for ShowNoteClientOption { } } -impl ShowNoteClientOption { +impl ShowSourceClientOption { pub fn set_note_options(self, note_options: &mut NoteOptions) { match self { Self::Hide => { @@ -67,7 +67,7 @@ impl ShowNoteClientOption { pub enum SettingsAction { SetZoomFactor(f32), SetTheme(ThemePreference), - SetShowSourceClient(ShowNoteClientOption), + SetShowSourceClient(ShowSourceClientOption), SetLocale(LanguageIdentifier), OpenRelays, OpenCacheFolder, @@ -125,7 +125,7 @@ impl SettingsAction { pub struct SettingsView<'a> { theme: &'a mut String, selected_language: &'a mut String, - show_note_client: &'a mut ShowNoteClientOption, + show_note_client: &'a mut ShowSourceClientOption, i18n: &'a mut Localization, img_cache: &'a mut Images, } @@ -135,7 +135,7 @@ impl<'a> SettingsView<'a> { img_cache: &'a mut Images, selected_language: &'a mut String, theme: &'a mut String, - show_note_client: &'a mut ShowNoteClientOption, + show_note_client: &'a mut ShowSourceClientOption, i18n: &'a mut Localization, ) -> Self { Self { @@ -160,19 +160,19 @@ impl<'a> SettingsView<'a> { } /// Get the localized label for ShowNoteClientOption - fn get_show_note_client_label(&mut self, option: ShowNoteClientOption) -> String { + fn get_show_note_client_label(&mut self, option: ShowSourceClientOption) -> String { match option { - ShowNoteClientOption::Hide => tr!( + ShowSourceClientOption::Hide => tr!( self.i18n, "Hide", "Option in settings section to hide the source client label in note display" ), - ShowNoteClientOption::Top => tr!( + ShowSourceClientOption::Top => tr!( self.i18n, "Top", "Option in settings section to show the source client label at the top of the note" ), - ShowNoteClientOption::Bottom => tr!( + ShowSourceClientOption::Bottom => tr!( self.i18n, "Bottom", "Option in settings section to show the source client label at the bottom of the note" @@ -463,9 +463,9 @@ impl<'a> SettingsView<'a> { ); for option in [ - ShowNoteClientOption::Hide, - ShowNoteClientOption::Top, - ShowNoteClientOption::Bottom, + ShowSourceClientOption::Hide, + ShowSourceClientOption::Top, + ShowSourceClientOption::Bottom, ] { let label = self.get_show_note_client_label(option);