From 7d7b99e2d3dfa2c3350dc2a0ddb1eb2bb4231ecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Fri, 24 Jun 2022 19:25:24 +0200 Subject: [PATCH] appDisplay: Simplify loading Folder apps a bit Instead of plugging into _redisplay(), we can use _loadApps() for this. It's actually exactly what _loadApps() is meant for... Part-of: --- js/ui/appDisplay.js | 99 +++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 57 deletions(-) diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js index 91c428a07..a9b876e31 100644 --- a/js/ui/appDisplay.js +++ b/js/ui/appDisplay.js @@ -2137,7 +2137,7 @@ class FolderView extends BaseAppView { this._scrollView.add_action(action); this._deletingFolder = false; - this._appIds = []; + this._apps = []; this._redisplay(); } @@ -2145,48 +2145,8 @@ class FolderView extends BaseAppView { return new FolderGrid(); } - _getFolderApps() { - const appIds = []; - const excludedApps = this._folder.get_strv('excluded-apps'); - const appSys = Shell.AppSystem.get_default(); - const addAppId = appId => { - if (excludedApps.includes(appId)) - return; - - if (this._appFavorites.isFavorite(appId)) - return; - - const app = appSys.lookup_app(appId); - if (!app) - return; - - if (!this._parentalControlsManager.shouldShowApp(app.get_app_info())) - return; - - if (appIds.indexOf(appId) !== -1) - return; - - appIds.push(appId); - }; - - const folderApps = this._folder.get_strv('apps'); - folderApps.forEach(addAppId); - - const folderCategories = this._folder.get_strv('categories'); - const appInfos = this._parentView.getAppInfos(); - appInfos.forEach(appInfo => { - let appCategories = _getCategories(appInfo); - if (!_listsIntersect(folderCategories, appCategories)) - return; - - addAppId(appInfo.get_id()); - }); - - return appIds; - } - _getItemPosition(item) { - const appIndex = this._appIds.indexOf(item.id); + const appIndex = this._apps.indexOf(item.app); if (appIndex === -1) return [-1, -1]; @@ -2196,8 +2156,8 @@ class FolderView extends BaseAppView { } _compareItems(a, b) { - const aPosition = this._appIds.indexOf(a.id); - const bPosition = this._appIds.indexOf(b.id); + const aPosition = this._apps.indexOf(a.app); + const bPosition = this._apps.indexOf(b.app); if (aPosition === -1 && bPosition === -1) return a.name.localeCompare(b.name); @@ -2243,27 +2203,52 @@ class FolderView extends BaseAppView { } _loadApps() { - let apps = []; - let appSys = Shell.AppSystem.get_default(); + this._apps = []; + const excludedApps = this._folder.get_strv('excluded-apps'); + const appSys = Shell.AppSystem.get_default(); + const addAppId = appId => { + if (excludedApps.includes(appId)) + return; + + if (this._appFavorites.isFavorite(appId)) + return; - this._appIds.forEach(appId => { const app = appSys.lookup_app(appId); + if (!app) + return; - let icon = this._items.get(appId); + if (!this._parentalControlsManager.shouldShowApp(app.get_app_info())) + return; + + if (this._apps.indexOf(app) !== -1) + return; + + this._apps.push(app); + }; + + const folderApps = this._folder.get_strv('apps'); + folderApps.forEach(addAppId); + + const folderCategories = this._folder.get_strv('categories'); + const appInfos = this._parentView.getAppInfos(); + appInfos.forEach(appInfo => { + let appCategories = _getCategories(appInfo); + if (!_listsIntersect(folderCategories, appCategories)) + return; + + addAppId(appInfo.get_id()); + }); + + let items = []; + this._apps.forEach(app => { + let icon = this._items.get(app.get_id()); if (!icon) icon = new AppIcon(app); - apps.push(icon); + items.push(icon); }); - return apps; - } - - _redisplay() { - // Keep the app ids list cached - this._appIds = this._getFolderApps(); - - super._redisplay(); + return items; } acceptDrop(source) {