Add preference for restoring your most recent sign in
This commit is contained in:
@@ -186,20 +186,22 @@ impl Component for App {
|
|||||||
|
|
||||||
model.register_actions();
|
model.register_actions();
|
||||||
|
|
||||||
if let Some(MostRecentLogin {
|
if config.general.restore_most_recent_login {
|
||||||
server_id,
|
if let Some(MostRecentLogin {
|
||||||
account_id,
|
server_id,
|
||||||
}) = config.general.most_recent_login
|
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(server) = config.servers.iter().find(|server| server.id == server_id) {
|
||||||
|
sender.input(AppInput::ServerSelected(server.clone()));
|
||||||
|
|
||||||
if let Some(account) = server
|
if let Some(account) = server
|
||||||
.accounts
|
.accounts
|
||||||
.iter()
|
.iter()
|
||||||
.find(|account| account.id == account_id)
|
.find(|account| account.id == account_id)
|
||||||
{
|
{
|
||||||
sender.input(AppInput::AccountSelected(server.clone(), account.clone()));
|
sender.input(AppInput::AccountSelected(server.clone(), account.clone()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,11 +53,24 @@ pub struct MostRecentLogin {
|
|||||||
pub account_id: Uuid,
|
pub account_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
|
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
|
#[serde(default)]
|
||||||
pub struct GeneralConfig {
|
pub struct GeneralConfig {
|
||||||
pub language: Option<LanguageIdentifier>,
|
pub language: Option<LanguageIdentifier>,
|
||||||
pub theme: Theme,
|
pub theme: Theme,
|
||||||
pub most_recent_login: Option<MostRecentLogin>,
|
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 {
|
impl GeneralConfig {
|
||||||
|
@@ -147,6 +147,7 @@ italic = false
|
|||||||
language: None,
|
language: None,
|
||||||
theme: THEME_DARK,
|
theme: THEME_DARK,
|
||||||
most_recent_login: None,
|
most_recent_login: None,
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
video_player: VideoPlayerConfig {
|
video_player: VideoPlayerConfig {
|
||||||
volume: 0.0,
|
volume: 0.0,
|
||||||
|
@@ -18,6 +18,7 @@ pub struct GeneralPreferences;
|
|||||||
pub enum GeneralPreferencesInput {
|
pub enum GeneralPreferencesInput {
|
||||||
Language(Option<String>),
|
Language(Option<String>),
|
||||||
ThemeChanged(u32),
|
ThemeChanged(u32),
|
||||||
|
RestoreMostRecentLogin(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[relm4::component(pub)]
|
#[relm4::component(pub)]
|
||||||
@@ -81,6 +82,15 @@ impl SimpleComponent for GeneralPreferences {
|
|||||||
sender.input(GeneralPreferencesInput::ThemeChanged(cb.selected()));
|
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) => {
|
GeneralPreferencesInput::ThemeChanged(theme) => {
|
||||||
config.general.set_theme(Theme::from(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");
|
config.save().expect("Error saving config");
|
||||||
|
@@ -16,6 +16,10 @@ prefs-general-theme =
|
|||||||
.option-light = Light
|
.option-light = Light
|
||||||
.option-dark = Dark
|
.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
|
# Interface
|
||||||
# =========
|
# =========
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user