Skip to content

Commit

Permalink
Force dark/light theme changing
Browse files Browse the repository at this point in the history
  • Loading branch information
igsha committed Apr 24, 2024
1 parent 9018833 commit 4a396fd
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions libdino/src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public interface Application : GLib.Application {

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) {
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.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);

MessageProcessor.start(stream_interactor, db);
Expand Down
4 changes: 2 additions & 2 deletions libdino/src/entity/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Settings : Object {

private Database db;

public Settings.from_db(Database db) {
public Settings.from_db(Database db, bool default_dark_theme) {
this.db = db;

send_typing_ = col_to_bool_or_default("send_typing", true);
Expand All @@ -15,7 +15,7 @@ public class Settings : Object {
default_encryption = col_to_encryption_or_default("default_encryption", Encryption.UNKNOWN);
send_button = col_to_bool_or_default("send_button", 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) {
Expand Down
1 change: 0 additions & 1 deletion main/data/settings_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@
<child>
<object class="AdwActionRow">
<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="activatable-widget">dark_theme</property>
<child type="suffix">
Expand Down
4 changes: 0 additions & 4 deletions main/po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -1054,10 +1054,6 @@ msgstr ""
msgid "_Dark theme"
msgstr ""

#: main/data/settings_dialog.ui:148
msgid "If disabled, use system settings"
msgstr ""

#: main/data/im.dino.Dino.appdata.xml.in:7
msgid "Modern XMPP Chat Client"
msgstr ""
Expand Down
4 changes: 0 additions & 4 deletions main/po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -1072,10 +1072,6 @@ msgstr "Если опция недоступна, используйте Shift+E
msgid "_Dark theme"
msgstr "Тёмная тема"

#: main/data/settings_dialog.ui:148
msgid "If disabled, use system settings"
msgstr "Если опция недоступна, используйте настройки системы"

#: main/data/im.dino.Dino.appdata.xml.in:7
msgid "Modern XMPP Chat Client"
msgstr "Современный XMPP клиент"
Expand Down
9 changes: 6 additions & 3 deletions main/src/ui/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application {

public Application() throws Error {
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");
Window.set_default_icon_name("im.dino.Dino");

Expand Down Expand Up @@ -73,9 +76,9 @@ public class Dino.Ui.Application : Adw.Application, Dino.Application {
var manager = Adw.StyleManager.get_default();
if (is_dark != manager.dark) {
if (is_dark) {
manager.set_color_scheme(Adw.ColorScheme.PREFER_DARK);
manager.set_color_scheme(Adw.ColorScheme.FORCE_DARK);
} else {
manager.set_color_scheme(Adw.ColorScheme.PREFER_LIGHT);
manager.set_color_scheme(Adw.ColorScheme.FORCE_LIGHT);
}
}
});
Expand Down
1 change: 0 additions & 1 deletion main/src/ui/settings_dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class SettingsDialog : Adw.PreferencesWindow {
enter_newline_switch.active = settings.enter_newline;
enter_newline_switch.sensitive = settings.send_button;
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; } );
marker_switch.notify["active"].connect(() => { settings.send_marker = marker_switch.active; } );
Expand Down

0 comments on commit 4a396fd

Please sign in to comment.