[gnome-shell] appMenu: Only show 'Quit' for running apps



commit 321e07c3c6be5339e1df50218a8cf031915f8add
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 12 02:47:23 2021 +0200

    appMenu: Only show 'Quit' for running apps
    
    The top bar menu always corresponds to a running app, so it made
    sense to include the 'Quit' item unconditionally. That won't be
    the case for the overview context menus, so handle app state changes
    and show/hide the item as necessary.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1948>

 js/ui/appMenu.js | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/appMenu.js b/js/ui/appMenu.js
index afd04d4b8f..7f25566e02 100644
--- a/js/ui/appMenu.js
+++ b/js/ui/appMenu.js
@@ -71,17 +71,34 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
 
         this.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
 
-        this.addAction(_('Quit'), () => this._app.request_quit());
+        this._quitItem =
+            this.addAction(_('Quit'), () => this._app.request_quit());
 
         this._signals = [];
         this._signals.push([
             this._appSystem,
             this._appSystem.connect('installed-changed',
                 () => this._updateDetailsVisibility()),
+        ], [
+            this._appSystem,
+            this._appSystem.connect('app-state-changed',
+                this._onAppStateChanged.bind(this)),
         ]);
+        this._updateQuitItem();
         this._updateDetailsVisibility();
     }
 
+    _onAppStateChanged(sys, app) {
+        if (this._app !== app)
+            return;
+
+        this._updateQuitItem();
+    }
+
+    _updateQuitItem() {
+        this._quitItem.visible = this._app?.state === Shell.AppState.RUNNING;
+    }
+
     _updateDetailsVisibility() {
         const sw = this._appSystem.lookup_app('org.gnome.Software.desktop');
         this._detailsItem.visible = sw !== null;
@@ -149,6 +166,7 @@ var AppMenu = class AppMenu extends PopupMenu.PopupMenu {
 
         this._newWindowItem.visible =
             app && app.can_open_new_window() && !actions.includes('new-window');
+        this._updateQuitItem();
     }
 
     _queueUpdateWindowsSection() {


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