Force dark/light theme changing

This commit is contained in:
Igor Sharonov 2024-04-24 18:15:44 +03:00 committed by Maxim Logaev
parent cdabee7f20
commit 5784530204
7 changed files with 10 additions and 17 deletions

View file

@ -25,13 +25,13 @@ public interface Application : GLib.Application {
public abstract void handle_uri(string jid, string query, Gee.Map<string, string> options); public abstract void handle_uri(string jid, string query, Gee.Map<string, string> options);
public void init() throws Error { public void init(bool default_dark_theme) throws Error {
if (DirUtils.create_with_parents(get_storage_dir(), 0700) == -1) { if (DirUtils.create_with_parents(get_storage_dir(), 0700) == -1) {
throw new Error(-1, 0, "Could not create storage dir \"%s\": %s", get_storage_dir(), FileUtils.error_from_errno(errno).to_string()); throw new Error(-1, 0, "Could not create storage dir \"%s\": %s", get_storage_dir(), FileUtils.error_from_errno(errno).to_string());
} }
this.db = new Database(Path.build_filename(get_storage_dir(), "dino.db")); this.db = new Database(Path.build_filename(get_storage_dir(), "dino.db"));
this.settings = new Dino.Entities.Settings.from_db(db); this.settings = new Dino.Entities.Settings.from_db(db, default_dark_theme);
this.stream_interactor = new StreamInteractor(db); this.stream_interactor = new StreamInteractor(db);
MessageProcessor.start(stream_interactor, db); MessageProcessor.start(stream_interactor, db);

View file

@ -4,7 +4,7 @@ public class Settings : Object {
private Database db; private Database db;
public Settings.from_db(Database db) { public Settings.from_db(Database db, bool default_dark_theme) {
this.db = db; this.db = db;
send_typing_ = col_to_bool_or_default("send_typing", true); send_typing_ = col_to_bool_or_default("send_typing", true);
@ -15,7 +15,7 @@ public class Settings : Object {
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN); default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
send_button = col_to_bool_or_default("send_button", false); send_button = col_to_bool_or_default("send_button", false);
enter_newline = col_to_bool_or_default("enter_newline", false); enter_newline = col_to_bool_or_default("enter_newline", false);
dark_theme = col_to_bool_or_default("dark_theme", false); dark_theme = col_to_bool_or_default("dark_theme", default_dark_theme);
} }
private bool col_to_bool_or_default(string key, bool def) { private bool col_to_bool_or_default(string key, bool def) {

View file

@ -145,7 +145,6 @@
<child> <child>
<object class="AdwActionRow"> <object class="AdwActionRow">
<property name="title" translatable="yes">_Dark theme</property> <property name="title" translatable="yes">_Dark theme</property>
<property name="subtitle" translatable="yes">If disabled, use system settings</property>
<property name="use-underline">True</property> <property name="use-underline">True</property>
<property name="activatable-widget">dark_theme</property> <property name="activatable-widget">dark_theme</property>
<child type="suffix"> <child type="suffix">

View file

@ -1054,10 +1054,6 @@ msgstr ""
msgid "_Dark theme" msgid "_Dark theme"
msgstr "" msgstr ""
#: main/data/settings_dialog.ui:148
msgid "If disabled, use system settings"
msgstr ""
#: main/data/im.dino.Dino.appdata.xml.in:7 #: main/data/im.dino.Dino.appdata.xml.in:7
msgid "Modern XMPP Chat Client" msgid "Modern XMPP Chat Client"
msgstr "" msgstr ""

View file

@ -1072,10 +1072,6 @@ msgstr "Если опция недоступна, используйте Shift+E
msgid "_Dark theme" msgid "_Dark theme"
msgstr "Тёмная тема" msgstr "Тёмная тема"
#: main/data/settings_dialog.ui:148
msgid "If disabled, use system settings"
msgstr "Если опция недоступна, используйте настройки системы"
#: main/data/im.dino.Dino.appdata.xml.in:7 #: main/data/im.dino.Dino.appdata.xml.in:7
msgid "Modern XMPP Chat Client" msgid "Modern XMPP Chat Client"
msgstr "Современный XMPP клиент" msgstr "Современный XMPP клиент"

View file

@ -29,7 +29,10 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application {
public Application() throws Error { public Application() throws Error {
Object(application_id: "im.dino.Dino", flags: ApplicationFlags.HANDLES_OPEN); Object(application_id: "im.dino.Dino", flags: ApplicationFlags.HANDLES_OPEN);
init();
var style_manager = Adw.StyleManager.get_default();
bool system_dark_theme = style_manager.system_supports_color_schemes && style_manager.dark;
init(system_dark_theme);
Environment.set_application_name("Dino"); Environment.set_application_name("Dino");
Window.set_default_icon_name("im.dino.Dino"); Window.set_default_icon_name("im.dino.Dino");
@ -73,9 +76,9 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application {
var manager = Adw.StyleManager.get_default(); var manager = Adw.StyleManager.get_default();
if (is_dark != manager.dark) { if (is_dark != manager.dark) {
if (is_dark) { if (is_dark) {
manager.set_color_scheme(Adw.ColorScheme.PREFER_DARK); manager.set_color_scheme(Adw.ColorScheme.FORCE_DARK);
} else { } else {
manager.set_color_scheme(Adw.ColorScheme.PREFER_LIGHT); manager.set_color_scheme(Adw.ColorScheme.FORCE_LIGHT);
} }
} }
}); });

View file

@ -34,7 +34,6 @@ class SettingsDialog : Adw.PreferencesWindow {
enter_newline_switch.active = settings.enter_newline; enter_newline_switch.active = settings.enter_newline;
enter_newline_switch.sensitive = settings.send_button; enter_newline_switch.sensitive = settings.send_button;
dark_theme.active = settings.dark_theme; dark_theme.active = settings.dark_theme;
dark_theme.sensitive = !Adw.StyleManager.get_default().system_supports_color_schemes;
typing_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } ); typing_switch.notify["active"].connect(() => { settings.send_typing = typing_switch.active; } );
marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } ); marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } );