From 493a364eb788d015d6f44a9a92aa86ef36ab72a9 Mon Sep 17 00:00:00 2001
From: c4pp4
Date: Wed, 23 Jul 2025 00:12:00 +0200
Subject: [PATCH 1/1] Use unity-control-center as the fallback

Try to use unity-control-center as the fallback when gnome-control-center
is not available.

Signed-off-by: c4pp4
---
 src/utils/gcal-utils.c | 59 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/src/utils/gcal-utils.c b/src/utils/gcal-utils.c
index 6056c8f..335b0ca 100644
--- a/src/utils/gcal-utils.c
+++ b/src/utils/gcal-utils.c
@@ -1022,6 +1022,48 @@ create_dbus_proxy (GDBusConnection *connection,
                                 NULL);
 }
 
+static gboolean
+in_desktop (const gchar *name)
+{
+  const gchar *desktop_name_list;
+  gchar **names;
+  gboolean in_list = FALSE;
+  gint i;
+
+  desktop_name_list = g_getenv ("XDG_CURRENT_DESKTOP");
+  if (!desktop_name_list)
+    return FALSE;
+
+  names = g_strsplit (desktop_name_list, ":", -1);
+  for (i = 0; names[i] && !in_list; i++)
+    if (strcmp (names[i], name) == 0) {
+      in_list = TRUE;
+      break;
+    }
+  g_strfreev (names);
+
+  return in_list;
+}
+
+static void
+spawn_ucc_with_args (const gchar *panel_id,
+                     const gchar *action)
+{
+  const gchar* const command[] = { "unity-control-center",
+                                   panel_id, action, NULL };
+  GError *error = NULL;
+
+  g_spawn_async (NULL, (gchar**) command,
+                 NULL,
+                 G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
+                 NULL, NULL, NULL, &error);
+
+  if (error) {
+    g_warning ("Couldn't open Unity Control Center: %s", error->message);
+    g_error_free (error);
+  }
+}
+
 void
 gcal_utils_launch_gnome_settings (GDBusConnection *connection,
                                   const gchar     *panel_id,
@@ -1031,6 +1073,7 @@ gcal_utils_launch_gnome_settings (GDBusConnection *connection,
   GVariantBuilder builder;
   GVariant *params[3];
   GVariant *array[1];
+  GError *error = NULL;
 
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("av"));
 
@@ -1059,7 +1102,11 @@ gcal_utils_launch_gnome_settings (GDBusConnection *connection,
 
   if (!proxy)
     {
-      g_warning ("Couldn't open panel '%s'", panel_id);
+      if (in_desktop("Unity"))
+        spawn_ucc_with_args (panel_id, action);
+      else
+        g_warning ("Couldn't open panel '%s'", panel_id);
+
       return;
     }
 
@@ -1069,7 +1116,15 @@ gcal_utils_launch_gnome_settings (GDBusConnection *connection,
                           G_DBUS_CALL_FLAGS_NONE,
                           -1,
                           NULL,
-                          NULL);
+                          &error);
+  if (error) {
+    if (in_desktop("Unity"))
+      spawn_ucc_with_args (panel_id, action);
+    else
+      g_warning ("Couldn't open panel '%s': %s", panel_id, error->message);
+
+    g_error_free (error);
+  }
 }
 
 gchar*
-- 
2.49.1

