From c37ba5eb4a0d2bb6cb0830f0e201d205c84aa995 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 11 Oct 2022 19:01:21 -0300 Subject: [PATCH] background: Update background apps list This is just enough to get a background monitoring service. Most of the heavy-lifting is already done by the background portal itself, via the monitoring thread. This commit merely serialized the already up-to-date list of applications into a vardict GVariant, and updates the 'background_apps' property of the background monitor interface. --- src/background.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/background.c b/src/background.c index 8a73974ca..143d00548 100644 --- a/src/background.c +++ b/src/background.c @@ -600,6 +600,37 @@ remove_outdated_instances (int stamp) } } +static void +update_background_monitor_properties (GHashTable *app_states) +{ + GVariantBuilder builder; + GHashTableIter iter; + InstanceData *data; + char *id; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT); + + G_LOCK (applications); + g_hash_table_iter_init (&iter, applications); + while (g_hash_table_iter_next (&iter, (gpointer *)&id, (gpointer *)&data)) + { + const char *app_id; + AppState state; + + app_id = flatpak_instance_get_app (data->instance); + if (!app_id) + continue; + + state = get_one_app_state (app_id, app_states); + if (state == BACKGROUND) + g_variant_builder_add (&builder, "{sv}", "app_id", g_variant_new_string (app_id)); + } + G_UNLOCK (applications); + + xdp_dbus_background_monitor_set_background_apps (XDP_DBUS_BACKGROUND_MONITOR (background->monitor), + g_variant_builder_end (&builder)); +} + static char * flatpak_instance_get_display_name (FlatpakInstance *instance) { @@ -849,6 +880,7 @@ check_background_apps (void) } remove_outdated_instances (stamp); + update_background_monitor_properties (app_states); } static GMainContext *monitor_context;