summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2020-04-08 13:52:48 +0200
committerBastien Nocera <hadess@hadess.net>2020-04-08 13:56:40 +0200
commit43ca0fc7a5bead686435caef7280f6fb73f70af2 (patch)
treeabee1afd404a30a6a30737e43ba1e7b017e29304
parent65a86611a8d570901f4376737debbaf771c584d4 (diff)
downloadgnome-control-center-wip/hadess/dont-run-unsupported.tar.gz
shell: Refuse to run under unsupported desktopswip/hadess/dont-run-unsupported
Closes: #945
-rw-r--r--shell/gnome-control-center.desktop.in.in1
-rw-r--r--shell/main.c37
2 files changed, 38 insertions, 0 deletions
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 ();