[gnome-shell/eos3.8: 121/255] AppIconBar: Hide favorite apps that are blacklisted by parental controls



commit b7031e33d6ce8974fd49d266d1a6db1fa1f2da5d
Author: Andre Moreira Magalhaes <andre endlessm com>
Date:   Wed Jul 10 21:06:19 2019 +0000

    AppIconBar: Hide favorite apps that are blacklisted by parental controls
    
    Note that this code hides the app button when the app is blacklisted
    instead of removing it so that we can more easily restore the original
    position in the favorites list when the app gets re-enabled.
    
    Also if an app is running and gets blacklisted, the app button will be
    displayed until the app gets closed.
    
    Signed-off-by: Andre Moreira Magalhaes <andre endlessm com>
    
     * 2020-03-23: Squash with f87080827
    
    https://phabricator.endlessm.com/T27191

 js/ui/appIconBar.js | 52 +++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 43 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/appIconBar.js b/js/ui/appIconBar.js
index ca1df8dbc2..0640d26891 100644
--- a/js/ui/appIconBar.js
+++ b/js/ui/appIconBar.js
@@ -10,6 +10,7 @@ const AppFavorites = imports.ui.appFavorites;
 const BoxPointer = imports.ui.boxpointer;
 const Main = imports.ui.main;
 const PanelMenu = imports.ui.panelMenu;
+const ParentalControlsManager = imports.misc.parentalControlsManager;
 const PopupMenu = imports.ui.popupMenu;
 
 const MAX_OPACITY = 255;
@@ -624,6 +625,9 @@ const ScrolledIconList = GObject.registerClass({
         this._container.connect('style-changed', this._updateStyleConstants.bind(this));
 
         let appSys = Shell.AppSystem.get_default();
+
+        this._parentalControlsManager = ParentalControlsManager.getDefault();
+
         this._taskbarApps = new Map();
 
         // Update for any apps running before the system started
@@ -652,6 +656,15 @@ const ScrolledIconList = GObject.registerClass({
             this._addButtonAnimated(sortedPid.app);
 
         appSys.connect('app-state-changed', this._onAppStateChanged.bind(this));
+
+        this._parentalControlsManager.connect('app-filter-changed', () => {
+            for (let [app, appButton] of this._taskbarApps) {
+                let shouldShow = this._parentalControlsManager.shouldShowApp(app.get_app_info());
+                let stopped = app.state === Shell.AppState.STOPPED;
+
+                appButton.visible = !stopped || shouldShow;
+            }
+        });
     }
 
     setActiveApp(app) {
@@ -669,6 +682,13 @@ const ScrolledIconList = GObject.registerClass({
         return this._taskbarApps.size;
     }
 
+    getNumVisibleAppButtons() {
+        let buttons = [...this._taskbarApps.values()];
+        return buttons.reduce((counter, appButton) => {
+            return appButton.visible ? counter : counter + 1;
+        }, 0);
+    }
+
     activateNthApp(index) {
         let buttons = [...this._taskbarApps.values()];
         let appButton = buttons[index];
@@ -686,7 +706,7 @@ const ScrolledIconList = GObject.registerClass({
 
     _updatePage() {
         // Clip the values of the iconOffset
-        let lastIconOffset = this._taskbarApps.size - 1;
+        let lastIconOffset = this.getNumVisibleAppButtons() - 1;
         let movableIconsPerPage = this._appsPerPage - 1;
         let iconOffset = Math.max(0, this._iconOffset);
         iconOffset = Math.min(lastIconOffset - movableIconsPerPage, iconOffset);
@@ -731,7 +751,7 @@ const ScrolledIconList = GObject.registerClass({
     }
 
     isForwardAllowed() {
-        return this._iconOffset < this._taskbarApps.size - this._appsPerPage;
+        return this._iconOffset < this.getNumVisibleAppButtons() - this._appsPerPage;
     }
 
     calculateNaturalSize(forWidth) {
@@ -837,6 +857,11 @@ const ScrolledIconList = GObject.registerClass({
         this._taskbarApps.set(app, newChild);
 
         this._container.add_actor(newActor);
+
+        if (app.state == Shell.AppState.STOPPED &&
+            !this._parentalControlsManager.shouldShowApp(app.get_app_info())) {
+            newActor.hide();
+        }
     }
 
     _addButton(app) {
@@ -847,22 +872,31 @@ const ScrolledIconList = GObject.registerClass({
         let state = app.state;
         switch (state) {
         case Shell.AppState.STARTING:
+            if (!this._parentalControlsManager.shouldShowApp(app.get_app_info()))
+                break;
+            this._addButton(app);
+            this._ensureIsVisible(app);
+            break;
+
         case Shell.AppState.RUNNING:
             this._addButton(app);
             this._ensureIsVisible(app);
             break;
 
         case Shell.AppState.STOPPED: {
-            if (AppFavorites.getAppFavorites().isFavorite(app.get_id()))
+            const appButton = this._taskbarApps.get(app);
+            if (!appButton)
                 break;
 
-            let oldChild = this._taskbarApps.get(app);
-            if (oldChild) {
-                let oldButton = this._taskbarApps.get(app);
-                this._container.remove_actor(oldButton);
-                this._taskbarApps.delete(app);
+            if (AppFavorites.getAppFavorites().isFavorite(app.get_id())) {
+                if (!this._parentalControlsManager.shouldShowApp(app.get_app_info()))
+                    appButton.hide();
+                break;
             }
 
+            this._container.remove_actor(appButton);
+            this._taskbarApps.delete(app);
+
             break;
         }
         }
@@ -878,7 +912,7 @@ const ScrolledIconList = GObject.registerClass({
         let iconsPerPage = Math.floor((forWidth + this._iconSpacing) / minimumIconWidth);
         iconsPerPage = Math.max(1, iconsPerPage);
 
-        let pages = Math.ceil(this._taskbarApps.size / iconsPerPage);
+        let pages = Math.ceil(this.getNumVisibleAppButtons() / iconsPerPage);
         return [pages, iconsPerPage];
     }
 });


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