From 38c8569d16e1e766879c7b172f80d39a3cf35986 Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Thu, 1 Nov 2012 15:55:41 -0400 Subject: [PATCH] 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 --- js/ui/remoteSearch.js | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/js/ui/remoteSearch.js b/js/ui/remoteSearch.js index 16c09100b..45fbda50a 100644 --- a/js/ui/remoteSearch.js +++ b/js/ui/remoteSearch.js @@ -31,10 +31,13 @@ const SearchProviderIface = var SearchProviderProxy = Gio.DBusProxy.makeProxyWrapper(SearchProviderIface); - function loadRemoteSearchProviders(addProviderCallback) { + let loadState = { loadedProviders: [], + objectPaths: {}, + numLoading: 0, + addProviderCallback: addProviderCallback }; + let dataDirs = GLib.get_system_data_dirs(); - let loadedProviders = {}; for (let i = 0; i < dataDirs.length; i++) { let path = GLib.build_filenamev([dataDirs[i], 'gnome-shell', 'search-providers']); let dir = Gio.file_new_for_path(path); @@ -52,12 +55,13 @@ function loadRemoteSearchProviders(addProviderCallback) { if (!exists) return; - loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallback); + loadState.numLoading++; + loadRemoteSearchProvidersFromDir(dir, loadState); }); } }; -function loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallback) { +function loadRemoteSearchProvidersFromDir(dir, loadState) { let dirPath = dir.get_path(); FileUtils.listDirAsync(dir, Lang.bind(this, function(files) { 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 objectPath = keyfile.get_string(group, 'ObjectPath'); - if (loadedProviders[objectPath]) + if (loadState.objectPaths[objectPath]) continue; let appInfo = null; @@ -94,18 +98,30 @@ function loadRemoteSearchProvidersFromDir(dir, loadedProviders, addProviderCallb remoteProvider = new RemoteSearchProvider(appInfo, busName, objectPath); - loadedProviders[objectPath] = remoteProvider; + loadState.objectPaths[objectPath] = remoteProvider; + loadState.loadedProviders.push(remoteProvider); } catch(e) { log('Failed to add search provider %s: %s'.format(path, e.toString())); 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({ Name: 'RemoteSearchProvider', Extends: Search.SearchProvider,