From 9534d57a2fd5be392ed588715913a6ec1212d929 Mon Sep 17 00:00:00 2001 From: lenemter Date: Wed, 14 May 2025 12:50:38 +0300 Subject: [PATCH] Don't use AccountService for color scheme --- settings-portal/Settings.vala | 40 +++++++++----------- src/AccountsService.vala | 1 - src/Application.vala | 4 +- src/Backends/PrefersColorSchemeSettings.vala | 8 ---- 4 files changed, 19 insertions(+), 34 deletions(-) diff --git a/settings-portal/Settings.vala b/settings-portal/Settings.vala index ba154b93..7519c838 100644 --- a/settings-portal/Settings.vala +++ b/settings-portal/Settings.vala @@ -31,7 +31,6 @@ public errordomain PortalError { [DBus (name = "io.elementary.pantheon.AccountsService")] private interface Pantheon.AccountsService : Object { - public abstract int prefers_color_scheme { owned get; set; } public abstract int prefers_accent_color { owned get; set; } } @@ -40,18 +39,16 @@ interface FDO.Accounts : Object { public abstract string find_user_by_name (string username) throws GLib.Error; } -/* Copied from Granite.Settings */ private class AccountsServiceMonitor : GLib.Object { private FDO.Accounts? accounts_service = null; private Pantheon.AccountsService? pantheon_act = null; private string user_path; - public int32 color_scheme { get; set; } public int32 accent_color { get; set; } construct { setup_user_path (); - setup_prefers_color_scheme (); + setup_accent_color (); } private void setup_user_path () { @@ -68,7 +65,7 @@ private class AccountsServiceMonitor : GLib.Object { } } - private void setup_prefers_color_scheme () { + private void setup_accent_color () { try { pantheon_act = GLib.Bus.get_proxy_sync ( GLib.BusType.SYSTEM, @@ -77,16 +74,10 @@ private class AccountsServiceMonitor : GLib.Object { GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES ); - color_scheme = pantheon_act.prefers_color_scheme; accent_color = pantheon_act.prefers_accent_color; ((GLib.DBusProxy) pantheon_act).g_properties_changed.connect ((changed, invalid) => { - var value = changed.lookup_value ("PrefersColorScheme", new VariantType ("i")); - if (value != null) { - color_scheme = value.get_int32 (); - } - - value = changed.lookup_value ("PrefersAccentColor", new VariantType ("i")); + var value = changed.lookup_value ("PrefersAccentColor", new VariantType ("i")); if (value != null) { accent_color = value.get_int32 (); } @@ -105,8 +96,9 @@ public class SettingsDaemon.Settings : GLib.Object { public signal void setting_changed (string namespace, string key, GLib.Variant value); - private HashTable settings; + private HashTable supported_settings; private AccountsServiceMonitor monitor; + private GLib.Settings settings; private const string[] SUPPORTED_SCHEMAS = { "io.elementary.settings-daemon.datetime", @@ -115,19 +107,21 @@ public class SettingsDaemon.Settings : GLib.Object { construct { monitor = new AccountsServiceMonitor (); - monitor.notify["color-scheme"].connect (() => { - setting_changed ("org.freedesktop.appearance", "color-scheme", get_color_scheme ()); - }); monitor.notify["accent-color"].connect (() => { setting_changed ("org.freedesktop.appearance", "accent-color", get_accent_color ()); }); - settings = new HashTable (str_hash, str_equal); + settings = new GLib.Settings ("io.elementary.settings-daemon.prefers-color-scheme"); + settings.changed["color-scheme"].connect (() => { + setting_changed ("org.freedesktop.appearance", "accent-color", get_color_scheme ()); + }); + + supported_settings = new HashTable (str_hash, str_equal); foreach (unowned var schema in SUPPORTED_SCHEMAS) { if (SettingsSchemaSource.get_default ().lookup (schema, true) != null) { - settings[schema] = new GLib.Settings (schema); - settings[schema].changed.connect ((key) => { - var @value = settings[schema].get_value (key); + supported_settings[schema] = new GLib.Settings (schema); + supported_settings[schema].changed.connect ((key) => { + var @value = supported_settings[schema].get_value (key); setting_changed (schema, key, value); }); } else { @@ -156,7 +150,7 @@ public class SettingsDaemon.Settings : GLib.Object { } private GLib.Variant get_color_scheme () { - return new GLib.Variant.uint32 (monitor.color_scheme); + return new GLib.Variant.uint32 (settings.get_enum ("color-scheme")); } private inline GLib.Variant rgb_to_variant (int rgb) { @@ -206,7 +200,7 @@ public class SettingsDaemon.Settings : GLib.Object { public async GLib.HashTable> read_all (string[] namespaces) throws GLib.DBusError, GLib.IOError { var ret = new GLib.HashTable> (str_hash, str_equal); - settings.foreach ((schema, setting) => { + supported_settings.foreach ((schema, setting) => { if (namespace_matches (schema, namespaces)) { var dict = new GLib.HashTable (str_hash, str_equal); @@ -238,7 +232,7 @@ public class SettingsDaemon.Settings : GLib.Object { } } - unowned GLib.Settings? setting = settings[namespace]; + unowned GLib.Settings? setting = supported_settings[namespace]; if (setting != null && setting.settings_schema.has_key (key)) { return setting.get_value (key); } diff --git a/src/AccountsService.vala b/src/AccountsService.vala index 7e06e06b..5dd4e491 100644 --- a/src/AccountsService.vala +++ b/src/AccountsService.vala @@ -86,7 +86,6 @@ public interface SettingsDaemon.AccountsService : Object { [DBus (name = "io.elementary.pantheon.AccountsService")] public interface Pantheon.AccountsService : Object { - public abstract int prefers_color_scheme { get; set; } public abstract int prefers_accent_color { get; set; } } diff --git a/src/Application.vala b/src/Application.vala index 018b7b9b..b6f83385 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -15,11 +15,11 @@ public sealed class SettingsDaemon.Application : Gtk.Application { private Backends.MouseSettings mouse_settings; private Backends.InterfaceSettings interface_settings; private Backends.NightLightSettings night_light_settings; - private Backends.PrefersColorSchemeSettings prefers_color_scheme_settings; private Backends.AccentColorManager accent_color_manager; private Backends.Housekeeping housekeeping; private Backends.PowerProfilesSync power_profiles_sync; + private Backends.PrefersColorSchemeSettings prefers_color_scheme_settings; private const string FDO_ACCOUNTS_NAME = "org.freedesktop.Accounts"; private const string FDO_ACCOUNTS_PATH = "/org/freedesktop/Accounts"; @@ -56,6 +56,7 @@ public sealed class SettingsDaemon.Application : Gtk.Application { housekeeping = new Backends.Housekeeping (); power_profiles_sync = new Backends.PowerProfilesSync (); + prefers_color_scheme_settings = new Backends.PrefersColorSchemeSettings (); var check_firmware_updates_action = new GLib.SimpleAction ("check-firmware-updates", null); check_firmware_updates_action.activate.connect (check_firmware_updates); @@ -122,7 +123,6 @@ public sealed class SettingsDaemon.Application : Gtk.Application { try { pantheon_service = yield connection.get_proxy (FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES); - prefers_color_scheme_settings = new Backends.PrefersColorSchemeSettings (pantheon_service); accent_color_manager = new Backends.AccentColorManager (pantheon_service); } catch { warning ("Unable to get pantheon's AccountsService proxy, color scheme preference may be incorrect"); diff --git a/src/Backends/PrefersColorSchemeSettings.vala b/src/Backends/PrefersColorSchemeSettings.vala index cd6097c7..dd80f909 100644 --- a/src/Backends/PrefersColorSchemeSettings.vala +++ b/src/Backends/PrefersColorSchemeSettings.vala @@ -20,8 +20,6 @@ */ public class SettingsDaemon.Backends.PrefersColorSchemeSettings : Object { - public unowned Pantheon.AccountsService accounts_service { get; construct; } - private const string COLOR_SCHEME = "color-scheme"; private const string DARK_SCHEDULE = "prefer-dark-schedule"; private const string DARK_SCHEDULE_SNOOZED = "prefer-dark-schedule-snoozed"; @@ -32,10 +30,6 @@ public class SettingsDaemon.Backends.PrefersColorSchemeSettings : Object { private uint time_id = 0; - public PrefersColorSchemeSettings (Pantheon.AccountsService accounts_service) { - Object (accounts_service: accounts_service); - } - construct { color_settings = new Settings ("io.elementary.settings-daemon.prefers-color-scheme"); @@ -135,8 +129,6 @@ public class SettingsDaemon.Backends.PrefersColorSchemeSettings : Object { color_settings.set_boolean (DARK_SCHEDULE_SNOOZED, true); } - accounts_service.prefers_color_scheme = color_scheme; - var mutter_settings = new GLib.Settings ("org.gnome.desktop.interface"); mutter_settings.set_enum ("color-scheme", color_scheme); }