[epiphany/mwleeds/webapp-dbus-api: 66/69] Use a global XdpPortal object




commit ce1558500624c93b4f63f4cf7c95538c313a6ec9
Author: Phaedrus Leeds <mwleeds protonmail com>
Date:   Tue Jan 25 12:59:55 2022 -0800

    Use a global XdpPortal object
    
    It doesn't seem to be the norm but the libportal documentation says
    that using one XdpPortal object across the application's lifetime is the
    expected pattern, and it makes sense so we don't have to make separate
    bus connections for no reason.

 lib/ephy-file-helpers.c  | 13 +++++++++++++
 lib/ephy-file-helpers.h  |  2 ++
 lib/ephy-flatpak-utils.c |  9 +++++----
 3 files changed, 20 insertions(+), 4 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 17adb338c..0dab7a72c 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -45,6 +45,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <libportal/portal-helpers.h>
 
 /**
  * SECTION:ephy-file-helpers
@@ -74,6 +75,8 @@ static char *config_dir;
 static char *tmp_dir;
 static EphyProfileDirType profile_dir_type;
 
+static XdpPortal *global_portal;
+
 GQuark ephy_file_helpers_error_quark;
 
 /**
@@ -455,6 +458,8 @@ ephy_file_helpers_init (const char            *profile_dir,
     }
   }
 
+  global_portal = xdp_portal_new ();
+
   return ret;
 }
 
@@ -489,6 +494,8 @@ ephy_file_helpers_shutdown (void)
     g_free (tmp_dir);
     tmp_dir = NULL;
   }
+
+  g_clear_object (&global_portal);
 }
 
 /**
@@ -889,3 +896,9 @@ ephy_copy_directory (const char *source,
     }
   }
 }
+
+XdpPortal *
+ephy_get_portal (void)
+{
+  return global_portal;
+}
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 581160d0c..16e5f0e0b 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -25,6 +25,7 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include <gtk/gtk.h>
+#include <libportal/portal-helpers.h>
 
 extern GQuark ephy_file_helpers_error_quark;
 #define EPHY_FILE_HELPERS_ERROR_QUARK        (ephy_file_helpers_error_quark)
@@ -76,5 +77,6 @@ gboolean           ephy_file_browse_to                      (GFile
                                                              guint32                user_time);
 void               ephy_copy_directory                      (const char            *source,
                                                              const char            *target);
+XdpPortal  *       ephy_get_portal                          (void);
 
 G_END_DECLS
diff --git a/lib/ephy-flatpak-utils.c b/lib/ephy-flatpak-utils.c
index e01d54cd8..49aca00cd 100644
--- a/lib/ephy-flatpak-utils.c
+++ b/lib/ephy-flatpak-utils.c
@@ -23,6 +23,7 @@
 
 #include <config.h>
 #include "ephy-flatpak-utils.h"
+#include "ephy-file-helpers.h"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -85,7 +86,7 @@ opened_uri (GObject      *object,
             GAsyncResult *result,
             gpointer      data)
 {
-  g_autoptr (XdpPortal) portal = XDP_PORTAL (object);
+  XdpPortal *portal = XDP_PORTAL (object);
   g_autoptr (GError) error = NULL;
   gboolean open_dir = GPOINTER_TO_INT (data);
   gboolean res;
@@ -106,16 +107,16 @@ ephy_open_uri (const char *uri,
   GApplication *application;
   GtkWindow *window;
   XdpParent *parent;
-  g_autoptr (XdpPortal) portal = xdp_portal_new ();
+  XdpPortal *portal = ephy_get_portal ();
 
   application = g_application_get_default ();
   window = gtk_application_get_active_window (GTK_APPLICATION (application));
   parent = xdp_parent_new_gtk (window);
 
   if (is_dir)
-    xdp_portal_open_directory (g_steal_pointer (&portal), parent, uri, XDP_OPEN_URI_FLAG_ASK, NULL, 
opened_uri, GINT_TO_POINTER (TRUE));
+    xdp_portal_open_directory (portal, parent, uri, XDP_OPEN_URI_FLAG_ASK, NULL, opened_uri, GINT_TO_POINTER 
(TRUE));
   else
-    xdp_portal_open_uri (g_steal_pointer (&portal), parent, uri, XDP_OPEN_URI_FLAG_ASK, NULL, opened_uri, 
GINT_TO_POINTER (FALSE));
+    xdp_portal_open_uri (portal, parent, uri, XDP_OPEN_URI_FLAG_ASK, NULL, opened_uri, GINT_TO_POINTER 
(FALSE));
 
   xdp_parent_free (parent);
 }


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