Skip to content
Open
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
68 changes: 2 additions & 66 deletions lib/Widgets/Settings.vala
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
/*-
* Copyright 2021 elementary, Inc. (https://elementary.io)
* Copyright 2021-2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: LGPL-2.1-or-later
*/

namespace Granite {
[DBus (name = "io.elementary.pantheon.AccountsService")]
private interface Pantheon.AccountsService : Object {
public abstract int prefers_color_scheme { get; set; }
}

[DBus (name = "org.freedesktop.Accounts")]
interface FDO.Accounts : Object {
public abstract string find_user_by_name (string username) throws GLib.Error;
}

/**
* Granite.Settings provides a way to share Pantheon desktop settings with applications.
*/
Expand Down Expand Up @@ -59,9 +49,6 @@ namespace Granite {

/**
* Whether the user would prefer if apps use a dark or light color scheme or if the user has expressed no preference.
*
* To access this from a Flatpak application, add an entry with the value `'--system-talk-name=org.freedesktop.Accounts'`
* in the `finish-args` array of your Flatpak manifest.
*/
public ColorScheme prefers_color_scheme {
get {
Expand All @@ -75,46 +62,17 @@ namespace Granite {
}
}

private string? _user_path = null;
private string user_path {
get {
if (_user_path == null) {
setup_user_path ();
}
return _user_path;
}
private set {
_user_path = value;
}
}

private static GLib.Once<Granite.Settings> instance;
public static unowned Granite.Settings get_default () {
return instance.once (() => {
return new Granite.Settings ();
});
}

private FDO.Accounts? accounts_service = null;
private Pantheon.AccountsService? pantheon_act = null;
private Portal.Settings? portal = null;

private Settings () {}

private void setup_user_path () {
try {
accounts_service = GLib.Bus.get_proxy_sync (
GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts"
);

_user_path = accounts_service.find_user_by_name (GLib.Environment.get_user_name ());
} catch (Error e) {
critical (e.message);
}
}

private void setup_accent_color () {
try {
if (portal == null) {
Expand Down Expand Up @@ -167,30 +125,8 @@ namespace Granite {
prefers_color_scheme = (ColorScheme) value.get_uint32 ();
}
});
return;
} catch (Error e) {
debug ("cannot use the portal, using the AccountsService: %s", e.message);
}

try {
pantheon_act = GLib.Bus.get_proxy_sync (
GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES
);

prefers_color_scheme = (ColorScheme) pantheon_act.prefers_color_scheme;

((GLib.DBusProxy) pantheon_act).g_properties_changed.connect ((changed, invalid) => {
var color_scheme = changed.lookup_value ("PrefersColorScheme", new VariantType ("i"));
if (color_scheme != null) {
prefers_color_scheme = (ColorScheme) color_scheme.get_int32 ();
}
});
return;
} catch (Error e) {
critical (e.message);
debug ("cannot use the portal: %s", e.message);
}

// Set a default in case we can't get from system
Expand Down