search: Use async functions instead of callbacks

Our search provider API has to be asynchronous to support remote
providers. It doesn't have to be based on callbacks though, now
that async functions provide a nicer alternative.

That is particularly true after gjs's D-Bus wrapper started to
generate promise-based method variants.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2344>
This commit is contained in:
Florian Müllner
2022-06-23 18:13:36 +02:00
committed by Marge Bot
parent 1cce999c30
commit 119581a4cb
3 changed files with 93 additions and 116 deletions

View File

@ -1825,7 +1825,7 @@ var AppSearchProvider = class AppSearchProvider {
this._parentalControlsManager = ParentalControlsManager.getDefault();
}
getResultMetas(apps, callback) {
getResultMetas(apps) {
const { scaleFactor } = St.ThemeContext.get_for_stage(global.stage);
let metas = [];
for (let id of apps) {
@ -1852,24 +1852,25 @@ var AppSearchProvider = class AppSearchProvider {
}
}
callback(metas);
return new Promise(resolve => resolve(metas));
}
filterResults(results, maxNumber) {
return results.slice(0, maxNumber);
}
getInitialResultSet(terms, callback, _cancellable) {
getInitialResultSet(terms, cancellable) {
// Defer until the parental controls manager is initialised, so the
// results can be filtered correctly.
if (!this._parentalControlsManager.initialized) {
let initializedId = this._parentalControlsManager.connect('app-filter-changed', () => {
if (this._parentalControlsManager.initialized) {
this._parentalControlsManager.disconnect(initializedId);
this.getInitialResultSet(terms, callback, _cancellable);
}
return new Promise(resolve => {
let initializedId = this._parentalControlsManager.connect('app-filter-changed', async () => {
if (this._parentalControlsManager.initialized) {
this._parentalControlsManager.disconnect(initializedId);
resolve(await this.getInitialResultSet(terms, cancellable));
}
});
});
return;
}
let query = terms.join(' ');
@ -1887,12 +1888,11 @@ var AppSearchProvider = class AppSearchProvider {
});
results = results.concat(this._systemActions.getMatchingActions(terms));
callback(results);
return new Promise(resolve => resolve(results));
}
getSubsearchResultSet(previousResults, terms, callback, cancellable) {
this.getInitialResultSet(terms, callback, cancellable);
getSubsearchResultSet(previousResults, terms, cancellable) {
return this.getInitialResultSet(terms, cancellable);
}
createResultObject(resultMeta) {