From 625609b907e37e30fa29eaf7beb9426fd2405eaa Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Thu, 18 Jan 2018 10:09:36 -0500
Subject: [PATCH 2/2] autostart: ensure gnome-shell and mutter get right
 autostart phase

Previous versions of gnome-shell neglected to save the autostart phases
for required components in the session state. While that is now fixed,
users may still have old saved state that lack the autostart phase.

In order to ease upgrades, this commit manually adds in the phases that
are important for a functioning GNOME desktop.
---
 gnome-session/gsm-autostart-app.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/gnome-session/gsm-autostart-app.c b/gnome-session/gsm-autostart-app.c
index 2332b039..584a9105 100644
--- a/gnome-session/gsm-autostart-app.c
+++ b/gnome-session/gsm-autostart-app.c
@@ -545,61 +545,71 @@ load_desktop_file (GsmAutostartApp  *app)
         char    *startup_id;
         char    *phase_str;
         int      phase;
         gboolean res;
 
         g_assert (app->priv->app_info != NULL);
 
         phase_str = g_desktop_app_info_get_string (app->priv->app_info,
                                                    GSM_AUTOSTART_APP_PHASE_KEY);
         if (phase_str != NULL) {
                 if (strcmp (phase_str, "EarlyInitialization") == 0) {
                         phase = GSM_MANAGER_PHASE_EARLY_INITIALIZATION;
                 } else if (strcmp (phase_str, "PreDisplayServer") == 0) {
                         phase = GSM_MANAGER_PHASE_PRE_DISPLAY_SERVER;
                 } else if (strcmp (phase_str, "DisplayServer") == 0) {
                         phase = GSM_MANAGER_PHASE_DISPLAY_SERVER;
                 } else if (strcmp (phase_str, "Initialization") == 0) {
                         phase = GSM_MANAGER_PHASE_INITIALIZATION;
                 } else if (strcmp (phase_str, "WindowManager") == 0) {
                         phase = GSM_MANAGER_PHASE_WINDOW_MANAGER;
                 } else if (strcmp (phase_str, "Panel") == 0) {
                         phase = GSM_MANAGER_PHASE_PANEL;
                 } else if (strcmp (phase_str, "Desktop") == 0) {
                         phase = GSM_MANAGER_PHASE_DESKTOP;
                 } else {
                         phase = GSM_MANAGER_PHASE_APPLICATION;
                 }
 
                 g_free (phase_str);
         } else {
-                phase = GSM_MANAGER_PHASE_APPLICATION;
+                const char *app_id;
+
+                app_id = g_app_info_get_id (G_APP_INFO (app->priv->app_info));
+
+                /* These hardcoded checks are to keep upgrades working */
+                if (app_id != NULL && g_str_has_prefix (app_id, "org.gnome.Shell"))
+                        phase = GSM_MANAGER_PHASE_DISPLAY_SERVER;
+                else if (app_id != NULL && g_str_equal (app_id, "org.gnome.SettingsDaemon.desktop"))
+                        phase = GSM_MANAGER_PHASE_INITIALIZATION;
+                else
+                        phase = GSM_MANAGER_PHASE_APPLICATION;
         }
 
         dbus_name = g_desktop_app_info_get_string (app->priv->app_info,
                                                    GSM_AUTOSTART_APP_DBUS_NAME_KEY);
         if (dbus_name != NULL) {
                 app->priv->launch_type = AUTOSTART_LAUNCH_ACTIVATE;
         } else {
                 app->priv->launch_type = AUTOSTART_LAUNCH_SPAWN;
         }
 
         /* this must only be done on first load */
         switch (app->priv->launch_type) {
         case AUTOSTART_LAUNCH_SPAWN:
                 startup_id =
                         g_desktop_app_info_get_string (app->priv->app_info,
                                                        GSM_AUTOSTART_APP_STARTUP_ID_KEY);
 
                 if (startup_id == NULL) {
                         startup_id = gsm_util_generate_startup_id ();
                 }
                 break;
         case AUTOSTART_LAUNCH_ACTIVATE:
                 startup_id = g_strdup (dbus_name);
                 break;
         default:
                 g_assert_not_reached ();
         }
 
         res = g_desktop_app_info_has_key (app->priv->app_info,
                                           GSM_AUTOSTART_APP_AUTORESTART_KEY);
-- 
2.14.3

