Blame SOURCES/0004-open-uri-Show-app-chooser-when-default-app-does-not-.patch

e90b52
From c056c8ee9eb5401564026a0bb963817073b3bced Mon Sep 17 00:00:00 2001
e90b52
From: Bastien Nocera <hadess@hadess.net>
e90b52
Date: Thu, 7 May 2020 11:39:27 +0200
e90b52
Subject: [PATCH 4/5] open-uri: Show app chooser when default app does not
e90b52
 exist
e90b52
e90b52
Fix a possible crash when the application that would be selected to
e90b52
avoid the app chooser is not available (anymore).
e90b52
e90b52
This would have happened when eog.desktop got renamed to
e90b52
org.gnome.eog.desktop but was launched enough times as eog.desktop to
e90b52
make it the default.
e90b52
e90b52
Based on https://github.com/flatpak/xdg-desktop-portal/pull/481
e90b52
e90b52
(cherry picked from commit 69205f12cc57542a7c38c1b631fa8a8d9529f5d6)
e90b52
---
e90b52
 src/open-uri.c | 17 +++++++++++++++--
e90b52
 1 file changed, 15 insertions(+), 2 deletions(-)
e90b52
e90b52
diff --git a/src/open-uri.c b/src/open-uri.c
e90b52
index 21b180e..1564753 100644
e90b52
--- a/src/open-uri.c
e90b52
+++ b/src/open-uri.c
e90b52
@@ -535,6 +535,15 @@ app_info_changed (GAppInfoMonitor *monitor,
e90b52
                                             NULL);
e90b52
 }
e90b52
 
e90b52
+static gboolean
e90b52
+app_exists (const char *app_id)
e90b52
+{
e90b52
+  g_autoptr(GDesktopAppInfo) info = NULL;
e90b52
+
e90b52
+  info = g_desktop_app_info_new (app_id);
e90b52
+  return (info != NULL);
e90b52
+}
e90b52
+
e90b52
 static void
e90b52
 handle_open_in_thread_func (GTask *task,
e90b52
                             gpointer source_object,
e90b52
@@ -632,10 +641,14 @@ handle_open_in_thread_func (GTask *task,
e90b52
 
e90b52
   /* collect all the information */
e90b52
   find_recommended_choices (scheme, content_type, &default_app, &choices, &n_choices);
e90b52
+  if (!app_exists (default_app))
e90b52
+    g_clear_pointer (&default_app, g_free);
e90b52
   use_default_app = should_use_default_app (scheme, content_type);
e90b52
   get_latest_choice_info (app_id, content_type,
e90b52
                           &latest_id, &latest_count, &latest_threshold,
e90b52
                           &ask_for_content_type);
e90b52
+  if (!app_exists (latest_id))
e90b52
+    g_clear_pointer (&latest_id, g_free);
e90b52
 
e90b52
   skip_app_chooser = FALSE;
e90b52
   reason = NULL;
e90b52
@@ -682,7 +695,7 @@ handle_open_in_thread_func (GTask *task,
e90b52
 
e90b52
   if (skip_app_chooser)
e90b52
     {
e90b52
-      const char *app;
e90b52
+      const char *app = NULL;
e90b52
 
e90b52
       if (default_app != NULL && use_default_app)
e90b52
         app = default_app;
e90b52
@@ -690,7 +703,7 @@ handle_open_in_thread_func (GTask *task,
e90b52
         app = latest_id;
e90b52
       else if (default_app != NULL)
e90b52
         app = default_app;
e90b52
-      else
e90b52
+      else if (choices && app_exists (choices[0]))
e90b52
         app = choices[0];
e90b52
 
e90b52
       if (app)
e90b52
-- 
e90b52
2.26.2
e90b52