feat(settings): persist settings to storage

This commit is contained in:
Fernando López Guevara
2025-07-29 21:02:18 -03:00
parent 0fc8e70180
commit 0dcf70bc15
4 changed files with 29 additions and 33 deletions

View File

@@ -10,13 +10,11 @@ use crate::{
subscriptions::{SubKind, Subscriptions}, subscriptions::{SubKind, Subscriptions},
support::Support, support::Support,
timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind}, timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind},
ui::{self, DesktopSidePanel, SidePanelAction}, ui::{self, DesktopSidePanel, ShowSourceClientOption, SidePanelAction},
view_state::ViewState, view_state::ViewState,
Result, Result,
}; };
use crate::ui::settings::ShowNoteClientOption;
use egui_extras::{Size, StripBuilder}; use egui_extras::{Size, StripBuilder};
use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool}; use enostr::{ClientMessage, PoolRelay, Pubkey, RelayEvent, RelayMessage, RelayPool};
use nostrdb::Transaction; use nostrdb::Transaction;
@@ -506,12 +504,12 @@ impl Damus {
); );
note_options.set( note_options.set(
NoteOptions::ShowNoteClientTop, 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), || parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientTop),
); );
note_options.set( note_options.set(
NoteOptions::ShowNoteClientBottom, NoteOptions::ShowNoteClientBottom,
ShowNoteClientOption::Bottom ShowSourceClientOption::Bottom
== app_context.settings_handler.show_source_client().into() == app_context.settings_handler.show_source_client().into()
|| parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientBottom), || parsed_args.is_flag_set(ColumnsFlag::ShowNoteClientBottom),
); );

View File

@@ -21,7 +21,7 @@ use crate::{
note::{custom_zap::CustomZapView, NewPostAction, PostAction, PostType, QuoteRepostView}, note::{custom_zap::CustomZapView, NewPostAction, PostAction, PostType, QuoteRepostView},
profile::EditProfileView, profile::EditProfileView,
search::{FocusState, SearchView}, search::{FocusState, SearchView},
settings::SettingsAction, settings::{SettingsAction, ShowSourceClientOption},
support::SupportView, support::SupportView,
wallet::{get_default_zap_state, WalletAction, WalletState, WalletView}, wallet::{get_default_zap_state, WalletAction, WalletState, WalletView},
AccountsView, PostReplyView, PostView, ProfileView, RelayView, SettingsView, ThreadView, AccountsView, PostReplyView, PostView, ProfileView, RelayView, SettingsView, ThreadView,
@@ -30,8 +30,6 @@ use crate::{
Damus, Damus,
}; };
use crate::ui::settings::ShowNoteClientOption;
use egui_nav::{Nav, NavAction, NavResponse, NavUiType, Percent, PopupResponse, PopupSheet}; use egui_nav::{Nav, NavAction, NavResponse, NavUiType, Percent, PopupResponse, PopupSheet};
use enostr::ProfileState; use enostr::ProfileState;
use nostrdb::{Filter, Ndb, Transaction}; use nostrdb::{Filter, Ndb, Transaction};
@@ -588,7 +586,7 @@ fn render_nav_body(
.map(RenderNavAction::RelayAction), .map(RenderNavAction::RelayAction),
Route::Settings => { 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 { let mut theme: String = (if ui.visuals().dark_mode {
"Dark" "Dark"

View File

@@ -26,7 +26,7 @@ pub use preview::{Preview, PreviewApp, PreviewConfig};
pub use profile::ProfileView; pub use profile::ProfileView;
pub use relay::RelayView; pub use relay::RelayView;
pub use settings::SettingsView; pub use settings::SettingsView;
pub use settings::ShowNoteClientOption; pub use settings::ShowSourceClientOption;
pub use side_panel::{DesktopSidePanel, SidePanelAction}; pub use side_panel::{DesktopSidePanel, SidePanelAction};
pub use thread::ThreadView; pub use thread::ThreadView;
pub use timeline::TimelineView; pub use timeline::TimelineView;

View File

@@ -6,35 +6,35 @@ use strum::Display;
use crate::{nav::RouterAction, Damus, Route}; use crate::{nav::RouterAction, Damus, Route};
#[derive(Clone, Copy, PartialEq, Eq, Display)] #[derive(Clone, Copy, PartialEq, Eq, Display)]
pub enum ShowNoteClientOption { pub enum ShowSourceClientOption {
Hide, Hide,
Top, Top,
Bottom, Bottom,
} }
impl From<ShowNoteClientOption> for String { impl Into<String> for ShowSourceClientOption {
fn from(value: ShowNoteClientOption) -> Self { fn into(self) -> String {
match value { match self {
ShowNoteClientOption::Hide => "hide".to_string(), Self::Hide => "hide".to_string(),
ShowNoteClientOption::Top => "top".to_string(), Self::Top => "top".to_string(),
ShowNoteClientOption::Bottom => "bottom".to_string(), Self::Bottom => "bottom".to_string(),
} }
} }
} }
impl From<NoteOptions> for ShowNoteClientOption { impl From<NoteOptions> for ShowSourceClientOption {
fn from(note_options: NoteOptions) -> Self { fn from(note_options: NoteOptions) -> Self {
if note_options.contains(NoteOptions::ShowNoteClientTop) { if note_options.contains(NoteOptions::ShowNoteClientTop) {
ShowNoteClientOption::Top ShowSourceClientOption::Top
} else if note_options.contains(NoteOptions::ShowNoteClientBottom) { } else if note_options.contains(NoteOptions::ShowNoteClientBottom) {
ShowNoteClientOption::Bottom ShowSourceClientOption::Bottom
} else { } else {
ShowNoteClientOption::Hide ShowSourceClientOption::Hide
} }
} }
} }
impl From<String> for ShowNoteClientOption { impl From<String> for ShowSourceClientOption {
fn from(s: String) -> Self { fn from(s: String) -> Self {
match s.to_lowercase().as_str() { match s.to_lowercase().as_str() {
"hide" => Self::Hide, "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) { pub fn set_note_options(self, note_options: &mut NoteOptions) {
match self { match self {
Self::Hide => { Self::Hide => {
@@ -67,7 +67,7 @@ impl ShowNoteClientOption {
pub enum SettingsAction { pub enum SettingsAction {
SetZoomFactor(f32), SetZoomFactor(f32),
SetTheme(ThemePreference), SetTheme(ThemePreference),
SetShowSourceClient(ShowNoteClientOption), SetShowSourceClient(ShowSourceClientOption),
SetLocale(LanguageIdentifier), SetLocale(LanguageIdentifier),
OpenRelays, OpenRelays,
OpenCacheFolder, OpenCacheFolder,
@@ -125,7 +125,7 @@ impl SettingsAction {
pub struct SettingsView<'a> { pub struct SettingsView<'a> {
theme: &'a mut String, theme: &'a mut String,
selected_language: &'a mut String, selected_language: &'a mut String,
show_note_client: &'a mut ShowNoteClientOption, show_note_client: &'a mut ShowSourceClientOption,
i18n: &'a mut Localization, i18n: &'a mut Localization,
img_cache: &'a mut Images, img_cache: &'a mut Images,
} }
@@ -135,7 +135,7 @@ impl<'a> SettingsView<'a> {
img_cache: &'a mut Images, img_cache: &'a mut Images,
selected_language: &'a mut String, selected_language: &'a mut String,
theme: &'a mut String, theme: &'a mut String,
show_note_client: &'a mut ShowNoteClientOption, show_note_client: &'a mut ShowSourceClientOption,
i18n: &'a mut Localization, i18n: &'a mut Localization,
) -> Self { ) -> Self {
Self { Self {
@@ -160,19 +160,19 @@ impl<'a> SettingsView<'a> {
} }
/// Get the localized label for ShowNoteClientOption /// 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 { match option {
ShowNoteClientOption::Hide => tr!( ShowSourceClientOption::Hide => tr!(
self.i18n, self.i18n,
"Hide", "Hide",
"Option in settings section to hide the source client label in note display" "Option in settings section to hide the source client label in note display"
), ),
ShowNoteClientOption::Top => tr!( ShowSourceClientOption::Top => tr!(
self.i18n, self.i18n,
"Top", "Top",
"Option in settings section to show the source client label at the top of the note" "Option in settings section to show the source client label at the top of the note"
), ),
ShowNoteClientOption::Bottom => tr!( ShowSourceClientOption::Bottom => tr!(
self.i18n, self.i18n,
"Bottom", "Bottom",
"Option in settings section to show the source client label at the bottom of the note" "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 [ for option in [
ShowNoteClientOption::Hide, ShowSourceClientOption::Hide,
ShowNoteClientOption::Top, ShowSourceClientOption::Top,
ShowNoteClientOption::Bottom, ShowSourceClientOption::Bottom,
] { ] {
let label = self.get_show_note_client_label(option); let label = self.get_show_note_client_label(option);