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



commit 4c3d17458a3577d37d30413ad17ac41cb1c925f4
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/main.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
---
diff --git a/shell/main.c b/shell/main.c
index 425306bc2..32437cb3b 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -38,6 +38,36 @@
 
 #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++)
+    {
+      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 +93,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]