2019-01-31 09:07:06 -05:00
|
|
|
/* exported getDefault */
|
2019-02-08 22:21:36 -05:00
|
|
|
const { AccountsService, Clutter, Gdm, Gio, GLib, GObject, Meta } = imports.gi;
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
const GnomeSession = imports.misc.gnomeSession;
|
|
|
|
const LoginManager = imports.misc.loginManager;
|
|
|
|
const Main = imports.ui.main;
|
2021-12-17 03:40:43 -05:00
|
|
|
const Screenshot = imports.ui.screenshot;
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
|
|
|
|
const LOGIN_SCREEN_SCHEMA = 'org.gnome.login-screen';
|
|
|
|
const DISABLE_USER_SWITCH_KEY = 'disable-user-switching';
|
|
|
|
const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
|
|
|
|
const DISABLE_LOG_OUT_KEY = 'disable-log-out';
|
|
|
|
const DISABLE_RESTART_KEY = 'disable-restart-buttons';
|
|
|
|
const ALWAYS_SHOW_LOG_OUT_KEY = 'always-show-log-out';
|
|
|
|
|
2017-08-02 18:32:02 -04:00
|
|
|
const POWER_OFF_ACTION_ID = 'power-off';
|
2020-07-01 11:02:15 -04:00
|
|
|
const RESTART_ACTION_ID = 'restart';
|
2017-08-02 18:32:02 -04:00
|
|
|
const LOCK_SCREEN_ACTION_ID = 'lock-screen';
|
|
|
|
const LOGOUT_ACTION_ID = 'logout';
|
|
|
|
const SUSPEND_ACTION_ID = 'suspend';
|
|
|
|
const SWITCH_USER_ACTION_ID = 'switch-user';
|
|
|
|
const LOCK_ORIENTATION_ACTION_ID = 'lock-orientation';
|
2021-12-17 03:40:43 -05:00
|
|
|
const SCREENSHOT_UI_ACTION_ID = 'open-screenshot-ui';
|
2017-08-02 18:32:02 -04:00
|
|
|
|
2017-08-02 16:57:54 -04:00
|
|
|
let _singleton = null;
|
|
|
|
|
|
|
|
function getDefault() {
|
|
|
|
if (_singleton == null)
|
|
|
|
_singleton = new SystemActions();
|
|
|
|
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2017-10-30 21:23:39 -04:00
|
|
|
const SystemActions = GObject.registerClass({
|
2017-08-02 16:57:54 -04:00
|
|
|
Properties: {
|
2020-07-01 10:55:59 -04:00
|
|
|
'can-power-off': GObject.ParamSpec.boolean(
|
|
|
|
'can-power-off', 'can-power-off', 'can-power-off',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
2020-07-01 11:02:15 -04:00
|
|
|
'can-restart': GObject.ParamSpec.boolean(
|
|
|
|
'can-restart', 'can-restart', 'can-restart',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
2020-07-01 10:55:59 -04:00
|
|
|
'can-suspend': GObject.ParamSpec.boolean(
|
|
|
|
'can-suspend', 'can-suspend', 'can-suspend',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'can-lock-screen': GObject.ParamSpec.boolean(
|
|
|
|
'can-lock-screen', 'can-lock-screen', 'can-lock-screen',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'can-switch-user': GObject.ParamSpec.boolean(
|
|
|
|
'can-switch-user', 'can-switch-user', 'can-switch-user',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'can-logout': GObject.ParamSpec.boolean(
|
|
|
|
'can-logout', 'can-logout', 'can-logout',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'can-lock-orientation': GObject.ParamSpec.boolean(
|
|
|
|
'can-lock-orientation', 'can-lock-orientation', 'can-lock-orientation',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'orientation-lock-icon': GObject.ParamSpec.string(
|
|
|
|
'orientation-lock-icon', 'orientation-lock-icon', 'orientation-lock-icon',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
null),
|
2019-08-20 17:43:54 -04:00
|
|
|
},
|
2017-10-30 21:23:39 -04:00
|
|
|
}, class SystemActions extends GObject.Object {
|
2017-10-30 20:03:21 -04:00
|
|
|
_init() {
|
2017-10-30 21:23:39 -04:00
|
|
|
super._init();
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
this._canHavePowerOff = true;
|
|
|
|
this._canHaveSuspend = true;
|
2017-08-02 18:32:02 -04:00
|
|
|
|
2020-04-25 05:54:55 -04:00
|
|
|
function tokenizeKeywords(keywords) {
|
|
|
|
return keywords.split(';').map(keyword => GLib.str_tokenize_and_fold(keyword, null)).flat(2);
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:32:02 -04:00
|
|
|
this._actions = new Map();
|
2019-02-04 07:28:22 -05:00
|
|
|
this._actions.set(POWER_OFF_ACTION_ID, {
|
|
|
|
// Translators: The name of the power-off action in search
|
|
|
|
name: C_("search-result", "Power Off"),
|
|
|
|
iconName: 'system-shutdown-symbolic',
|
|
|
|
// Translators: A list of keywords that match the power-off action, separated by semicolons
|
2022-10-26 07:41:20 -04:00
|
|
|
keywords: tokenizeKeywords(_('power off;poweroff;shutdown;halt;stop')),
|
2020-07-01 11:02:15 -04:00
|
|
|
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;')),
|
2019-08-20 17:43:54 -04:00
|
|
|
available: false,
|
2019-02-04 07:28:22 -05:00
|
|
|
});
|
|
|
|
this._actions.set(LOCK_SCREEN_ACTION_ID, {
|
|
|
|
// Translators: The name of the lock screen action in search
|
|
|
|
name: C_("search-result", "Lock Screen"),
|
|
|
|
iconName: 'system-lock-screen-symbolic',
|
|
|
|
// Translators: A list of keywords that match the lock screen action, separated by semicolons
|
2020-04-25 05:54:55 -04:00
|
|
|
keywords: tokenizeKeywords(_('lock screen')),
|
2019-08-20 17:43:54 -04:00
|
|
|
available: false,
|
2019-02-04 07:28:22 -05:00
|
|
|
});
|
|
|
|
this._actions.set(LOGOUT_ACTION_ID, {
|
|
|
|
// Translators: The name of the logout action in search
|
|
|
|
name: C_("search-result", "Log Out"),
|
2020-05-07 15:19:32 -04:00
|
|
|
iconName: 'system-log-out-symbolic',
|
2019-02-04 07:28:22 -05:00
|
|
|
// Translators: A list of keywords that match the logout action, separated by semicolons
|
2020-04-25 05:54:55 -04:00
|
|
|
keywords: tokenizeKeywords(_('logout;log out;sign off')),
|
2019-08-20 17:43:54 -04:00
|
|
|
available: false,
|
2019-02-04 07:28:22 -05:00
|
|
|
});
|
|
|
|
this._actions.set(SUSPEND_ACTION_ID, {
|
|
|
|
// Translators: The name of the suspend action in search
|
|
|
|
name: C_("search-result", "Suspend"),
|
|
|
|
iconName: 'media-playback-pause-symbolic',
|
|
|
|
// Translators: A list of keywords that match the suspend action, separated by semicolons
|
2020-04-25 05:54:55 -04:00
|
|
|
keywords: tokenizeKeywords(_('suspend;sleep')),
|
2019-08-20 17:43:54 -04:00
|
|
|
available: false,
|
2019-02-04 07:28:22 -05:00
|
|
|
});
|
|
|
|
this._actions.set(SWITCH_USER_ACTION_ID, {
|
|
|
|
// Translators: The name of the switch user action in search
|
|
|
|
name: C_("search-result", "Switch User"),
|
|
|
|
iconName: 'system-switch-user-symbolic',
|
|
|
|
// Translators: A list of keywords that match the switch user action, separated by semicolons
|
2020-04-25 05:54:55 -04:00
|
|
|
keywords: tokenizeKeywords(_('switch user')),
|
2019-08-20 17:43:54 -04:00
|
|
|
available: false,
|
2019-02-04 07:28:22 -05:00
|
|
|
});
|
|
|
|
this._actions.set(LOCK_ORIENTATION_ACTION_ID, {
|
2019-12-09 13:16:41 -05:00
|
|
|
name: '',
|
2019-02-04 07:28:22 -05:00
|
|
|
iconName: '',
|
|
|
|
// Translators: A list of keywords that match the lock orientation action, separated by semicolons
|
2020-04-25 05:54:55 -04:00
|
|
|
keywords: tokenizeKeywords(_('lock orientation;unlock orientation;screen;rotation')),
|
2019-08-20 17:43:54 -04:00
|
|
|
available: false,
|
2019-02-04 07:28:22 -05:00
|
|
|
});
|
2021-12-17 03:40:43 -05:00
|
|
|
this._actions.set(SCREENSHOT_UI_ACTION_ID, {
|
|
|
|
// Translators: The name of the screenshot UI action in search
|
|
|
|
name: C_('search-result', 'Take a Screenshot'),
|
2022-02-09 11:55:03 -05:00
|
|
|
iconName: 'record-screen-symbolic',
|
2021-12-17 03:40:43 -05:00
|
|
|
// Translators: A list of keywords that match the screenshot UI action, separated by semicolons
|
|
|
|
keywords: tokenizeKeywords(_('screenshot;screencast;snip;capture;record')),
|
|
|
|
available: true,
|
|
|
|
});
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
this._loginScreenSettings = new Gio.Settings({ schema_id: LOGIN_SCREEN_SCHEMA });
|
|
|
|
this._lockdownSettings = new Gio.Settings({ schema_id: LOCKDOWN_SCHEMA });
|
|
|
|
this._orientationSettings = new Gio.Settings({ schema_id: 'org.gnome.settings-daemon.peripherals.touchscreen' });
|
|
|
|
|
|
|
|
this._session = new GnomeSession.SessionManager();
|
|
|
|
this._loginManager = LoginManager.getLoginManager();
|
|
|
|
this._monitorManager = Meta.MonitorManager.get();
|
|
|
|
|
|
|
|
this._userManager = AccountsService.UserManager.get_default();
|
|
|
|
|
|
|
|
this._userManager.connect('notify::is-loaded',
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateMultiUser());
|
2017-08-02 16:57:54 -04:00
|
|
|
this._userManager.connect('notify::has-multiple-users',
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateMultiUser());
|
2017-08-02 16:57:54 -04:00
|
|
|
this._userManager.connect('user-added',
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateMultiUser());
|
2017-08-02 16:57:54 -04:00
|
|
|
this._userManager.connect('user-removed',
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateMultiUser());
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
this._lockdownSettings.connect(`changed::${DISABLE_USER_SWITCH_KEY}`,
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateSwitchUser());
|
2022-02-07 09:14:06 -05:00
|
|
|
this._lockdownSettings.connect(`changed::${DISABLE_LOG_OUT_KEY}`,
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateLogout());
|
2022-02-07 09:14:06 -05:00
|
|
|
global.settings.connect(`changed::${ALWAYS_SHOW_LOG_OUT_KEY}`,
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateLogout());
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
this._lockdownSettings.connect(`changed::${DISABLE_LOCK_SCREEN_KEY}`,
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateLockScreen());
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2022-02-07 09:14:06 -05:00
|
|
|
this._lockdownSettings.connect(`changed::${DISABLE_LOG_OUT_KEY}`,
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateHaveShutdown());
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
this.forceUpdate();
|
|
|
|
|
2019-12-09 13:16:41 -05:00
|
|
|
this._orientationSettings.connect('changed::orientation-lock', () => {
|
|
|
|
this._updateOrientationLock();
|
|
|
|
this._updateOrientationLockStatus();
|
|
|
|
});
|
2017-08-02 16:57:54 -04:00
|
|
|
Main.layoutManager.connect('monitors-changed',
|
2019-01-27 19:42:00 -05:00
|
|
|
() => this._updateOrientationLock());
|
2020-06-11 12:21:30 -04:00
|
|
|
this._monitorManager.connect('notify::panel-orientation-managed',
|
|
|
|
() => this._updateOrientationLock());
|
2017-08-02 16:57:54 -04:00
|
|
|
this._updateOrientationLock();
|
2019-12-09 13:16:41 -05:00
|
|
|
this._updateOrientationLockStatus();
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2019-01-27 19:42:00 -05:00
|
|
|
Main.sessionMode.connect('updated', () => this._sessionUpdated());
|
2017-08-02 16:57:54 -04:00
|
|
|
this._sessionUpdated();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canPowerOff() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(POWER_OFF_ACTION_ID).available;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canRestart() {
|
2020-07-01 11:02:15 -04:00
|
|
|
return this._actions.get(RESTART_ACTION_ID).available;
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canSuspend() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(SUSPEND_ACTION_ID).available;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canLockScreen() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(LOCK_SCREEN_ACTION_ID).available;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canSwitchUser() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(SWITCH_USER_ACTION_ID).available;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canLogout() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(LOGOUT_ACTION_ID).available;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get canLockOrientation() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(LOCK_ORIENTATION_ACTION_ID).available;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2021-01-29 20:03:07 -05:00
|
|
|
get orientationLockIcon() {
|
2017-08-02 18:32:02 -04:00
|
|
|
return this._actions.get(LOCK_ORIENTATION_ACTION_ID).iconName;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateOrientationLock() {
|
2020-06-11 12:21:30 -04:00
|
|
|
const available = this._monitorManager.get_panel_orientation_managed();
|
2017-08-02 18:32:02 -04:00
|
|
|
|
|
|
|
this._actions.get(LOCK_ORIENTATION_ACTION_ID).available = available;
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
this.notify('can-lock-orientation');
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2019-12-09 13:16:41 -05:00
|
|
|
_updateOrientationLockStatus() {
|
2017-08-02 16:57:54 -04:00
|
|
|
let locked = this._orientationSettings.get_boolean('orientation-lock');
|
2019-12-09 13:16:41 -05:00
|
|
|
let action = this._actions.get(LOCK_ORIENTATION_ACTION_ID);
|
|
|
|
|
|
|
|
// Translators: The name of the lock orientation action in search
|
|
|
|
// and in the system status menu
|
|
|
|
let name = locked
|
|
|
|
? C_('search-result', 'Unlock Screen Rotation')
|
|
|
|
: C_('search-result', 'Lock Screen Rotation');
|
2019-08-19 15:33:15 -04:00
|
|
|
let iconName = locked
|
|
|
|
? 'rotation-locked-symbolic'
|
|
|
|
: 'rotation-allowed-symbolic';
|
2019-12-09 13:16:41 -05:00
|
|
|
|
|
|
|
action.name = name;
|
|
|
|
action.iconName = iconName;
|
2017-08-02 16:57:54 -04:00
|
|
|
|
|
|
|
this.notify('orientation-lock-icon');
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sessionUpdated() {
|
2017-08-02 16:57:54 -04:00
|
|
|
this._updateLockScreen();
|
|
|
|
this._updatePowerOff();
|
|
|
|
this._updateSuspend();
|
|
|
|
this._updateMultiUser();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
forceUpdate() {
|
2017-08-02 16:57:54 -04:00
|
|
|
// Whether those actions are available or not depends on both lockdown
|
|
|
|
// settings and Polkit policy - we don't get change notifications for the
|
|
|
|
// latter, so their value may be outdated; force an update now
|
|
|
|
this._updateHaveShutdown();
|
|
|
|
this._updateHaveSuspend();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getMatchingActions(terms) {
|
2017-08-02 18:21:17 -04:00
|
|
|
// terms is a list of strings
|
2020-09-12 12:27:45 -04:00
|
|
|
terms = terms.map(
|
|
|
|
term => GLib.str_tokenize_and_fold(term, null)[0]).flat(2);
|
2017-08-02 18:21:17 -04:00
|
|
|
|
2020-09-12 12:32:57 -04:00
|
|
|
// tokenizing may return an empty array
|
|
|
|
if (terms.length === 0)
|
|
|
|
return [];
|
|
|
|
|
2017-08-02 18:21:17 -04:00
|
|
|
let results = [];
|
|
|
|
|
2019-08-19 20:51:42 -04:00
|
|
|
for (let [key, { available, keywords }] of this._actions) {
|
2018-11-04 18:21:26 -05:00
|
|
|
if (available && terms.every(t => keywords.some(k => k.startsWith(t))))
|
2017-08-02 18:21:17 -04:00
|
|
|
results.push(key);
|
2019-08-19 20:51:42 -04:00
|
|
|
}
|
2017-08-02 18:21:17 -04:00
|
|
|
|
|
|
|
return results;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 18:21:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getName(id) {
|
2017-08-02 18:21:17 -04:00
|
|
|
return this._actions.get(id).name;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 18:21:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
getIconName(id) {
|
2017-08-02 18:21:17 -04:00
|
|
|
return this._actions.get(id).iconName;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 18:21:17 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateAction(id) {
|
2017-08-02 18:21:17 -04:00
|
|
|
switch (id) {
|
2019-02-01 07:21:00 -05:00
|
|
|
case POWER_OFF_ACTION_ID:
|
|
|
|
this.activatePowerOff();
|
|
|
|
break;
|
2020-07-01 11:02:15 -04:00
|
|
|
case RESTART_ACTION_ID:
|
|
|
|
this.activateRestart();
|
|
|
|
break;
|
2019-02-01 07:21:00 -05:00
|
|
|
case LOCK_SCREEN_ACTION_ID:
|
|
|
|
this.activateLockScreen();
|
|
|
|
break;
|
|
|
|
case LOGOUT_ACTION_ID:
|
|
|
|
this.activateLogout();
|
|
|
|
break;
|
|
|
|
case SUSPEND_ACTION_ID:
|
|
|
|
this.activateSuspend();
|
|
|
|
break;
|
|
|
|
case SWITCH_USER_ACTION_ID:
|
|
|
|
this.activateSwitchUser();
|
|
|
|
break;
|
|
|
|
case LOCK_ORIENTATION_ACTION_ID:
|
|
|
|
this.activateLockOrientation();
|
|
|
|
break;
|
2021-12-17 03:40:43 -05:00
|
|
|
case SCREENSHOT_UI_ACTION_ID:
|
|
|
|
this.activateScreenshotUI();
|
|
|
|
break;
|
2017-08-02 18:21:17 -04:00
|
|
|
}
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 18:21:17 -04:00
|
|
|
|
2017-08-02 16:57:54 -04:00
|
|
|
_updateLockScreen() {
|
|
|
|
let showLock = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
let allowLockScreen = !this._lockdownSettings.get_boolean(DISABLE_LOCK_SCREEN_KEY);
|
2017-08-02 18:32:02 -04:00
|
|
|
this._actions.get(LOCK_SCREEN_ACTION_ID).available = showLock && allowLockScreen && LoginManager.canLock();
|
2017-08-02 16:57:54 -04:00
|
|
|
this.notify('can-lock-screen');
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2022-06-23 08:53:29 -04:00
|
|
|
async _updateHaveShutdown() {
|
|
|
|
try {
|
|
|
|
const [canShutdown] = await this._session.CanShutdownAsync();
|
|
|
|
this._canHavePowerOff = canShutdown;
|
|
|
|
} catch (e) {
|
|
|
|
this._canHavePowerOff = false;
|
|
|
|
}
|
|
|
|
this._updatePowerOff();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updatePowerOff() {
|
2017-08-02 16:57:54 -04:00
|
|
|
let disabled = Main.sessionMode.isLocked ||
|
|
|
|
(Main.sessionMode.isGreeter &&
|
|
|
|
this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
|
2017-08-02 18:32:02 -04:00
|
|
|
this._actions.get(POWER_OFF_ACTION_ID).available = this._canHavePowerOff && !disabled;
|
2017-08-02 16:57:54 -04:00
|
|
|
this.notify('can-power-off');
|
2020-07-01 11:02:15 -04:00
|
|
|
|
|
|
|
this._actions.get(RESTART_ACTION_ID).available = this._canHavePowerOff && !disabled;
|
|
|
|
this.notify('can-restart');
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2022-06-23 09:45:44 -04:00
|
|
|
async _updateHaveSuspend() {
|
2022-07-08 10:23:39 -04:00
|
|
|
const {canSuspend, needsAuth} = await this._loginManager.canSuspend();
|
2022-06-23 09:45:44 -04:00
|
|
|
this._canHaveSuspend = canSuspend;
|
|
|
|
this._suspendNeedsAuth = needsAuth;
|
|
|
|
this._updateSuspend();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSuspend() {
|
2017-08-02 16:57:54 -04:00
|
|
|
let disabled = (Main.sessionMode.isLocked &&
|
|
|
|
this._suspendNeedsAuth) ||
|
|
|
|
(Main.sessionMode.isGreeter &&
|
|
|
|
this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY));
|
2017-08-02 18:32:02 -04:00
|
|
|
this._actions.get(SUSPEND_ACTION_ID).available = this._canHaveSuspend && !disabled;
|
2017-08-02 16:57:54 -04:00
|
|
|
this.notify('can-suspend');
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateMultiUser() {
|
2017-08-02 16:57:54 -04:00
|
|
|
this._updateLogout();
|
|
|
|
this._updateSwitchUser();
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateSwitchUser() {
|
2017-08-02 16:57:54 -04:00
|
|
|
let allowSwitch = !this._lockdownSettings.get_boolean(DISABLE_USER_SWITCH_KEY);
|
|
|
|
let multiUser = this._userManager.can_switch() && this._userManager.has_multiple_users;
|
|
|
|
let shouldShowInMode = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
|
|
|
|
let visible = allowSwitch && multiUser && shouldShowInMode;
|
2017-08-02 18:32:02 -04:00
|
|
|
this._actions.get(SWITCH_USER_ACTION_ID).available = visible;
|
2017-08-02 16:57:54 -04:00
|
|
|
this.notify('can-switch-user');
|
|
|
|
|
|
|
|
return visible;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_updateLogout() {
|
2017-08-02 16:57:54 -04:00
|
|
|
let user = this._userManager.get_user(GLib.get_user_name());
|
|
|
|
|
|
|
|
let allowLogout = !this._lockdownSettings.get_boolean(DISABLE_LOG_OUT_KEY);
|
|
|
|
let alwaysShow = global.settings.get_boolean(ALWAYS_SHOW_LOG_OUT_KEY);
|
|
|
|
let systemAccount = user.system_account;
|
|
|
|
let localAccount = user.local_account;
|
|
|
|
let multiUser = this._userManager.has_multiple_users;
|
|
|
|
let multiSession = Gdm.get_session_ids().length > 1;
|
|
|
|
let shouldShowInMode = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
|
|
|
|
let visible = allowLogout && (alwaysShow || multiUser || multiSession || systemAccount || !localAccount) && shouldShowInMode;
|
2017-08-02 18:32:02 -04:00
|
|
|
this._actions.get(LOGOUT_ACTION_ID).available = visible;
|
2017-08-02 16:57:54 -04:00
|
|
|
this.notify('can-logout');
|
|
|
|
|
|
|
|
return visible;
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateLockOrientation() {
|
2017-08-02 18:32:02 -04:00
|
|
|
if (!this._actions.get(LOCK_ORIENTATION_ACTION_ID).available)
|
2017-08-02 16:57:54 -04:00
|
|
|
throw new Error('The lock-orientation action is not available!');
|
|
|
|
|
|
|
|
let locked = this._orientationSettings.get_boolean('orientation-lock');
|
|
|
|
this._orientationSettings.set_boolean('orientation-lock', !locked);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateLockScreen() {
|
2017-08-02 18:32:02 -04:00
|
|
|
if (!this._actions.get(LOCK_SCREEN_ACTION_ID).available)
|
2017-08-02 16:57:54 -04:00
|
|
|
throw new Error('The lock-screen action is not available!');
|
|
|
|
|
|
|
|
Main.screenShield.lock(true);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateSwitchUser() {
|
2017-08-02 18:32:02 -04:00
|
|
|
if (!this._actions.get(SWITCH_USER_ACTION_ID).available)
|
2017-08-02 16:57:54 -04:00
|
|
|
throw new Error('The switch-user action is not available!');
|
|
|
|
|
|
|
|
if (Main.screenShield)
|
|
|
|
Main.screenShield.lock(false);
|
|
|
|
|
2017-10-30 20:38:18 -04:00
|
|
|
Clutter.threads_add_repaint_func_full(Clutter.RepaintFlags.POST_PAINT, () => {
|
2017-08-02 16:57:54 -04:00
|
|
|
Gdm.goto_login_session_sync(null);
|
|
|
|
return false;
|
|
|
|
});
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateLogout() {
|
2017-08-02 18:32:02 -04:00
|
|
|
if (!this._actions.get(LOGOUT_ACTION_ID).available)
|
2017-08-02 16:57:54 -04:00
|
|
|
throw new Error('The logout action is not available!');
|
|
|
|
|
|
|
|
Main.overview.hide();
|
2022-06-23 08:53:29 -04:00
|
|
|
this._session.LogoutAsync(0).catch(logError);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activatePowerOff() {
|
2017-08-02 18:32:02 -04:00
|
|
|
if (!this._actions.get(POWER_OFF_ACTION_ID).available)
|
2017-08-02 16:57:54 -04:00
|
|
|
throw new Error('The power-off action is not available!');
|
|
|
|
|
2022-06-23 08:53:29 -04:00
|
|
|
this._session.ShutdownAsync(0).catch(logError);
|
2017-10-30 21:23:39 -04:00
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
|
2020-07-01 11:02:15 -04:00
|
|
|
activateRestart() {
|
|
|
|
if (!this._actions.get(RESTART_ACTION_ID).available)
|
|
|
|
throw new Error('The restart action is not available!');
|
|
|
|
|
2022-06-23 08:53:29 -04:00
|
|
|
this._session.RebootAsync().catch(logError);
|
2020-07-01 11:02:15 -04:00
|
|
|
}
|
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
activateSuspend() {
|
2017-08-02 18:32:02 -04:00
|
|
|
if (!this._actions.get(SUSPEND_ACTION_ID).available)
|
2017-08-02 16:57:54 -04:00
|
|
|
throw new Error('The suspend action is not available!');
|
|
|
|
|
|
|
|
this._loginManager.suspend();
|
|
|
|
}
|
2021-12-17 03:40:43 -05:00
|
|
|
|
|
|
|
activateScreenshotUI() {
|
|
|
|
if (!this._actions.get(SCREENSHOT_UI_ACTION_ID).available)
|
|
|
|
throw new Error('The screenshot UI action is not available!');
|
|
|
|
|
|
|
|
if (this._overviewHiddenId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this._overviewHiddenId = Main.overview.connect('hidden', () => {
|
|
|
|
Main.overview.disconnect(this._overviewHiddenId);
|
|
|
|
delete this._overviewHiddenId;
|
|
|
|
Screenshot.showScreenshotUI();
|
|
|
|
});
|
|
|
|
}
|
2017-08-02 16:57:54 -04:00
|
|
|
});
|