GNOME Bugzilla – Bug 652038
user-status: Hide "Power off" option if shutdown is disabled
Last modified: 2011-06-27 19:41:24 UTC
Shutdown may be disable due to lockdown settings or Polkit policy. We shouldn't show the "Power off..." action in the menu in this case.
Created attachment 189385 [details] [review] user-status: Hide "Power off" option if shutdown is disabled Due to lockdown settings or Polkit policy, shutdown may not be available. If this is the case, the "Power off ..." action should be hidden from the user status menu.
Comment on attachment 189385 [details] [review] user-status: Hide "Power off" option if shutdown is disabled >- if (showSeparator) >+ if (showSeparator && this._suspendOrPowerOffItem.actor.visible) { > this._sessionSeparator.actor.show(); I'd rename the "showSeparator" variable. Especially since you're now dealing with two different separators in this function. >+ _updateHaveShutdown: function() { >+ this._session.CanShutdownRemote(Lang.bind(this, >+ function(canShutdown) { >+ this._haveShutdown = canShutdown; gjs-dbus callbacks are "function(array_of_out_values, error)", where one of the two will be null. So you need something like: function(result, error) { if (result) this._haveShutdown = result[0]; or [this._haveShutdown] = result;
Created attachment 190782 [details] [review] user-status: Hide "Power off" option if shutdown is disabled (In reply to comment #2) > I'd rename the "showSeparator" variable. Especially since you're now dealing > with two different separators in this function. Done. > gjs-dbus callbacks are "function(array_of_out_values, error)", where one of the > two will be null. Doh.
Comment on attachment 190782 [details] [review] user-status: Hide "Power off" option if shutdown is disabled >+ let showSesssionSeparator = sessionItemsVisible && too many "s"s there I tried to test the patch, but could not figure out how to either disable suspend or enable shutdown, so... ok to commit after fixing the above
Created attachment 190788 [details] [review] user-status: Hide "Power off" option if shutdown is disabled (In reply to comment #4) > I tried to test the patch, but could not figure out how to either disable > suspend or enable shutdown, so... Not sure about suspend (to test I just hardcoded 'false' when updating _haveSuspend ...), shutdown can be disabled with org.gnome.desktop.lockdown disable-log-out. > ok to commit after fixing the above Actually no. I hadn't tested the modified patch until now, and it doesn't actually work as expected. The attached one should be fine, here's the interdiff: diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js index 58c6bc6..7d49743 100644 --- a/js/ui/statusMenu.js +++ b/js/ui/statusMenu.js @@ -130,8 +130,8 @@ StatusMenuButton.prototype = { this._logoutItem.actor.visible || this._lockScreenItem.actor.visible; - let showSesssionSeparator = sessionItemsVisible && - this._suspendOrPowerOffItem.actor.visible; + let showSessionSeparator = sessionItemsVisible && + this._suspendOrPowerOffItem.actor.visible; let showSettingsSeparator = sessionItemsVisible || this._suspendOrPowerOffItem.actor.visible; @@ -177,8 +177,8 @@ StatusMenuButton.prototype = { _updateHaveShutdown: function() { this._session.CanShutdownRemote(Lang.bind(this, function(result, error) { - if (result) { - this._haveShutdown = result[0]; + if (!error) { + this._haveShutdown = result; this._updateSuspendOrPowerOff(); } })); @@ -194,6 +194,7 @@ StatusMenuButton.prototype = { this._suspendOrPowerOffItem.actor.hide(); else this._suspendOrPowerOffItem.actor.show(); + this._updateSessionSeparator(); // If we can't suspend show Power Off... instead // and disable the alt key
Attachment 190788 [details] pushed as 6b2b347 - user-status: Hide "Power off" option if shutdown is disabled Pushed after approval on IRC