From 51152367034a206f7423632a16f343bc521f457d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 13 Feb 2025 02:51:14 +0100 Subject: [PATCH] loginManager: Get user proxy for UID Using the user object at `/org/freedesktop/login1/User/self` is convenient, but has the caveat that login1 does not emit the `PropertiesChanged` signal for the object. That is indeed logical, as for signal emissions there is no sender that can be used to resolve `self`. The new TimeLimitsManager depends on change notifications for user properties, so stop using the `self` shorthand and instead create the User proxy for the user's UID. Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/8185 Part-of: --- .../org.freedesktop.login1.Manager.xml | 4 +++ js/misc/loginManager.js | 25 +++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/data/dbus-interfaces/org.freedesktop.login1.Manager.xml b/data/dbus-interfaces/org.freedesktop.login1.Manager.xml index f40d498dc..7e0fc225e 100644 --- a/data/dbus-interfaces/org.freedesktop.login1.Manager.xml +++ b/data/dbus-interfaces/org.freedesktop.login1.Manager.xml @@ -17,6 +17,10 @@ + + + + diff --git a/js/misc/loginManager.js b/js/misc/loginManager.js index 4bbe7c42c..d928ff022 100644 --- a/js/misc/loginManager.js +++ b/js/misc/loginManager.js @@ -1,6 +1,7 @@ import GLib from 'gi://GLib'; import Gio from 'gi://Gio'; import GioUnix from 'gi://GioUnix'; +import Shell from 'gi://Shell'; import * as Signals from './signals.js'; import {loadInterfaceXML} from './fileUtils.js'; @@ -95,17 +96,26 @@ class LoginManagerSystemd extends Signals.EventEmitter { this._proxy = new SystemdLoginManager(Gio.DBus.system, 'org.freedesktop.login1', '/org/freedesktop/login1'); - this._userProxy = new SystemdLoginUser(Gio.DBus.system, - 'org.freedesktop.login1', - '/org/freedesktop/login1/user/self'); this._proxy.connectSignal('PrepareForSleep', this._prepareForSleep.bind(this)); this._proxy.connectSignal('SessionRemoved', this._sessionRemoved.bind(this)); } - getCurrentUserProxy() { - return this._userProxy; + async getCurrentUserProxy() { + if (this._userProxy) + return this._userProxy; + + const uid = Shell.util_get_uid(); + try { + const [objectPath] = await this._proxy.GetUserAsync(uid); + this._userProxy = await SystemdLoginUser.newAsync( + Gio.DBus.system, 'org.freedesktop.login1', objectPath); + return this._userProxy; + } catch (error) { + logError(error, `Could not get a proxy for user ${uid}`); + return null; + } } async getCurrentSessionProxy() { @@ -115,14 +125,15 @@ class LoginManagerSystemd extends Signals.EventEmitter { let sessionId = GLib.getenv('XDG_SESSION_ID'); if (!sessionId) { log('Unset XDG_SESSION_ID, getCurrentSessionProxy() called outside a user session. Asking logind directly.'); - let [session, objectPath] = this._userProxy.Display; + const userProxy = await this.getCurrentUserProxy(); + let [session, objectPath] = userProxy.Display; if (session) { log(`Will monitor session ${session}`); sessionId = session; } else { log('Failed to find "Display" session; are we the greeter?'); - for ([session, objectPath] of this._userProxy.Sessions) { + for ([session, objectPath] of userProxy.Sessions) { let sessionProxy = new SystemdLoginSession(Gio.DBus.system, 'org.freedesktop.login1', objectPath);