From a6600160ca8c972350e5794c341ddcfa5c1a4640 Mon Sep 17 00:00:00 2001
From: Adrian Vovk <adrianvovk@gmail.com>
Date: Tue, 27 May 2025 17:03:34 -0400
Subject: [PATCH 1/4] main: Notify gnome-session when we're ready

Basically, we recently[1] removed XSMP from gnome-session because it's
been disabled for a while. Mutter also[2] removed its XSMP integration
shortly after.

However, it turns out that gnome-session's builtin service manager was
relying on Mutter's XSMP integration to know when gnome-shell is done
starting up. No more XSMP = no more notification = gnome-session decides
that gnome-shell is dead even though it's not = fail whale

This is a temporary measure. GDM will soon switch[3] to an architecture
that will allow us to completely drop gnome-session's builtin service
manager, and this workaround will go away

[1]: https://gitlab.gnome.org/GNOME/gnome-session/-/merge_requests/139
[2]: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/4438
[3]: https://gitlab.gnome.org/GNOME/gdm/-/merge_requests/289

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3730>
Signed-off-by: Achill Gilgenast <achill@achill.org>
---
 js/ui/main.js | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/js/ui/main.js b/js/ui/main.js
index 252cfef8c191..6674bb20ca51 100644
--- a/js/ui/main.js
+++ b/js/ui/main.js
@@ -334,6 +334,7 @@ async function _initializeUI() {
     GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
         Shell.util_sd_notify();
         global.context.notify_ready();
+        _notifyGnomeSessionReady();
         return GLib.SOURCE_REMOVE;
     });
 
@@ -398,6 +399,20 @@ async function _initializeUI() {
     });
 }
 
+async function _notifyGnomeSessionReady() {
+    try {
+        let params = GLib.Variant.new('(ss)', ['org.gnome.Shell.desktop', '']);
+        await Gio.DBus.session.call(
+            'org.gnome.SessionManager',
+            '/org/gnome/SessionManager',
+            'org.gnome.SessionManager',
+            'RegisterClient', params, null,
+            Gio.DBusCallFlags.NONE, -1, null);
+    } catch (e) {
+        log(`Error notifying gnome-session that we're ready: ${e.message}`);
+    }
+}
+
 function _handleShowWelcomeScreen() {
     const lastShownVersion = global.settings.get_string(WELCOME_DIALOG_LAST_SHOWN_VERSION);
     if (Util.GNOMEversionCompare(WELCOME_DIALOG_LAST_TOUR_CHANGE, lastShownVersion) > 0) {
-- 
2.53.0

