[epiphany] Use a global XdpPortal object



commit 88cb0505cf55069f3aa36e50595cc2e32fc3bd38
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 42fff8a79..1ddde58b0 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -40,6 +40,7 @@
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
+#include <libportal/portal-helpers.h>
 #include <libxml/xmlreader.h>
 #include <stdlib.h>
 #include <string.h>
@@ -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;
 
 /**
@@ -489,6 +492,8 @@ ephy_file_helpers_init (const char            *profile_dir,
     }
   }
 
+  global_portal = xdp_portal_new ();
+
   return ret;
 }
 
@@ -523,6 +528,8 @@ ephy_file_helpers_shutdown (void)
     g_free (tmp_dir);
     tmp_dir = NULL;
   }
+
+  g_clear_object (&global_portal);
 }
 
 /**
@@ -923,3 +930,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 6c74acf38..46b7fc459 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)
@@ -77,5 +78,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..351276e54 100644
--- a/lib/ephy-flatpak-utils.c
+++ b/lib/ephy-flatpak-utils.c
@@ -22,6 +22,7 @@
 #define _GNU_SOURCE
 
 #include <config.h>
+#include "ephy-file-helpers.h"
 #include "ephy-flatpak-utils.h"
 
 #include <errno.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]