[gnome-shell/T29763: 97/249] appDisplay: Filter out placeholder app-store apps



commit a88a3b8aabaad330984e6949afce4dff56db789d
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 b33ac7befe..dd5c7ec065 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -70,6 +70,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)
@@ -964,6 +966,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 => {
                 const isLink = appID.startsWith(EOS_LINK_PREFIX);
@@ -974,7 +978,15 @@ var AppSearchProvider = class AppSearchProvider {
                     return false;
 
                 const app = this._appSys.lookup_app(appID);
-                return app && app.app_info.should_show();
+                if (app && app.app_info.should_show()) {
+                    let replacedByID = app.app_info.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)
@@ -990,6 +1002,24 @@ var AppSearchProvider = class AppSearchProvider {
 
             return hasB - hasA;
         });
+
+        // perform replacements by removing replaceable apps
+        results = results.filter(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]