[gnome-boxes/user-avatar-accountsservice-flatpak] unnattended-installer, flatpak: Get user avatar correctly
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/user-avatar-accountsservice-flatpak] unnattended-installer, flatpak: Get user avatar correctly
- Date: Tue, 24 Sep 2019 13:24:43 +0000 (UTC)
commit 109ff2887551c5879c2743a82778bcce2cda1ec3
Author: Felipe Borges <felipeborges gnome org>
Date: Tue Sep 24 15:22:25 2019 +0200
unnattended-installer, flatpak: Get user avatar correctly
We get the user account data from the host and propagate that to
guests while performing express-installations.
When distributed as a Flatpak, Boxes needs access to the AccountsService
D-Bus service and to the location in the filesystem where it stores
the user avatar images.
build-aux/flatpak/org.gnome.Boxes.json | 3 ++-
src/unattended-installer.vala | 23 +----------------------
src/util.vala | 30 ++++++++++++++++++++++++++++++
3 files changed, 33 insertions(+), 23 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.Boxes.json b/build-aux/flatpak/org.gnome.Boxes.json
index 3bc13007..5df9d7da 100644
--- a/build-aux/flatpak/org.gnome.Boxes.json
+++ b/build-aux/flatpak/org.gnome.Boxes.json
@@ -13,9 +13,10 @@
"--socket=pulseaudio",
"--share=network",
"--device=all",
+ "--system-talk-name=org.freedesktop.Accounts",
+ "--filesystem=/var/lib/AccountsService/icons:ro",
"--talk-name=org.freedesktop.Tracker1",
"--talk-name=org.freedesktop.timedate1",
- "--talk-name=org.freedesktop.Accounts",
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
"--filesystem=home",
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index cac78ed1..98003f3e 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -85,8 +85,6 @@
// Devices made available by device drivers added through express installation (only).
private Osinfo.DeviceList additional_devices;
- private static Fdo.Accounts? accounts;
-
private InstallScriptInjectionMethod injection_method {
private get {
foreach (var unattended_file in unattended_files) {
@@ -104,20 +102,6 @@ private static string escape_genisoimage_path (string path) {
return str.replace ("=", "\\=");
}
- construct {
- /* We can't do this in the class constructor as the sync call can
- cause deadlocks, see bug #676679. */
- if (accounts == null) {
- try {
- accounts = Bus.get_proxy_sync (BusType.SYSTEM,
- "org.freedesktop.Accounts",
- "/org/freedesktop/Accounts");
- } catch (GLib.Error error) {
- warning ("Failed to connect to D-Bus service '%s': %s", "org.freedesktop.Accounts",
error.message);
- }
- }
- }
-
public UnattendedInstaller.from_media (InstallerMedia media, InstallScriptList scripts) throws
GLib.Error {
os = media.os;
os_media = media.os_media;
@@ -416,16 +400,11 @@ private async void create_iso (Cancellable? cancellable) throws GLib.Error {
}
private async void fetch_user_avatar () {
- if (accounts == null)
- return;
-
var username = Environment.get_user_name ();
string avatar_path = "/var/lib/AccountsService/icons/" + username;
try {
- var path = yield accounts.FindUserByName (Environment.get_user_name ());
- Fdo.AccountsUser user = yield Bus.get_proxy (BusType.SYSTEM, "org.freedesktop.Accounts", path);
- avatar_path = user.IconFile;
+ avatar_path = yield get_user_avatar_from_accountsservice (username);
} catch (GLib.IOError error) {
warning ("Failed to retrieve information about user '%s': %s", username, error.message);
}
diff --git a/src/util.vala b/src/util.vala
index 28b7bf01..0f88bc91 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -439,6 +439,17 @@ public static string canonicalize_for_search (string str) {
public abstract async string FindUserByName(string name) throws IOError;
}
+ private async Fdo.Accounts? get_accountsservice_accounts_manager () throws GLib.Error {
+ Fdo.Accounts? accounts = yield Bus.get_proxy (BusType.SYSTEM,
+ "org.freedesktop.Accounts",
+ "/org/freedesktop/Accounts");
+
+ if (accounts == null)
+ throw new Boxes.Error.INVALID ("Failed to connect to AccountsService D-Bus service");
+
+ return accounts;
+ }
+
[DBus (name = "org.freedesktop.Accounts.User")]
public interface Fdo.AccountsUser : Object {
public abstract bool AutomaticLogin { get; }
@@ -456,4 +467,23 @@ public static string canonicalize_for_search (string str) {
public abstract string UserName { owned get; }
public abstract string XSession { owned get; }
}
+
+ private async Fdo.AccountsUser? get_accountsservice_accounts_user (string object_path) throws GLib.Error
{
+ Fdo.AccountsUser? user = yield Bus.get_proxy (BusType.SYSTEM,
+ "org.freedesktop.Accounts",
+ object_path);
+
+ if (user == null)
+ throw new Boxes.Error.INVALID ("Failed to retrieve information about user");
+
+ return user;
+ }
+
+ public async string? get_user_avatar_from_accountsservice (string username) throws GLib.Error {
+ Fdo.Accounts accounts = yield get_accountsservice_accounts_manager ();
+ var path = yield accounts.FindUserByName (username);
+ Fdo.AccountsUser user = yield get_accountsservice_accounts_user (path);
+
+ return user.IconFile;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]