Skip to content

Don't use AccountService for color scheme #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 17 additions & 23 deletions settings-portal/Settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

Expand All @@ -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 () {
Expand All @@ -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,
Expand All @@ -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 ();
}
Expand All @@ -105,8 +96,9 @@ public class SettingsDaemon.Settings : GLib.Object {

public signal void setting_changed (string namespace, string key, GLib.Variant value);

private HashTable<unowned string, GLib.Settings> settings;
private HashTable<unowned string, GLib.Settings> supported_settings;
private AccountsServiceMonitor monitor;
private GLib.Settings settings;

private const string[] SUPPORTED_SCHEMAS = {
"io.elementary.settings-daemon.datetime",
Expand All @@ -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<unowned string, GLib.Settings> (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<unowned string, GLib.Settings> (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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -206,7 +200,7 @@ public class SettingsDaemon.Settings : GLib.Object {
public async GLib.HashTable<string, GLib.HashTable<string, GLib.Variant>> read_all (string[] namespaces) throws GLib.DBusError, GLib.IOError {
var ret = new GLib.HashTable<string, GLib.HashTable<string, GLib.Variant>> (str_hash, str_equal);

settings.foreach ((schema, setting) => {
supported_settings.foreach ((schema, setting) => {
if (namespace_matches (schema, namespaces)) {
var dict = new GLib.HashTable<string, GLib.Variant> (str_hash, str_equal);

Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/AccountsService.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}

Expand Down
4 changes: 2 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 0 additions & 8 deletions src/Backends/PrefersColorSchemeSettings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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");

Expand Down Expand Up @@ -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);
}
Expand Down