From 0b56416d30f390e49115fdca9a57813b360558f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 1 Jul 2020 17:02:15 +0200 Subject: [PATCH] sytemActions: Add separate 'restart' action In order to split restart and power-off in the system menu, we need to separate the underlying actions as well. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2202 --- js/misc/systemActions.js | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/js/misc/systemActions.js b/js/misc/systemActions.js index fe55f061d..33dacf21e 100644 --- a/js/misc/systemActions.js +++ b/js/misc/systemActions.js @@ -21,6 +21,7 @@ const SENSOR_OBJECT_PATH = '/net/hadess/SensorProxy'; const SensorProxyInterface = loadInterfaceXML('net.hadess.SensorProxy'); const POWER_OFF_ACTION_ID = 'power-off'; +const RESTART_ACTION_ID = 'restart'; const LOCK_SCREEN_ACTION_ID = 'lock-screen'; const LOGOUT_ACTION_ID = 'logout'; const SUSPEND_ACTION_ID = 'suspend'; @@ -44,6 +45,10 @@ const SystemActions = GObject.registerClass({ 'can-power-off', 'can-power-off', 'can-power-off', GObject.ParamFlags.READABLE, false), + 'can-restart': GObject.ParamSpec.boolean( + 'can-restart', 'can-restart', 'can-restart', + GObject.ParamFlags.READABLE, + false), 'can-suspend': GObject.ParamSpec.boolean( 'can-suspend', 'can-suspend', 'can-suspend', GObject.ParamFlags.READABLE, @@ -86,7 +91,15 @@ const SystemActions = GObject.registerClass({ name: C_("search-result", "Power Off"), iconName: 'system-shutdown-symbolic', // Translators: A list of keywords that match the power-off action, separated by semicolons - keywords: tokenizeKeywords(_('power off;shutdown;reboot;restart;halt;stop')), + keywords: tokenizeKeywords(_('power off;shutdown;halt;stop')), + available: false, + }); + this._actions.set(RESTART_ACTION_ID, { + // Translators: The name of the restart action in search + name: C_('search-result', 'Restart'), + iconName: 'system-reboot-symbolic', + // Translators: A list of keywords that match the restart action, separated by semicolons + keywords: tokenizeKeywords(_('reboot;restart;')), available: false, }); this._actions.set(LOCK_SCREEN_ACTION_ID, { @@ -196,6 +209,11 @@ const SystemActions = GObject.registerClass({ return this._actions.get(POWER_OFF_ACTION_ID).available; } + // eslint-disable-next-line camelcase + get can_restart() { + return this._actions.get(RESTART_ACTION_ID).available; + } + // eslint-disable-next-line camelcase get can_suspend() { return this._actions.get(SUSPEND_ACTION_ID).available; @@ -299,6 +317,9 @@ const SystemActions = GObject.registerClass({ case POWER_OFF_ACTION_ID: this.activatePowerOff(); break; + case RESTART_ACTION_ID: + this.activateRestart(); + break; case LOCK_SCREEN_ACTION_ID: this.activateLockScreen(); break; @@ -340,6 +361,9 @@ const SystemActions = GObject.registerClass({ this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY)); this._actions.get(POWER_OFF_ACTION_ID).available = this._canHavePowerOff && !disabled; this.notify('can-power-off'); + + this._actions.get(RESTART_ACTION_ID).available = this._canHavePowerOff && !disabled; + this.notify('can-restart'); } _updateHaveSuspend() { @@ -438,6 +462,13 @@ const SystemActions = GObject.registerClass({ this._session.ShutdownRemote(0); } + activateRestart() { + if (!this._actions.get(RESTART_ACTION_ID).available) + throw new Error('The restart action is not available!'); + + this._session.RebootRemote(); + } + activateSuspend() { if (!this._actions.get(SUSPEND_ACTION_ID).available) throw new Error('The suspend action is not available!');