diff --git a/js/misc/appInfo.js b/js/misc/appInfo.js index 4b6dde673..2e9a96620 100644 --- a/js/misc/appInfo.js +++ b/js/misc/appInfo.js @@ -71,39 +71,43 @@ function getAppInfo(appId) { return info; } -// getMostUsedApps: +// getTopApps: // @count: maximum number of apps to retrieve // // Gets a list of #AppInfos for the @count most-frequently-used -// applications +// applications, with explicitly-chosen favorites first. // // Return value: the list of #AppInfo -function getMostUsedApps(count) { +function getTopApps(count) { let appMonitor = Shell.AppMonitor.get_default(); + let matches = [], alreadyAdded = {}; + + let favs = getFavorites(); + for (let i = 0; i < favs.length && favs.length <= count; i++) { + let appId = favs[i].appId; + + if (alreadyAdded[appId]) + continue; + alreadyAdded[appId] = true; + + matches.push(favs[i]); + } + // Ask for more apps than we need, since the list of recently used // apps might contain an app we don't have a desktop file for let apps = appMonitor.get_most_used_apps (0, Math.round(count * 1.5)); - let matches = [], alreadyAdded = {}; - for (let i = 0; i < apps.length && matches.length <= count; i++) { let appId = apps[i] + ".desktop"; + if (alreadyAdded[appId]) + continue; + alreadyAdded[appId] = true; let appInfo = getAppInfo(appId); if (appInfo) { matches.push(appInfo); - alreadyAdded[appId] = true; } } - let favs = getFavorites(); - // Fill the list with default applications it's not full yet - for (let i = 0; i < favs.length && favs.length <= count; i++) { - let appId = favs[i].appId; - if (alreadyAdded[appId]) - continue; - matches.push(favs[i]); - } - return matches; } @@ -126,11 +130,5 @@ function getFavorites() { function getRunning() { let monitor = Shell.AppMonitor.get_default(); - let basename = function (n) { - let i = n.lastIndexOf('/'); - if (i < 0) - return n; - return n.substring(i+1); - } - return _idListToInfos(monitor.get_running_app_ids().map(basename)); + return _idListToInfos(monitor.get_running_app_ids()); } diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 93d330485..77db9b041 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -351,7 +351,7 @@ AppDisplay.prototype = { // Sets the list of the displayed items based on the most used apps. _setDefaultList : function() { - let matchedInfos = AppInfo.getMostUsedApps(MAX_ITEMS); + let matchedInfos = AppInfo.getTopApps(MAX_ITEMS); this._matchedItems = matchedInfos.map(function(info) { return info.appId; }); }, @@ -519,7 +519,6 @@ WellArea.prototype = { children = this.actor.get_children(); children.forEach(Lang.bind(this, function (v) { - this.actor.remove_actor(v); v.destroy(); })); @@ -550,6 +549,8 @@ WellArea.prototype = { Mainloop.idle_add(function () { appSystem.add_favorite(id); }); + } else { + return false; } return true; diff --git a/js/ui/widget.js b/js/ui/widget.js index 8a0644f8e..0984c5de1 100644 --- a/js/ui/widget.js +++ b/js/ui/widget.js @@ -284,7 +284,7 @@ AppsWidget.prototype = { this.actor = new Big.Box({ spacing: 2 }); this.collapsedActor = new Big.Box({ spacing: 2}); - let apps = AppInfo.getMostUsedApps(5); + let apps = AppInfo.getTopApps(5); for (let i = 0; i < apps.length; i++) this.addItem(apps[i]); }