Update for review of e57b7ec335
This commit is contained in:
parent
39e31a3aa9
commit
e191636f34
@ -71,39 +71,43 @@ function getAppInfo(appId) {
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMostUsedApps:
|
// getTopApps:
|
||||||
// @count: maximum number of apps to retrieve
|
// @count: maximum number of apps to retrieve
|
||||||
//
|
//
|
||||||
// Gets a list of #AppInfos for the @count most-frequently-used
|
// Gets a list of #AppInfos for the @count most-frequently-used
|
||||||
// applications
|
// applications, with explicitly-chosen favorites first.
|
||||||
//
|
//
|
||||||
// Return value: the list of #AppInfo
|
// Return value: the list of #AppInfo
|
||||||
function getMostUsedApps(count) {
|
function getTopApps(count) {
|
||||||
let appMonitor = Shell.AppMonitor.get_default();
|
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
|
// 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
|
// 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 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++) {
|
for (let i = 0; i < apps.length && matches.length <= count; i++) {
|
||||||
let appId = apps[i] + ".desktop";
|
let appId = apps[i] + ".desktop";
|
||||||
|
if (alreadyAdded[appId])
|
||||||
|
continue;
|
||||||
|
alreadyAdded[appId] = true;
|
||||||
let appInfo = getAppInfo(appId);
|
let appInfo = getAppInfo(appId);
|
||||||
if (appInfo) {
|
if (appInfo) {
|
||||||
matches.push(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;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +130,5 @@ function getFavorites() {
|
|||||||
|
|
||||||
function getRunning() {
|
function getRunning() {
|
||||||
let monitor = Shell.AppMonitor.get_default();
|
let monitor = Shell.AppMonitor.get_default();
|
||||||
let basename = function (n) {
|
return _idListToInfos(monitor.get_running_app_ids());
|
||||||
let i = n.lastIndexOf('/');
|
|
||||||
if (i < 0)
|
|
||||||
return n;
|
|
||||||
return n.substring(i+1);
|
|
||||||
}
|
|
||||||
return _idListToInfos(monitor.get_running_app_ids().map(basename));
|
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ AppDisplay.prototype = {
|
|||||||
|
|
||||||
// Sets the list of the displayed items based on the most used apps.
|
// Sets the list of the displayed items based on the most used apps.
|
||||||
_setDefaultList : function() {
|
_setDefaultList : function() {
|
||||||
let matchedInfos = AppInfo.getMostUsedApps(MAX_ITEMS);
|
let matchedInfos = AppInfo.getTopApps(MAX_ITEMS);
|
||||||
this._matchedItems = matchedInfos.map(function(info) { return info.appId; });
|
this._matchedItems = matchedInfos.map(function(info) { return info.appId; });
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -519,7 +519,6 @@ WellArea.prototype = {
|
|||||||
|
|
||||||
children = this.actor.get_children();
|
children = this.actor.get_children();
|
||||||
children.forEach(Lang.bind(this, function (v) {
|
children.forEach(Lang.bind(this, function (v) {
|
||||||
this.actor.remove_actor(v);
|
|
||||||
v.destroy();
|
v.destroy();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -550,6 +549,8 @@ WellArea.prototype = {
|
|||||||
Mainloop.idle_add(function () {
|
Mainloop.idle_add(function () {
|
||||||
appSystem.add_favorite(id);
|
appSystem.add_favorite(id);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -284,7 +284,7 @@ AppsWidget.prototype = {
|
|||||||
this.actor = new Big.Box({ spacing: 2 });
|
this.actor = new Big.Box({ spacing: 2 });
|
||||||
this.collapsedActor = 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++)
|
for (let i = 0; i < apps.length; i++)
|
||||||
this.addItem(apps[i]);
|
this.addItem(apps[i]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user