mirror of
https://github.com/elementary/gala.git
synced 2024-11-26 23:05:09 +03:00
AppCache: Rebuild in a thread (#1021)
This commit is contained in:
parent
5784505020
commit
9d15793049
@ -34,7 +34,7 @@ public class Gala.AppCache : GLib.Object {
|
|||||||
app_info_monitor = GLib.AppInfoMonitor.@get ();
|
app_info_monitor = GLib.AppInfoMonitor.@get ();
|
||||||
app_info_monitor.changed.connect (queue_cache_update);
|
app_info_monitor.changed.connect (queue_cache_update);
|
||||||
|
|
||||||
rebuild_cache ();
|
rebuild_cache.begin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queue_cache_update () {
|
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, () => {
|
queued_update_id = GLib.Timeout.add_seconds (DEFAULT_TIMEOUT_SECONDS, () => {
|
||||||
rebuild_cache ();
|
rebuild_cache.begin ((obj, res) => {
|
||||||
|
rebuild_cache.end (res);
|
||||||
changed ();
|
changed ();
|
||||||
|
|
||||||
queued_update_id = 0;
|
queued_update_id = 0;
|
||||||
|
});
|
||||||
|
|
||||||
return GLib.Source.REMOVE;
|
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 ();
|
startup_wm_class_to_id.clear ();
|
||||||
id_to_app.clear ();
|
id_to_app.clear ();
|
||||||
|
|
||||||
var app_infos = GLib.AppInfo.get_all ();
|
var app_infos = GLib.AppInfo.get_all ();
|
||||||
|
|
||||||
foreach (unowned GLib.AppInfo app in app_infos) {
|
foreach (unowned GLib.AppInfo app in app_infos) {
|
||||||
var id = app.get_id ();
|
unowned string id = app.get_id ();
|
||||||
var startup_wm_class = ((GLib.DesktopAppInfo)app).get_startup_wm_class ();
|
unowned string? startup_wm_class = ((GLib.DesktopAppInfo)app).get_startup_wm_class ();
|
||||||
|
|
||||||
id_to_app[id] = (GLib.DesktopAppInfo)app;
|
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) {
|
public GLib.DesktopAppInfo? lookup_id (string? id) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user