[gnome-builder] flatpak: abstract runtime check for flatpak



commit 679ed6d6c0e58fa577b1d9aafa75fccde7929277
Author: Christian Hergert <chergert redhat com>
Date:   Mon Sep 19 11:27:27 2016 -0700

    flatpak: abstract runtime check for flatpak
    
    This adds ide_is_flatpak() to simplify our checks to see if we are running
    in our bundled environment. Generally we don't want to have to rely on
    this, but special cases do exist (such as choosing what terminal to run).

 libide/Makefile.am                          |    2 +
 libide/ide.h                                |    1 +
 libide/subprocess/ide-subprocess-launcher.c |   19 +----------
 libide/util/ide-flatpak.c                   |   46 +++++++++++++++++++++++++++
 libide/util/ide-flatpak.h                   |   30 +++++++++++++++++
 5 files changed, 81 insertions(+), 17 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index aa2e203..9aa324e 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -152,6 +152,7 @@ libide_1_0_la_public_headers =                            \
        util/ide-cairo.h                                  \
        util/ide-dnd.h                                    \
        util/ide-file-manager.h                           \
+       util/ide-flatpak.h                                \
        util/ide-glib.h                                   \
        util/ide-gtk.h                                    \
        util/ide-line-reader.h                            \
@@ -306,6 +307,7 @@ libide_1_0_la_public_sources =                            \
        util/ide-cairo.c                                  \
        util/ide-dnd.c                                    \
        util/ide-file-manager.c                           \
+       util/ide-flatpak.c                                \
        util/ide-glib.c                                   \
        util/ide-gtk.c                                    \
        util/ide-line-reader.c                            \
diff --git a/libide/ide.h b/libide/ide.h
index fdb0dfc..3109127 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -130,6 +130,7 @@ G_BEGIN_DECLS
 #include "tree/ide-tree-types.h"
 #include "tree/ide-tree.h"
 #include "util/ide-file-manager.h"
+#include "util/ide-flatpak.h"
 #include "util/ide-glib.h"
 #include "util/ide-gtk.h"
 #include "util/ide-line-reader.h"
diff --git a/libide/subprocess/ide-subprocess-launcher.c b/libide/subprocess/ide-subprocess-launcher.c
index 0cb51fe..df44792 100644
--- a/libide/subprocess/ide-subprocess-launcher.c
+++ b/libide/subprocess/ide-subprocess-launcher.c
@@ -32,6 +32,7 @@
 #include "subprocess/ide-breakout-subprocess-private.h"
 #include "subprocess/ide-simple-subprocess.h"
 #include "subprocess/ide-subprocess-launcher.h"
+#include "util/ide-flatpak.h"
 
 typedef struct
 {
@@ -133,32 +134,16 @@ static gboolean
 should_use_breakout_process (IdeSubprocessLauncher *self)
 {
   IdeSubprocessLauncherPrivate *priv = ide_subprocess_launcher_get_instance_private (self);
-  static gsize initialized;
-  static gboolean is_contained;
 
   g_assert (IDE_IS_SUBPROCESS_LAUNCHER (self));
 
-  if (g_once_init_enter (&initialized))
-    {
-      g_autofree gchar *flatpak_info_path = NULL;
-
-      flatpak_info_path = g_build_filename (g_get_user_runtime_dir (),
-                                            "flatpak-info",
-                                            NULL);
-
-      if (g_file_test (flatpak_info_path, G_FILE_TEST_EXISTS))
-        is_contained = TRUE;
-
-      g_once_init_leave (&initialized, TRUE);
-    }
-
   if (g_getenv ("IDE_USE_BREAKOUT_SUBPROCESS") != NULL)
     return TRUE;
 
   if (!priv->run_on_host)
     return FALSE;
 
-  return is_contained;
+  return ide_is_flatpak ();
 }
 
 static void
diff --git a/libide/util/ide-flatpak.c b/libide/util/ide-flatpak.c
new file mode 100644
index 0000000..857fce9
--- /dev/null
+++ b/libide/util/ide-flatpak.c
@@ -0,0 +1,46 @@
+/* ide-flatpak.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-flatpak.h"
+
+/**
+ * ide_is_flatpak:
+ *
+ * This function checks to see if the application is running within
+ * a flatpak. This might be useful for cases where you need to perform
+ * a different command when you are in the bundled flatpak version.
+ */
+gboolean
+ide_is_flatpak (void)
+{
+  static gboolean checked;
+  static gboolean is_flatpak;
+
+  if (!checked)
+    {
+      g_autofree gchar *path = NULL;
+
+      path = g_build_filename (g_get_user_runtime_dir (),
+                               "flatpak-info",
+                               NULL);
+      is_flatpak = g_file_test (path, G_FILE_TEST_EXISTS);
+      checked = TRUE;
+    }
+
+  return is_flatpak;
+}
diff --git a/libide/util/ide-flatpak.h b/libide/util/ide-flatpak.h
new file mode 100644
index 0000000..3ddd06a
--- /dev/null
+++ b/libide/util/ide-flatpak.h
@@ -0,0 +1,30 @@
+/* ide-flatpak.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_FLATPAK_H
+#define IDE_FLATPAK_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+gboolean ide_is_flatpak (void);
+
+G_END_DECLS
+
+#endif /* IDE_FLATPAK_H */


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