[gnome-shell/T27795: 119/138] appDisplay: Filter out placeholder app-store apps



commit e14f3ff605d0780be03d7c415df628aa6674b9dd
Author: Sam Spilsbury <sam endlessm com>
Date:   Sat Aug 12 14:33:11 2017 +0800

    appDisplay: Filter out placeholder app-store apps
    
    We read the X-Endless-Replaced-By key in order to work out
    which apps should be replaced, so that we hide results from
    global app search that might look duplicate to the user (e.g.
    finding multiple VLC apps, or showing launchers both for the
    app and to open the App Center to install it).
    
    https://phabricator.endlessm.com/T18771

 js/ui/appDisplay.js | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index b418aee52d..d2e528b751 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -69,6 +69,8 @@ var EOS_ACTIVE_GRID_TRANSITION = Clutter.AnimationMode.EASE_IN_QUAD;
 var EOS_INACTIVE_GRID_SATURATION = 1;
 var EOS_ACTIVE_GRID_SATURATION = 0;
 
+const EOS_REPLACED_BY_KEY = 'X-Endless-Replaced-By';
+
 function _getCategories(info) {
     let categoriesStr = info.get_categories();
     if (!categoriesStr)
@@ -1017,6 +1019,8 @@ var AppSearchProvider = class AppSearchProvider {
         let groups = Shell.AppSystem.search(query);
         let usage = Shell.AppUsage.get_default();
         let results = [];
+        let replacementMap = {};
+
         groups.forEach(group => {
             group = group.filter(appID => {
                 let app = Gio.DesktopAppInfo.new(appID);
@@ -1027,7 +1031,15 @@ var AppSearchProvider = class AppSearchProvider {
                 if (!(app && app.should_show() && !(isLink && !isOnDesktop)))
                     return false;
 
-                return app && app.should_show();
+                if (app && app.should_show()) {
+                    let replacedByID = app.get_string(EOS_REPLACED_BY_KEY);
+                    if (replacedByID)
+                        replacementMap[appID] = replacedByID;
+
+                    return true;
+                }
+
+                return false;
             });
             results = results.concat(group.sort(
                 (a, b) => usage.compare(a, b)
@@ -1043,6 +1055,24 @@ var AppSearchProvider = class AppSearchProvider {
 
             return hasB - hasA;
         });
+
+        // perform replacements by removing replaceable apps
+        results = results.filter(function(appID) {
+            let replacedByID = replacementMap[appID];
+
+            // this app does not specify any replacements, show it
+            if (!replacedByID)
+                return true;
+
+            // the specified replacement is not installed, show it
+            let replacedByApp = Gio.DesktopAppInfo.new(replacedByID);
+            if (!replacedByApp)
+                return true;
+
+            // the specified replacement is installed, hide it
+            return false;
+        });
+
         callback(results);
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]