Add preference for restoring your most recent sign in

This commit is contained in:
Avery
2024-01-19 15:44:21 -05:00
parent 69c0497e3f
commit fb9e8e064e
5 changed files with 47 additions and 14 deletions

View File

@@ -186,20 +186,22 @@ impl Component for App {
model.register_actions();
if let Some(MostRecentLogin {
server_id,
account_id,
}) = config.general.most_recent_login
{
if let Some(server) = config.servers.iter().find(|server| server.id == server_id) {
sender.input(AppInput::ServerSelected(server.clone()));
if config.general.restore_most_recent_login {
if let Some(MostRecentLogin {
server_id,
account_id,
}) = config.general.most_recent_login
{
if let Some(server) = config.servers.iter().find(|server| server.id == server_id) {
sender.input(AppInput::ServerSelected(server.clone()));
if let Some(account) = server
.accounts
.iter()
.find(|account| account.id == account_id)
{
sender.input(AppInput::AccountSelected(server.clone(), account.clone()));
if let Some(account) = server
.accounts
.iter()
.find(|account| account.id == account_id)
{
sender.input(AppInput::AccountSelected(server.clone(), account.clone()));
}
}
}
}

View File

@@ -53,11 +53,24 @@ pub struct MostRecentLogin {
pub account_id: Uuid,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
#[serde(default)]
pub struct GeneralConfig {
pub language: Option<LanguageIdentifier>,
pub theme: Theme,
pub most_recent_login: Option<MostRecentLogin>,
pub restore_most_recent_login: bool,
}
impl Default for GeneralConfig {
fn default() -> Self {
Self {
language: Option::default(),
theme: Theme::default(),
most_recent_login: Option::default(),
restore_most_recent_login: true,
}
}
}
impl GeneralConfig {

View File

@@ -147,6 +147,7 @@ italic = false
language: None,
theme: THEME_DARK,
most_recent_login: None,
..Default::default()
},
video_player: VideoPlayerConfig {
volume: 0.0,

View File

@@ -18,6 +18,7 @@ pub struct GeneralPreferences;
pub enum GeneralPreferencesInput {
Language(Option<String>),
ThemeChanged(u32),
RestoreMostRecentLogin(bool),
}
#[relm4::component(pub)]
@@ -81,6 +82,15 @@ impl SimpleComponent for GeneralPreferences {
sender.input(GeneralPreferencesInput::ThemeChanged(cb.selected()));
},
},
add = &adw::SwitchRow {
set_title: tr!("prefs-general-restore-most-recent.title"),
set_subtitle: tr!("prefs-general-restore-most-recent.subtitle"),
set_active: general_preferences.restore_most_recent_login,
connect_active_notify[sender] => move |switch| {
sender.input(GeneralPreferencesInput::RestoreMostRecentLogin(switch.is_active()));
},
},
},
}
}
@@ -109,6 +119,9 @@ impl SimpleComponent for GeneralPreferences {
GeneralPreferencesInput::ThemeChanged(theme) => {
config.general.set_theme(Theme::from(theme));
}
GeneralPreferencesInput::RestoreMostRecentLogin(restore_most_recent_login) => {
config.general.restore_most_recent_login = restore_most_recent_login;
}
}
config.save().expect("Error saving config");

View File

@@ -16,6 +16,10 @@ prefs-general-theme =
.option-light = Light
.option-dark = Dark
prefs-general-restore-most-recent =
.title = Sign in automatically when { app-name } starts
.subtitle = On startup, you will be signed in to your most recently used account
# Interface
# =========