AppCache: Rebuild in a thread (#1021)

This commit is contained in:
David Hewitt 2021-01-17 15:35:59 +00:00 committed by GitHub
parent 5784505020
commit 9d15793049
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ public class Gala.AppCache : GLib.Object {
app_info_monitor = GLib.AppInfoMonitor.@get ();
app_info_monitor.changed.connect (queue_cache_update);
rebuild_cache ();
rebuild_cache.begin ();
}
private void queue_cache_update () {
@ -43,24 +43,30 @@ public class Gala.AppCache : GLib.Object {
}
queued_update_id = GLib.Timeout.add_seconds (DEFAULT_TIMEOUT_SECONDS, () => {
rebuild_cache ();
rebuild_cache.begin ((obj, res) => {
rebuild_cache.end (res);
changed ();
queued_update_id = 0;
});
return GLib.Source.REMOVE;
});
}
private void rebuild_cache () {
private async void rebuild_cache () {
SourceFunc callback = rebuild_cache.callback;
new Thread<void> ("rebuild_cache", () => {
lock (startup_wm_class_to_id) {
startup_wm_class_to_id.clear ();
id_to_app.clear ();
var app_infos = GLib.AppInfo.get_all ();
foreach (unowned GLib.AppInfo app in app_infos) {
var id = app.get_id ();
var startup_wm_class = ((GLib.DesktopAppInfo)app).get_startup_wm_class ();
unowned string id = app.get_id ();
unowned string? startup_wm_class = ((GLib.DesktopAppInfo)app).get_startup_wm_class ();
id_to_app[id] = (GLib.DesktopAppInfo)app;
@ -75,6 +81,12 @@ public class Gala.AppCache : GLib.Object {
}
}
Idle.add ((owned)callback);
});
yield;
}
public GLib.DesktopAppInfo? lookup_id (string? id) {
if (id == null) {
return null;