[gnome-builder/wip/gtk4-port: 1603/1774] plugins/flatpak: setup gsettings overrides with workbench addin




commit 82418d7ad381316ed8c8652f8ff67ac497252afb
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 22 12:56:48 2022 -0700

    plugins/flatpak: setup gsettings overrides with workbench addin
    
    Since we don't have the runner object anymore to use for running the app,
    we need to do our setup from the run signal to alter GTK settings for the
    inspector access.

 src/plugins/flatpak/flatpak-plugin.c              |   4 +
 src/plugins/flatpak/gbp-flatpak-workbench-addin.c | 167 ++++++++++++++++++++++
 src/plugins/flatpak/gbp-flatpak-workbench-addin.h |  31 ++++
 src/plugins/flatpak/meson.build                   |   1 +
 4 files changed, 203 insertions(+)
---
diff --git a/src/plugins/flatpak/flatpak-plugin.c b/src/plugins/flatpak/flatpak-plugin.c
index d8e2b5113..964021d5a 100644
--- a/src/plugins/flatpak/flatpak-plugin.c
+++ b/src/plugins/flatpak/flatpak-plugin.c
@@ -36,6 +36,7 @@
 #include "gbp-flatpak-pipeline-addin.h"
 #include "gbp-flatpak-run-command-provider.h"
 #include "gbp-flatpak-runtime-provider.h"
+#include "gbp-flatpak-workbench-addin.h"
 
 _IDE_EXTERN void
 _gbp_flatpak_register_types (PeasObjectModule *module)
@@ -63,6 +64,9 @@ _gbp_flatpak_register_types (PeasObjectModule *module)
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_PIPELINE_ADDIN,
                                               GBP_TYPE_FLATPAK_PIPELINE_ADDIN);
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_WORKBENCH_ADDIN,
+                                              GBP_TYPE_FLATPAK_WORKBENCH_ADDIN);
 
   gbp_flatpak_aux_init ();
 
diff --git a/src/plugins/flatpak/gbp-flatpak-workbench-addin.c 
b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
new file mode 100644
index 000000000..f86e7ffc6
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-workbench-addin.c
@@ -0,0 +1,167 @@
+/* gbp-flatpak-workbench-addin.c
+ *
+ * Copyright 2022 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-flatpak-workbench-addin"
+
+#include "config.h"
+
+#define G_SETTINGS_ENABLE_BACKEND
+#include <gio/gsettingsbackend.h>
+
+#include <libide-foundry.h>
+
+#include "gbp-flatpak-manifest.h"
+#include "gbp-flatpak-workbench-addin.h"
+
+struct _GbpFlatpakWorkbenchAddin
+{
+  GObject        parent_instance;
+  IdeWorkbench  *workbench;
+  IdeRunManager *run_manager;
+  gulong         run_signal_handler;
+};
+
+static void
+gbp_flatpak_workbench_addin_run_cb (GbpFlatpakWorkbenchAddin *self,
+                                    IdeRunContext            *run_context,
+                                    IdeRunManager            *run_manager)
+{
+  g_autoptr(GSettingsBackend) backend = NULL;
+  g_autoptr(GSettings) gtk_settings = NULL;
+  g_autofree char *filename = NULL;
+  IdeConfigManager *config_manager;
+  IdeContext *context;
+  const char *app_id;
+  IdeConfig *config;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_RUN_CONTEXT (run_context));
+  g_assert (IDE_IS_RUN_MANAGER (run_manager));
+
+  /* This function will overwrite various settings in the application that
+   * are very useful for developing applications from Builder. It modifies
+   * the GLib GKeyFile-based settings file.
+   */
+
+  if (!(context = ide_object_get_context (IDE_OBJECT (self))) ||
+      !(config_manager = ide_config_manager_from_context (context)) ||
+      !(config = ide_config_manager_get_current (config_manager)) ||
+      !GBP_IS_FLATPAK_MANIFEST (config) ||
+      !(app_id = ide_config_get_app_id (config)))
+    IDE_EXIT;
+
+  filename = g_build_filename (g_get_home_dir (), ".var", "app", app_id, "config", "glib-2.0", "settings", 
"keyfile", NULL);
+  backend = g_keyfile_settings_backend_new (filename, "/", NULL);
+  gtk_settings = g_settings_new_with_backend ("org.gtk.Settings.Debug", backend);
+
+  g_settings_set_boolean (gtk_settings, "enable-inspector-keybinding", TRUE);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_flatpak_workbench_addin_project_loaded (IdeWorkbenchAddin *addin,
+                                            IdeProjectInfo    *project_info)
+{
+  GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
+  IdeRunManager *run_manager;
+  IdeContext *context;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_WORKBENCH (self->workbench));
+  g_assert (IDE_IS_PROJECT_INFO (project_info));
+
+  context = ide_workbench_get_context (self->workbench);
+  run_manager = ide_run_manager_from_context (context);
+
+  g_set_object (&self->run_manager, run_manager);
+
+  self->run_signal_handler =
+    g_signal_connect_object (run_manager,
+                             "run",
+                             G_CALLBACK (gbp_flatpak_workbench_addin_run_cb),
+                             self,
+                             G_CONNECT_SWAPPED);
+
+  IDE_EXIT;
+}
+
+static void
+gbp_flatpak_workbench_addin_load (IdeWorkbenchAddin *addin,
+                                  IdeWorkbench      *workbench)
+{
+  GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_WORKBENCH (workbench));
+
+  self->workbench = workbench;
+
+  IDE_EXIT;
+}
+
+static void
+gbp_flatpak_workbench_addin_unload (IdeWorkbenchAddin *addin,
+                                    IdeWorkbench      *workbench)
+{
+  GbpFlatpakWorkbenchAddin *self = (GbpFlatpakWorkbenchAddin *)addin;
+
+  IDE_ENTRY;
+
+  g_assert (GBP_IS_FLATPAK_WORKBENCH_ADDIN (self));
+  g_assert (IDE_IS_WORKBENCH (workbench));
+
+  if (self->run_manager != NULL)
+    {
+      g_clear_signal_handler (&self->run_signal_handler, self->run_manager);
+      g_clear_object (&self->run_manager);
+    }
+
+  self->workbench = NULL;
+
+  IDE_EXIT;
+}
+
+static void
+workbench_addin_iface_init (IdeWorkbenchAddinInterface *iface)
+{
+  iface->load = gbp_flatpak_workbench_addin_load;
+  iface->project_loaded = gbp_flatpak_workbench_addin_project_loaded;
+  iface->unload = gbp_flatpak_workbench_addin_unload;
+}
+
+G_DEFINE_FINAL_TYPE_WITH_CODE (GbpFlatpakWorkbenchAddin, gbp_flatpak_workbench_addin, G_TYPE_OBJECT,
+                               G_IMPLEMENT_INTERFACE (IDE_TYPE_WORKBENCH_ADDIN, workbench_addin_iface_init))
+
+static void
+gbp_flatpak_workbench_addin_class_init (GbpFlatpakWorkbenchAddinClass *klass)
+{
+}
+
+static void
+gbp_flatpak_workbench_addin_init (GbpFlatpakWorkbenchAddin *self)
+{
+}
diff --git a/src/plugins/flatpak/gbp-flatpak-workbench-addin.h 
b/src/plugins/flatpak/gbp-flatpak-workbench-addin.h
new file mode 100644
index 000000000..f0c802eff
--- /dev/null
+++ b/src/plugins/flatpak/gbp-flatpak-workbench-addin.h
@@ -0,0 +1,31 @@
+/* gbp-flatpak-workbench-addin.h
+ *
+ * Copyright 2022 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-gui.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_FLATPAK_WORKBENCH_ADDIN (gbp_flatpak_workbench_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpFlatpakWorkbenchAddin, gbp_flatpak_workbench_addin, GBP, FLATPAK_WORKBENCH_ADDIN, 
GObject)
+
+G_END_DECLS
diff --git a/src/plugins/flatpak/meson.build b/src/plugins/flatpak/meson.build
index d86282625..9e586bf79 100644
--- a/src/plugins/flatpak/meson.build
+++ b/src/plugins/flatpak/meson.build
@@ -34,6 +34,7 @@ plugins_sources += files([
   'gbp-flatpak-sources.c',
   'gbp-flatpak-subprocess-launcher.c',
   'gbp-flatpak-util.c',
+  'gbp-flatpak-workbench-addin.c',
   'ipc-flatpak-transfer-impl.c',
 ])
 


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