-
-
Notifications
You must be signed in to change notification settings - Fork 13
Implement the settings portal #38
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e132254
Implement the settings portal
alice-mkh a0ef5a1
Address review
alice-mkh 94a4e42
Address review
alice-mkh 7bbf77e
Commit what hadn't been committed.
alice-mkh 8c75e0e
Remove the leftover posix dep
alice-mkh 1c9ee57
Merge branch 'master' into wip/exalm/portal
danirabbit 1ecc562
Update Main.vala
danirabbit 2cdbd52
Fix version
alice-mkh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| option('systemduserunitdir', type: 'string', value: '', description: 'custom directory for systemd user units, or \'no\' to disable') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /*- | ||
| * Copyright 2021 elementary, Inc. <https://elementary.io> | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Library General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Library General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Library General Public | ||
| * License along with this library; if not, write to the | ||
| * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
| * Boston, MA 02110-1335 USA. | ||
| * | ||
| * Authored by: Corentin Noël <corentin@elementary.io> | ||
| */ | ||
|
|
||
| private static bool opt_replace = false; | ||
| private static bool show_version = false; | ||
|
|
||
| private static GLib.MainLoop loop; | ||
|
|
||
| private const GLib.OptionEntry[] ENTRIES = { | ||
| { "replace", 'r', 0, OptionArg.NONE, ref opt_replace, "Replace a running instance", null }, | ||
| { "version", 0, 0, OptionArg.NONE, ref show_version, "Show program version.", null }, | ||
| { null } | ||
| }; | ||
|
|
||
| private void on_bus_acquired (GLib.DBusConnection connection, string name) { | ||
| try { | ||
| connection.register_object ("/org/freedesktop/portal/desktop", new SettingsDaemon.Settings ()); | ||
| } catch (GLib.Error e) { | ||
| critical ("Unable to register the object: %s", e.message); | ||
| } | ||
| } | ||
|
|
||
| public int main (string[] args) { | ||
| var context = new GLib.OptionContext ("- Settings portal"); | ||
| context.add_main_entries (ENTRIES, null); | ||
| try { | ||
| context.parse (ref args); | ||
| } catch (Error e) { | ||
| printerr ("%s: %s", Environment.get_application_name (), e.message); | ||
| printerr ("\n"); | ||
| printerr ("Try \"%s --help\" for more information.", GLib.Environment.get_prgname ()); | ||
| printerr ("\n"); | ||
| return 1; | ||
| } | ||
|
|
||
| if (show_version) { | ||
| print ("%s \n", Build.VERSION); | ||
| return 0; | ||
| } | ||
|
|
||
| loop = new GLib.MainLoop (null, false); | ||
|
|
||
| try { | ||
| var session_bus = GLib.Bus.get_sync (GLib.BusType.SESSION); | ||
| var owner_id = GLib.Bus.own_name ( | ||
| GLib.BusType.SESSION, | ||
| "org.freedesktop.impl.portal.desktop.elementary.settings-daemon", | ||
| GLib.BusNameOwnerFlags.ALLOW_REPLACEMENT | (opt_replace ? GLib.BusNameOwnerFlags.REPLACE : 0), | ||
| on_bus_acquired, | ||
| () => { debug ("org.freedesktop.impl.portal.desktop.elementary.settings acquired"); }, | ||
| () => { loop.quit (); } | ||
| ); | ||
| loop.run (); | ||
| GLib.Bus.unown_name (owner_id); | ||
| } catch (Error e) { | ||
| printerr ("No session bus: %s\n", e.message); | ||
| return 2; | ||
| } | ||
|
|
||
| return 0; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| /*- | ||
| * Copyright 2021 elementary, Inc. (https://elementary.io) | ||
| * Copyright 2021 Alexander Mikhaylenko <alexm@gnome.org> | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU Library General Public | ||
| * License as published by the Free Software Foundation; either | ||
| * version 2 of the License, or (at your option) any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Library General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Library General Public | ||
| * License along with this library; if not, write to the | ||
| * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor | ||
| * Boston, MA 02110-1335 USA. | ||
| */ | ||
|
|
||
| [DBus (name = "org.freedesktop.portal.Error")] | ||
| public errordomain PortalError { | ||
| FAILED, | ||
| INVALID_ARGUMENT, | ||
| NOT_FOUND, | ||
| EXISTS, | ||
| NOT_ALLOWED, | ||
| CANCELLED, | ||
| WINDOW_DESTROYED | ||
| } | ||
|
|
||
| [DBus (name = "io.elementary.pantheon.AccountsService")] | ||
| private interface Pantheon.AccountsService : Object { | ||
| public abstract int prefers_color_scheme { owned get; set; } | ||
| } | ||
|
|
||
| [DBus (name = "org.freedesktop.Accounts")] | ||
| 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; } | ||
alice-mkh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| construct { | ||
| setup_user_path (); | ||
| setup_prefers_color_scheme (); | ||
| } | ||
|
|
||
| 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_prefers_color_scheme () { | ||
| try { | ||
| pantheon_act = GLib.Bus.get_proxy_sync ( | ||
| GLib.BusType.SYSTEM, | ||
| "org.freedesktop.Accounts", | ||
| user_path, | ||
| GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES | ||
| ); | ||
|
|
||
| color_scheme = pantheon_act.prefers_color_scheme; | ||
|
|
||
| ((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 (); | ||
| } | ||
| }); | ||
| } catch (Error e) { | ||
| critical (e.message); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [DBus (name = "org.freedesktop.impl.portal.Settings")] | ||
| public class SettingsDaemon.Settings : GLib.Object { | ||
| public uint32 version { | ||
| get { return 1; } | ||
| } | ||
|
|
||
| public signal void setting_changed (string namespace, string key, GLib.Variant value); | ||
|
|
||
| private AccountsServiceMonitor monitor; | ||
|
|
||
| construct { | ||
| monitor = new AccountsServiceMonitor (); | ||
| monitor.notify["color-scheme"].connect (() => { | ||
| setting_changed ("org.freedesktop.appearance", "color-scheme", get_color_scheme ()); | ||
alice-mkh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
| } | ||
|
|
||
| private bool namespace_matches (string namespace, string[] patterns) { | ||
| foreach (var pattern in patterns) { | ||
| if (pattern[0] == '\0') { | ||
| return true; | ||
| } | ||
|
|
||
| if (pattern == namespace) { | ||
| return true; | ||
| } | ||
|
|
||
| int pattern_len = pattern.length; | ||
| if (pattern[pattern_len - 1] == '*' && namespace.has_prefix (pattern.slice (0, pattern_len - 1))) { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return patterns.length == 0; | ||
| } | ||
|
|
||
| private GLib.Variant get_color_scheme () { | ||
| return new GLib.Variant.uint32 (monitor.color_scheme); | ||
| } | ||
|
|
||
| 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); | ||
|
|
||
| if (namespace_matches ("org.freedesktop.appearance", namespaces)) { | ||
| var dict = new HashTable<string, Variant> (str_hash, str_equal); | ||
|
|
||
| dict.insert ("color-scheme", get_color_scheme ()); | ||
|
|
||
| ret.insert ("org.freedesktop.appearance", dict); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| public async GLib.Variant read (string namespace, string key) throws GLib.DBusError, GLib.Error { | ||
| if (namespace == "org.freedesktop.appearance" && key == "color-scheme") { | ||
| return get_color_scheme (); | ||
| } | ||
|
|
||
| debug ("Attempted to read unknown namespace/key pair: %s %s", namespace, key); | ||
|
|
||
| throw new PortalError.NOT_FOUND ("Requested setting not found"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [portal] | ||
| DBusName=org.freedesktop.impl.portal.desktop.elementary.settings-daemon | ||
| Interfaces=org.freedesktop.impl.portal.Settings | ||
| UseIn=pantheon |
7 changes: 7 additions & 0 deletions
7
settings-portal/io.elementary.settings-daemon.xdg-desktop-portal.service.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [Unit] | ||
| Description=Portal service (Pantheon Settings Daemon) | ||
|
|
||
| [Service] | ||
| Type=dbus | ||
| BusName=org.freedesktop.impl.portal.desktop.elementary.settings-daemon | ||
| ExecStart=@libexecdir@/io.elementary.settings-daemon.xdg-desktop-portal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| libexec_dir = join_paths(get_option('prefix'), get_option ('libexecdir')) | ||
|
|
||
| portal_sources = files( | ||
| 'Main.vala', | ||
| 'Settings.vala', | ||
| ) | ||
|
|
||
| executable( | ||
| 'io.elementary.settings-daemon.xdg-desktop-portal', | ||
| portal_sources, | ||
| dependencies: [ | ||
| config_dep, | ||
| glib_dep, | ||
| gio_dep, | ||
| ], | ||
| install: true, | ||
| install_dir: libexec_dir, | ||
| ) | ||
|
|
||
| portal_conf_data = configuration_data() | ||
| portal_conf_data.set('libexecdir', libexec_dir) | ||
|
|
||
| systemd_systemduserunitdir = get_option('systemduserunitdir') | ||
| if systemd_systemduserunitdir != 'no' | ||
|
|
||
| if systemd_systemduserunitdir == '' | ||
| systemd_dep = dependency('systemd', version: '>= 206', required: false) | ||
| assert(systemd_dep.found(), 'systemd required but not found, please provide a valid systemd user unit dir or disable it') | ||
| systemd_systemduserunitdir = systemd_dep.get_pkgconfig_variable('systemduserunitdir', define_variable: ['prefix', get_option('prefix')]) | ||
| endif | ||
|
|
||
| configure_file( | ||
| input: 'io.elementary.settings-daemon.xdg-desktop-portal.service.in', | ||
| output: '@BASENAME@', | ||
| configuration: portal_conf_data, | ||
| install: true, | ||
| install_dir: systemd_systemduserunitdir | ||
| ) | ||
| endif | ||
|
|
||
| install_data( | ||
| 'io.elementary.settings-daemon.portal', | ||
| install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'xdg-desktop-portal', 'portals') | ||
| ) | ||
|
|
||
| configure_file( | ||
| input: 'org.freedesktop.impl.portal.desktop.elementary.settings-daemon.service.in', | ||
| output: '@BASENAME@', | ||
| configuration: portal_conf_data, | ||
| install: true, | ||
| install_dir: join_paths(get_option('prefix'), get_option('datadir'), 'dbus-1', 'services') | ||
| ) |
4 changes: 4 additions & 0 deletions
4
settings-portal/org.freedesktop.impl.portal.desktop.elementary.settings-daemon.service.in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [D-BUS Service] | ||
| Name=org.freedesktop.impl.portal.desktop.elementary.settings-daemon | ||
| Exec=@libexecdir@/io.elementary.settings-daemon.xdg-desktop-portal | ||
| SystemdService=io.elementary.settings-daemon.xdg-desktop-portal.service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple options for this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is still an open question. We can also leave it as is, of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OTOH if it's in the same process Granite will need an override to not try to access portal from portal itself too, having it separate doesn't require it as long as the portal binary doesn't link to granite.