[gnome-shell] app-system: Filter out stale apps from cache



commit 66b71a36cef5d6514e79d088624335f370172cdf
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Mar 15 11:24:27 2014 +0100

    app-system: Filter out stale apps from cache
    
    Since rebasing our AppSystem on GLib's facilities, we only ever
    append to the id-to-app cache. So if an application is uninstalled,
    shell_app_system_lookup_app() will still happily return it if it
    was cached previously. For instance if a favorite app is uninstalled,
    it keeps lurking in the dash until a restart.
    To fix, filter out removed apps from the cache when handling
    GAppInfoMonitor::installed-changed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=726414

 src/shell-app-system.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/shell-app-system.c b/src/shell-app-system.c
index c7876c7..ac0206c 100644
--- a/src/shell-app-system.c
+++ b/src/shell-app-system.c
@@ -96,6 +96,32 @@ scan_startup_wm_class_to_id (ShellAppSystem *self)
   g_list_free_full (apps, g_object_unref);
 }
 
+static gboolean
+app_is_stale (ShellApp *app)
+{
+  GDesktopAppInfo *info;
+  gboolean is_stale;
+
+  if (shell_app_is_window_backed (app))
+    return FALSE;
+
+  info = g_desktop_app_info_new (shell_app_get_id (app));
+  is_stale = (info == NULL);
+
+  if (info)
+    g_object_unref (info);
+
+  return is_stale;
+}
+
+static gboolean
+stale_app_remove_func (gpointer key,
+                       gpointer value,
+                       gpointer user_data)
+{
+  return app_is_stale (value);
+}
+
 static void
 installed_changed (GAppInfoMonitor *monitor,
                    gpointer         user_data)
@@ -104,6 +130,8 @@ installed_changed (GAppInfoMonitor *monitor,
 
   scan_startup_wm_class_to_id (self);
 
+  g_hash_table_foreach_remove (self->priv->id_to_app, stale_app_remove_func, NULL);
+
   g_signal_emit (self, signals[INSTALLED_CHANGED], 0, NULL);
 }
 


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