mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
use the new dark mode settings
This commit is contained in:
parent
b2d2e4e363
commit
020850c5cb
4 changed files with 24 additions and 11 deletions
|
@ -15,7 +15,7 @@
|
|||
<property name="icon-name">applications-system-symbolic</property>
|
||||
<property name="title" translatable="yes">General</property>
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<object class="AdwPreferencesGroup" id="dark_theme_group">
|
||||
<property name="title" translatable="yes">Appearance</property>
|
||||
<child>
|
||||
<object class="AdwActionRow">
|
||||
|
|
|
@ -3,9 +3,10 @@ use crate::{
|
|||
models::{Keyring, ProvidersModel, FAVICONS_PATH},
|
||||
widgets::{PreferencesWindow, ProvidersDialog, Window},
|
||||
};
|
||||
use adw::prelude::*;
|
||||
use gettextrs::gettext;
|
||||
use glib::clone;
|
||||
use gtk::{gio, glib, prelude::*, subclass::prelude::*};
|
||||
use gtk::{gio, glib, subclass::prelude::*};
|
||||
use gtk_macros::{action, get_action};
|
||||
|
||||
mod imp {
|
||||
|
@ -196,10 +197,12 @@ mod imp {
|
|||
}
|
||||
},
|
||||
"auto-lock-timeout" => app.restart_lock_timeout(),
|
||||
"dark-mode" => app.update_color_scheme(),
|
||||
_ => ()
|
||||
}
|
||||
}),
|
||||
);
|
||||
app.update_color_scheme();
|
||||
}
|
||||
|
||||
fn activate(&self, app: &Self::Type) {
|
||||
|
@ -316,4 +319,16 @@ impl Application {
|
|||
id.remove();
|
||||
}
|
||||
}
|
||||
|
||||
fn update_color_scheme(&self) {
|
||||
let manager = self.style_manager();
|
||||
if !manager.system_supports_color_schemes() {
|
||||
let color_scheme = if self.imp().settings.boolean("dark-mode") {
|
||||
adw::ColorScheme::PreferDark
|
||||
} else {
|
||||
adw::ColorScheme::PreferLight
|
||||
};
|
||||
manager.set_color_scheme(color_scheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ mod imp {
|
|||
pub auto_lock: TemplateChild<gtk::Switch>,
|
||||
#[template_child(id = "dark_theme_switch")]
|
||||
pub dark_theme: TemplateChild<gtk::Switch>,
|
||||
#[template_child]
|
||||
pub dark_theme_group: TemplateChild<adw::PreferencesGroup>,
|
||||
#[template_child(id = "lock_timeout_spin_btn")]
|
||||
pub lock_timeout: TemplateChild<gtk::SpinButton>,
|
||||
}
|
||||
|
@ -71,6 +73,7 @@ mod imp {
|
|||
lock_timeout: TemplateChild::default(),
|
||||
backup_group: TemplateChild::default(),
|
||||
restore_group: TemplateChild::default(),
|
||||
dark_theme_group: TemplateChild::default(),
|
||||
file_chooser: RefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
@ -161,6 +164,10 @@ impl PreferencesWindow {
|
|||
fn setup_widgets(&self) {
|
||||
let imp = self.imp();
|
||||
|
||||
let style_manager = adw::StyleManager::default();
|
||||
imp.dark_theme_group
|
||||
.set_visible(!style_manager.system_supports_color_schemes());
|
||||
|
||||
imp.settings
|
||||
.bind("dark-theme", &*imp.dark_theme, "active")
|
||||
.build();
|
||||
|
|
|
@ -250,15 +250,6 @@ impl Window {
|
|||
title_stack.set_visible_child_name("title");
|
||||
}
|
||||
}));
|
||||
|
||||
let gtk_settings = gtk::Settings::default().unwrap();
|
||||
imp.settings
|
||||
.bind(
|
||||
"dark-theme",
|
||||
>k_settings,
|
||||
"gtk-application-prefer-dark-theme",
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
||||
fn setup_actions(&self, app: &Application) {
|
||||
|
|
Loading…
Add table
Reference in a new issue