Taken from upstream, fixes an issue where an application launcher would in some cases disappear making it impossible to launch that application via the GUI. From 1b642cd8ba63fd10ad40030e1e9c16e04c090e6e Mon Sep 17 00:00:00 2001 From: Zander Brown Date: Fri, 19 Jun 2020 19:49:14 +0100 Subject: [PATCH] app-list-model: phantom launcher At last a fix for the missing item problem tl;dr: we skipped the first entry The reason it was weirdly deterministic is that we _always_ skipped the first item and as long as the entries didn't change the item would _always_ be the same Why was the item seemingly random? Because the list doesn't have any sorting at the point we lost an item So why didn't this effect more people? A system has many, many entries - a lot of which aren't actually app launchers. For example my laptop currently has 301 entries of which 172 should actually be shown. By pure fluke we got lucky most of the time and skipped an unintersting one. The fix is painfully simple: iterate the GList properly --- src/app-list-model.c | 18 +++++++++-------- tools/dump-app-list.c | 47 +++++++++++++++++++++++++++++++++++++++++++ tools/meson.build | 3 +++ 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 tools/dump-app-list.c diff --git a/src/app-list-model.c b/src/app-list-model.c index 648ee00..5281985 100644 --- a/src/app-list-model.c +++ b/src/app-list-model.c @@ -1,12 +1,14 @@ /* - * Copyright © 2019 Zander Brown + * Copyright © 2019-2020 Zander Brown * * Inspired by gliststore.c: * Copyright 2015 Lars Uebernickel * Copyright 2015 Ryan Lortie * https://gitlab.gnome.org/GNOME/glib/blob/713fec9dcb1ee49c4f64bbb6f483a5cd1db9966a/gio/gliststore.c * - * SPDX-License-Identifier: GPL-3.0+ + * SPDX-License-Identifier: GPL-3-or-later + * + * Author: Zander Brown */ #include "app-list-model.h" @@ -116,27 +118,27 @@ items_changed (gpointer data) { PhoshAppListModel *self = PHOSH_APP_LIST_MODEL (data); PhoshAppListModelPrivate *priv = phosh_app_list_model_get_instance_private (self); - GList *new_apps; + g_autolist(GAppInfo) new_apps = NULL; int removed; int added = 0; new_apps = g_app_info_get_all (); + g_return_val_if_fail (new_apps != NULL, G_SOURCE_REMOVE); + removed = g_sequence_get_length (priv->items); g_sequence_remove_range (g_sequence_get_begin_iter (priv->items), g_sequence_get_end_iter (priv->items)); - while ((new_apps = g_list_next (new_apps))) { - if (!g_app_info_should_show (G_APP_INFO (new_apps->data))) { + for (GList *l = new_apps; l; l = g_list_next (l)) { + if (!g_app_info_should_show (G_APP_INFO (l->data))) { continue; } - g_sequence_append (priv->items, g_object_ref (new_apps->data)); + g_sequence_append (priv->items, g_object_ref (l->data)); added++; } - g_list_free_full (new_apps, g_object_unref); - priv->last.is_valid = FALSE; priv->last.iter = NULL; priv->last.position = 0; diff --git a/tools/dump-app-list.c b/tools/dump-app-list.c new file mode 100644 index 0000000..2f7919d --- /dev/null +++ b/tools/dump-app-list.c @@ -0,0 +1,47 @@ +/* + * Copyright © 2020 Zander Brown + * + * SPDX-License-Identifier: GPL-3-or-later + * + * Author: Zander Brown + * + * Print the contents of PhoshAppListModel + */ + +#include + +int +main (int argc, char **argv) +{ + PhoshAppListModel *list = phosh_app_list_model_get_default (); + int i = 0; + GAppInfo *info; + GMainLoop *loop; + + g_print ("Populating...\n"); + + /* Let the main loop run a bit for the timeouts/idle callbacks to run */ + loop = g_main_loop_new (NULL, FALSE); + g_timeout_add_seconds (2, G_SOURCE_FUNC (g_main_loop_quit), loop); + g_main_loop_run (loop); + + while ((info = g_list_model_get_item (G_LIST_MODEL (list), i))) { + if (G_IS_DESKTOP_APP_INFO (info)) { + g_print ("%s\n - %s\n", + g_app_info_get_id (info), + g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (info))); + } else { + /* Unlikely but handle it just in case */ + g_print ("%s\n - %s\n", + g_app_info_get_id (info), + G_OBJECT_TYPE_NAME (info)); + } + + i++; + g_clear_object (&info); + } + + g_print ("=== %i items\n", i); + + return 0; +} diff --git a/tools/meson.build b/tools/meson.build index 65a6a6d..d3fdd13 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -34,3 +34,6 @@ executable('notify-blocks', ['notify-blocks.c'], executable('notify-server-standalone', ['notify-server-standalone.c'] + stubs, dependencies: phosh_dep) + +executable('dump-app-list', ['dump-app-list.c'], + dependencies: phosh_dep) -- 2.27.0