Skip to content

Commit

Permalink
background: Update background apps list
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
GeorgesStavracas committed Oct 11, 2022
1 parent 46a1f8e commit c37ba5e
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -849,6 +880,7 @@ check_background_apps (void)
}

remove_outdated_instances (stamp);
update_background_monitor_properties (app_states);
}

static GMainContext *monitor_context;
Expand Down

0 comments on commit c37ba5e

Please sign in to comment.