[epiphany/mwleeds/webapp-dbus-api: 1/4] Allow launching apps and URIs from Flatpak
- From: Phaedrus Leeds <mwleeds src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/mwleeds/webapp-dbus-api: 1/4] Allow launching apps and URIs from Flatpak
- Date: Fri, 17 Dec 2021 22:40:00 +0000 (UTC)
commit 3dc2d44735f3cb5a989f1aa2f7aedee3a75283a9
Author: Phaedrus Leeds <mwleeds protonmail com>
Date: Fri Dec 17 14:03:13 2021 -0800
Allow launching apps and URIs from Flatpak
It is possible to launch a web app (initiated by the user clicking on
the install completed notification) from within Flatpak, and it's
possible to open a URI from within Flatpak, so let these code paths
execute from Flatpaks. Follow-up commits will enable the rest of the web
app functionality under Flatpak.
lib/ephy-file-helpers.c | 43 ++++++++++++++-----------------------------
lib/ephy-file-helpers.h | 26 +++++++++-----------------
lib/ephy-flatpak-utils.c | 14 ++++++++++++++
lib/ephy-flatpak-utils.h | 1 +
org.gnome.Epiphany.json | 3 ++-
src/ephy-shell.c | 8 ++------
src/ephy-window.c | 12 ++----------
src/window-commands.c | 6 ++----
8 files changed, 46 insertions(+), 67 deletions(-)
---
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index d1ad88e26..27a92231c 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -551,11 +551,6 @@ launch_application (GAppInfo *app,
GdkScreen *screen;
gboolean res;
- /* This is impossible to implement inside sandbox. Higher layers must
- * ensure we don't get here.
- */
- g_assert (!ephy_is_running_inside_sandbox ());
-
display = gdk_display_get_default ();
screen = gdk_screen_get_default ();
@@ -572,28 +567,20 @@ launch_application (GAppInfo *app,
}
/**
- * ephy_file_launch_desktop_file:
- * @filename: the path to the .desktop file
- * @tag: used to guard against improper usage
+ * ephy_file_launch_webapp_desktop_file:
+ * @filename: the path to the .desktop file of a web app
*
* Launches the application described by the desktop file @filename.
*
* Returns: %TRUE if the application launch was successful
**/
gboolean
-ephy_file_launch_desktop_file (const char *filename,
- guint32 user_time,
- EphyFileHelpersNotFlatpakTag tag)
+ephy_file_launch_webapp_desktop_file (const char *filename,
+ guint32 user_time)
{
g_autoptr (GDesktopAppInfo) app = NULL;
- /* This is impossible to implement inside sandbox. Higher layers must
- * ensure we don't get here.
- */
- g_assert (tag == EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
- g_assert (!ephy_is_running_inside_sandbox ());
-
- app = g_desktop_app_info_new (filename);
+ app = g_desktop_app_info_new_from_filename (filename);
return launch_application (G_APP_INFO (app), NULL, user_time);
}
@@ -665,20 +652,13 @@ static gboolean
open_in_default_handler (const char *uri,
const char *mime_type,
guint32 timestamp,
- GdkScreen *screen,
- EphyFileHelpersNotFlatpakTag tag)
+ GdkScreen *screen)
{
g_autoptr (GdkAppLaunchContext) context = NULL;
g_autoptr (GAppInfo) appinfo = NULL;
g_autoptr (GError) error = NULL;
GList uris;
- /* This is impossible to implement inside sandbox. Higher layers must
- * ensure we don't get here.
- */
- g_assert (tag == EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
- g_assert (!ephy_is_running_inside_sandbox ());
-
context = gdk_display_get_app_launch_context (screen ? gdk_screen_get_display (screen) :
gdk_display_get_default ());
gdk_app_launch_context_set_screen (context, screen);
gdk_app_launch_context_set_timestamp (context, timestamp);
@@ -703,10 +683,15 @@ open_in_default_handler (const char *uri,
gboolean
ephy_file_open_uri_in_default_browser (const char *uri,
guint32 user_time,
- GdkScreen *screen,
- EphyFileHelpersNotFlatpakTag tag)
+ GdkScreen *screen)
{
- return open_in_default_handler (uri, "x-scheme-handler/http", user_time, screen, tag);
+ if (ephy_is_running_inside_sandbox ())
+ {
+ ephy_open_uri_via_flatpak_portal (uri);
+ return TRUE;
+ }
+ else
+ return open_in_default_handler (uri, "x-scheme-handler/http", user_time, screen);
}
/**
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index c09d145c8..1991641de 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -72,22 +72,14 @@ gboolean ephy_file_delete_dir_recursively (const char
char * ephy_sanitize_filename (char *filename);
void ephy_open_default_instance_window (void);
void ephy_open_incognito_window (const char *uri);
-
-/* These functions attempt to launch a particular application chosen by
- * Epiphany, which is not possible to do when running inside flatpak. Be
- * careful!
- */
-gboolean ephy_file_launch_desktop_file (const char *filename,
- guint32 user_time,
- EphyFileHelpersNotFlatpakTag tag);
-gboolean ephy_file_open_uri_in_default_browser (const char *uri,
- guint32 user_time,
- GdkScreen *screen,
- EphyFileHelpersNotFlatpakTag tag);
-gboolean ephy_file_browse_to (GFile *file,
- guint32 user_time);
-
-void ephy_copy_directory (const char *source,
- const char *target);
+gboolean ephy_file_launch_webapp_desktop_file (const char *filepath,
+ guint32 user_time);
+gboolean ephy_file_open_uri_in_default_browser (const char *uri,
+ guint32 user_time,
+ GdkScreen *screen);
+gboolean ephy_file_browse_to (GFile *file,
+ guint32 user_time);
+void ephy_copy_directory (const char *source,
+ const char *target);
G_END_DECLS
diff --git a/lib/ephy-flatpak-utils.c b/lib/ephy-flatpak-utils.c
index 6fc9a5dec..568dbcde9 100644
--- a/lib/ephy-flatpak-utils.c
+++ b/lib/ephy-flatpak-utils.c
@@ -140,3 +140,17 @@ ephy_open_uri_via_flatpak_portal (const char *uri)
{
ephy_open_uri (uri, FALSE);
}
+
+gboolean
+ephy_can_install_web_apps (void)
+{
+ if (!ephy_is_running_inside_sandbox ())
+ return TRUE;
+
+#if USE_LIBPORTAL
+ //TODO bump version requirement of libportal and also check that the portal is available
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
diff --git a/lib/ephy-flatpak-utils.h b/lib/ephy-flatpak-utils.h
index 15b85ac9b..289663efb 100644
--- a/lib/ephy-flatpak-utils.h
+++ b/lib/ephy-flatpak-utils.h
@@ -30,3 +30,4 @@ void ephy_open_uri_via_flatpak_portal (const char *uri);
void ephy_open_directory_via_flatpak_portal (const char *uri);
+gboolean ephy_can_install_web_apps (void);
diff --git a/org.gnome.Epiphany.json b/org.gnome.Epiphany.json
index d58f3bd86..f9a81ccd9 100644
--- a/org.gnome.Epiphany.json
+++ b/org.gnome.Epiphany.json
@@ -18,7 +18,8 @@
"--socket=pulseaudio",
"--socket=wayland",
"--system-talk-name=org.freedesktop.GeoClue2",
- "--own-name=org.gnome.Epiphany.WebAppProvider"
+ "--own-name=org.gnome.Epiphany.WebAppProvider",
+ "--own-name=org.gnome.Epiphany.*"
],
"modules" : [
{
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 0ace095aa..d356ee168 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -335,12 +335,8 @@ launch_app (GSimpleAction *action,
{
const gchar *desktop_file = g_variant_get_string (parameter, NULL);
- /* We can't get here under flatpak because all web app functionality
- * is disabled when running under flatpak.
- */
- ephy_file_launch_desktop_file (desktop_file,
- gtk_get_current_event_time (),
- EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+ ephy_file_launch_webapp_desktop_file (desktop_file,
+ gtk_get_current_event_time ());
}
static void
diff --git a/src/ephy-window.c b/src/ephy-window.c
index ab8caedf5..640eefc74 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2126,12 +2126,8 @@ decide_navigation_policy (WebKitWebView *web_view,
if (ephy_web_application_is_uri_allowed (uri)) {
gtk_widget_show (GTK_WIDGET (window));
} else {
- /* We can't get here under sandbox because this code only
- * executes in web app mode.
- */
ephy_file_open_uri_in_default_browser (uri, GDK_CURRENT_TIME,
- gtk_window_get_screen (GTK_WINDOW (window)),
-
EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+ gtk_window_get_screen (GTK_WINDOW (window)));
webkit_policy_decision_ignore (decision);
gtk_widget_destroy (GTK_WIDGET (window));
@@ -2145,12 +2141,8 @@ decide_navigation_policy (WebKitWebView *web_view,
if (ephy_web_application_is_uri_allowed (uri))
return accept_navigation_policy_decision (window, decision, uri);
- /* We can't get here under sandbox because this code only
- * executes in web app mode.
- */
ephy_file_open_uri_in_default_browser (uri, GDK_CURRENT_TIME,
- gtk_window_get_screen (GTK_WINDOW (window)),
-
EPHY_FILE_HELPERS_I_UNDERSTAND_I_MUST_NOT_USE_THIS_FUNCTION_UNDER_FLATPAK);
+ gtk_window_get_screen (GTK_WINDOW (window)));
webkit_policy_decision_ignore (decision);
return TRUE;
diff --git a/src/window-commands.c b/src/window-commands.c
index 07ed22cea..ab629630a 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1807,11 +1807,9 @@ save_as_application_proceed (EphyApplicationDialogData *data)
}
if (desktop_file) {
- g_autofree char *basename = g_path_get_basename (desktop_file);
-
/* Translators: Desktop notification when a new web app is created. */
- g_notification_add_button_with_target (notification, _("Launch"), "app.launch-app", "s", basename);
- g_notification_set_default_action_and_target (notification, "app.launch-app", "s", basename);
+ g_notification_add_button_with_target (notification, _("Launch"), "app.launch-app", "s", desktop_file);
+ g_notification_set_default_action_and_target (notification, "app.launch-app", "s", desktop_file);
ephy_focus_desktop_app (desktop_file);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]