[gnome-control-center/wip/hadess/dont-run-unsupported] shell: Refuse to run under unsupported desktops



commit 43ca0fc7a5bead686435caef7280f6fb73f70af2
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Apr 8 13:52:48 2020 +0200

    shell: Refuse to run under unsupported desktops
    
    Closes: #945

 shell/gnome-control-center.desktop.in.in |  1 +
 shell/main.c                             | 37 ++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)
---
diff --git a/shell/gnome-control-center.desktop.in.in b/shell/gnome-control-center.desktop.in.in
index e87629970..8776ffad5 100644
--- a/shell/gnome-control-center.desktop.in.in
+++ b/shell/gnome-control-center.desktop.in.in
@@ -7,6 +7,7 @@ Terminal=false
 Type=Application
 StartupNotify=true
 Categories=GNOME;GTK;Settings;
+# See also is_supported_desktop() in main.c
 OnlyShowIn=GNOME;Unity;
 X-GNOME-Bugzilla-Bugzilla=GNOME
 X-GNOME-Bugzilla-Product=gnome-control-center
diff --git a/shell/main.c b/shell/main.c
index 425306bc2..9dd19597b 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -38,6 +38,37 @@
 
 #include "cc-application.h"
 
+static char **
+get_current_desktops (void)
+{
+  const char *envvar;
+
+  envvar = g_getenv ("XDG_CURRENT_DESKTOP");
+
+  if (!envvar)
+    return g_new0 (char *, 0 + 1);
+
+  return g_strsplit (envvar, G_SEARCHPATH_SEPARATOR_S, 0);
+}
+
+static gboolean
+is_supported_desktop (void)
+{
+  g_auto(GStrv) desktops = NULL;
+  guint i;
+
+  desktops = get_current_desktops ();
+  for (i = 0; desktops[i] != NULL; i++)
+    {
+      /* This matches OnlyShowIn in gnome-control-center.desktop.in.in */
+      if (g_ascii_strcasecmp (desktops[i], "GNOME") == 0 ||
+          g_ascii_strcasecmp (desktops[i], "Unity") == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 initialize_dependencies (gint    *argc,
                          gchar ***argv)
@@ -63,6 +94,12 @@ main (gint    argc,
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 
+  if (!is_supported_desktop ())
+    {
+      g_message ("Running gnome-control-center is only supported under GNOME and Unity, exiting");
+      return 1;
+    }
+
   initialize_dependencies (&argc, &argv);
 
   application = cc_application_new ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]