remote-search: restructure remote search provider loading process
Instead of adding search providers to the system as we find them, wait until we loaded information from all the directories, and then add all providers at once. This will be useful when we will sort the providers information according to the sort order saved in GSettings. https://bugzilla.gnome.org/show_bug.cgi?id=687491
This commit is contained in:
parent
9791d15f39
commit
38c8569d16
@ -31,10 +31,13 @@ const SearchProviderIface = <interface name="org.gnome.Shell.SearchProvider">
|
|||||||
|
|
||||||
var SearchProviderProxy = Gio.DBusProxy.makeProxyWrapper(SearchProviderIface);
|
var SearchProviderProxy = Gio.DBusProxy.makeProxyWrapper(SearchProviderIface);
|
||||||
|
|
||||||
|
|
||||||
function loadRemoteSearchProviders(addProviderCallback) {
|
function loadRemoteSearchProviders(addProviderCallback) {
|
||||||
|
let loadState = { loadedProviders: [],
|
||||||
|
objectPaths: {},
|
||||||
|
numLoading: 0,
|
||||||
|
addProviderCallback: addProviderCallback };
|
||||||
|
|
||||||
let dataDirs = GLib.get_system_data_dirs();
|
let dataDirs = GLib.get_system_data_dirs();
|
||||||
let loadedProviders = {};
|
|
||||||
for (let i = 0; i < dataDirs.length; i++) {
|
for (let i = 0; i < dataDirs.length; i++) {
|
||||||
let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', 'search-providers']);
|
let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', 'search-providers']);
|
||||||
let dir = Gio.file_new_for_path(path);
|
let dir = Gio.file_new_for_path(path);
|
||||||
@ -52,12 +55,13 @@ function loadRemoteSearchProviders(addProviderCallback) {
|
|||||||
if (!exists)
|
if (!exists)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallback);
|
loadState.numLoading++;
|
||||||
|
loadRemoteSearchProvidersFromDir(dir, loadState);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallback) {
|
function loadRemoteSearchProvidersFromDir(dir, loadState) {
|
||||||
let dirPath = dir.get_path();
|
let dirPath = dir.get_path();
|
||||||
FileUtils.listDirAsync(dir, Lang.bind(this, function(files) {
|
FileUtils.listDirAsync(dir, Lang.bind(this, function(files) {
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
@ -79,7 +83,7 @@ function loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallb
|
|||||||
let busName = keyfile.get_string(group, 'BusName');
|
let busName = keyfile.get_string(group, 'BusName');
|
||||||
let objectPath = keyfile.get_string(group, 'ObjectPath');
|
let objectPath = keyfile.get_string(group, 'ObjectPath');
|
||||||
|
|
||||||
if (loadedProviders[objectPath])
|
if (loadState.objectPaths[objectPath])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
let appInfo = null;
|
let appInfo = null;
|
||||||
@ -94,18 +98,30 @@ function loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallb
|
|||||||
remoteProvider = new RemoteSearchProvider(appInfo,
|
remoteProvider = new RemoteSearchProvider(appInfo,
|
||||||
busName,
|
busName,
|
||||||
objectPath);
|
objectPath);
|
||||||
loadedProviders[objectPath] = remoteProvider;
|
loadState.objectPaths[objectPath] = remoteProvider;
|
||||||
|
loadState.loadedProviders.push(remoteProvider);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
log('Failed to add search provider %s: %s'.format(path, e.toString()));
|
log('Failed to add search provider %s: %s'.format(path, e.toString()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
addProviderCallback(remoteProvider);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remoteProvidersDirLoaded(loadState);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function remoteProvidersDirLoaded(loadState) {
|
||||||
|
loadState.numLoading--;
|
||||||
|
if (loadState.numLoading > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
loadState.loadedProviders.forEach(
|
||||||
|
function(provider) {
|
||||||
|
loadState.addProviderCallback(provider);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const RemoteSearchProvider = new Lang.Class({
|
const RemoteSearchProvider = new Lang.Class({
|
||||||
Name: 'RemoteSearchProvider',
|
Name: 'RemoteSearchProvider',
|
||||||
Extends: Search.SearchProvider,
|
Extends: Search.SearchProvider,
|
||||||
|
Loading…
Reference in New Issue
Block a user