2011-09-28 13:16:26 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported Indicator */
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
const { GObject, Shell, St } = imports.gi;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2012-09-19 03:02:15 +00:00
|
|
|
const BoxPointer = imports.ui.boxpointer;
|
2017-08-02 20:57:54 +00:00
|
|
|
const SystemActions = imports.misc.systemActions;
|
2010-06-03 23:21:08 +00:00
|
|
|
const Main = imports.ui.main;
|
2010-06-22 21:02:26 +00:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
2010-05-20 15:18:46 +00:00
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2015-03-05 14:46:57 +00:00
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends PanelMenu.SystemIndicator {
|
2019-07-16 09:24:13 +00:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2013-06-06 21:27:25 +00:00
|
|
|
|
2017-08-02 20:57:54 +00:00
|
|
|
this._systemActions = new SystemActions.getDefault();
|
2013-06-11 19:25:32 +00:00
|
|
|
|
|
|
|
this._createSubMenu();
|
|
|
|
|
2019-04-12 21:00:49 +00:00
|
|
|
this._loginScreenItem.connect('notify::visible',
|
2020-02-04 01:35:43 +00:00
|
|
|
() => this._updateSessionSubMenu());
|
2019-04-12 21:00:49 +00:00
|
|
|
this._logoutItem.connect('notify::visible',
|
2020-02-04 01:35:43 +00:00
|
|
|
() => this._updateSessionSubMenu());
|
|
|
|
this._suspendItem.connect('notify::visible',
|
|
|
|
() => this._updateSessionSubMenu());
|
|
|
|
this._powerOffItem.connect('notify::visible',
|
|
|
|
() => this._updateSessionSubMenu());
|
2020-07-01 15:15:48 +00:00
|
|
|
this._restartItem.connect('notify::visible',
|
|
|
|
() => this._updateSessionSubMenu());
|
2011-06-03 22:10:55 +00:00
|
|
|
// Whether shutdown is available or not depends on both lockdown
|
|
|
|
// settings (disable-log-out) and Polkit policy - the latter doesn't
|
|
|
|
// notify, so we update the menu item each time the menu opens or
|
|
|
|
// the lockdown setting changes, which should be close enough.
|
2017-10-31 00:38:18 +00:00
|
|
|
this.menu.connect('open-state-changed', (menu, open) => {
|
|
|
|
if (!open)
|
|
|
|
return;
|
2012-10-19 15:41:10 +00:00
|
|
|
|
2017-10-31 00:38:18 +00:00
|
|
|
this._systemActions.forceUpdate();
|
|
|
|
});
|
2020-02-04 01:35:43 +00:00
|
|
|
this._updateSessionSubMenu();
|
2013-07-17 06:33:09 +00:00
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2012-09-01 12:42:53 +00:00
|
|
|
this._sessionUpdated();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sessionUpdated() {
|
2019-10-15 18:51:33 +00:00
|
|
|
this._settingsItem.visible = Main.sessionMode.allowSettings;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2009-11-10 17:13:58 +00:00
|
|
|
|
2020-02-04 01:35:43 +00:00
|
|
|
_updateSessionSubMenu() {
|
|
|
|
this._sessionSubMenu.visible =
|
|
|
|
this._loginScreenItem.visible ||
|
|
|
|
this._logoutItem.visible ||
|
|
|
|
this._suspendItem.visible ||
|
2020-07-01 15:15:48 +00:00
|
|
|
this._restartItem.visible ||
|
2020-02-04 01:35:43 +00:00
|
|
|
this._powerOffItem.visible;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2011-02-04 23:37:54 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_createSubMenu() {
|
2017-08-02 20:57:54 +00:00
|
|
|
let bindFlags = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
|
2009-11-10 17:13:58 +00:00
|
|
|
let item;
|
|
|
|
|
2019-12-09 18:16:41 +00:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(
|
|
|
|
this._systemActions.getName('lock-orientation'),
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.orientation_lock_icon);
|
2019-12-09 18:16:41 +00:00
|
|
|
|
2017-08-02 20:57:54 +00:00
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.activateLockOrientation();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._orientationLockItem = item;
|
|
|
|
this._systemActions.bind_property('can-lock-orientation',
|
2020-07-01 15:38:41 +00:00
|
|
|
this._orientationLockItem, 'visible',
|
|
|
|
bindFlags);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.connect('notify::orientation-lock-icon', () => {
|
|
|
|
let iconName = this._systemActions.orientation_lock_icon;
|
2019-12-09 18:16:41 +00:00
|
|
|
let labelText = this._systemActions.getName("lock-orientation");
|
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this._orientationLockItem.setIcon(iconName);
|
2019-12-09 18:16:41 +00:00
|
|
|
this._orientationLockItem.label.text = labelText;
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2013-06-11 21:17:09 +00:00
|
|
|
|
2018-07-24 14:40:03 +00:00
|
|
|
let app = this._settingsApp = Shell.AppSystem.get_default().lookup_app(
|
2020-04-03 23:52:29 +00:00
|
|
|
'gnome-control-center.desktop');
|
2018-07-24 14:40:03 +00:00
|
|
|
if (app) {
|
2020-07-01 15:38:41 +00:00
|
|
|
const [icon] = app.app_info.get_icon().names;
|
|
|
|
const name = app.app_info.get_name();
|
2019-10-15 18:51:33 +00:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(name, icon);
|
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
|
|
|
Main.overview.hide();
|
|
|
|
this._settingsApp.activate();
|
|
|
|
});
|
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._settingsItem = item;
|
2018-07-24 14:40:03 +00:00
|
|
|
} else {
|
|
|
|
log('Missing required core component Settings, expect trouble…');
|
2019-10-15 18:51:33 +00:00
|
|
|
this._settingsItem = new St.Widget();
|
2018-07-24 14:40:03 +00:00
|
|
|
}
|
2013-06-11 21:17:09 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
item = new PopupMenu.PopupImageMenuItem(_('Lock'), 'changes-prevent-symbolic');
|
|
|
|
item.connect('activate', () => {
|
2019-08-19 18:56:36 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._systemActions.activateLockScreen();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this.menu.addMenuItem(item);
|
|
|
|
this._lockScreenItem = item;
|
|
|
|
this._systemActions.bind_property('can-lock-screen',
|
2020-07-01 15:38:41 +00:00
|
|
|
this._lockScreenItem, 'visible',
|
|
|
|
bindFlags);
|
2019-10-15 18:51:33 +00:00
|
|
|
|
|
|
|
this._sessionSubMenu = new PopupMenu.PopupSubMenuMenuItem(
|
2021-12-03 19:04:05 +00:00
|
|
|
_('Power Off'), true);
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.icon.icon_name = 'system-shutdown-symbolic';
|
|
|
|
|
2020-07-01 15:18:16 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_('Suspend'));
|
2019-10-15 18:51:33 +00:00
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._systemActions.activateSuspend();
|
2019-10-15 18:51:33 +00:00
|
|
|
});
|
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._suspendItem = item;
|
|
|
|
this._systemActions.bind_property('can-suspend',
|
|
|
|
this._suspendItem, 'visible',
|
2020-07-01 15:38:41 +00:00
|
|
|
bindFlags);
|
2013-07-17 06:33:09 +00:00
|
|
|
|
2020-07-01 15:15:48 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_('Restart…'));
|
|
|
|
item.connect('activate', () => {
|
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
|
|
|
this._systemActions.activateRestart();
|
|
|
|
});
|
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
|
|
|
this._restartItem = item;
|
|
|
|
this._systemActions.bind_property('can-restart',
|
|
|
|
this._restartItem, 'visible',
|
|
|
|
bindFlags);
|
|
|
|
|
2020-07-01 15:18:16 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_('Power Off…'));
|
2019-10-15 18:51:33 +00:00
|
|
|
item.connect('activate', () => {
|
2017-08-02 20:57:54 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._systemActions.activatePowerOff();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._powerOffItem = item;
|
|
|
|
this._systemActions.bind_property('can-power-off',
|
|
|
|
this._powerOffItem, 'visible',
|
2020-07-01 15:38:41 +00:00
|
|
|
bindFlags);
|
2013-06-11 21:17:09 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
|
|
|
2020-07-01 15:18:16 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_('Log Out'));
|
2019-10-15 18:51:33 +00:00
|
|
|
item.connect('activate', () => {
|
2017-08-02 20:57:54 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._systemActions.activateLogout();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._logoutItem = item;
|
|
|
|
this._systemActions.bind_property('can-logout',
|
|
|
|
this._logoutItem, 'visible',
|
2020-07-01 15:38:41 +00:00
|
|
|
bindFlags);
|
2013-08-23 15:09:51 +00:00
|
|
|
|
2020-07-01 15:18:16 +00:00
|
|
|
item = new PopupMenu.PopupMenuItem(_('Switch User…'));
|
2019-10-15 18:51:33 +00:00
|
|
|
item.connect('activate', () => {
|
2017-08-02 20:57:54 +00:00
|
|
|
this.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._systemActions.activateSwitchUser();
|
2017-08-02 20:57:54 +00:00
|
|
|
});
|
2019-10-15 18:51:33 +00:00
|
|
|
this._sessionSubMenu.menu.addMenuItem(item);
|
2020-07-01 15:18:16 +00:00
|
|
|
this._loginScreenItem = item;
|
|
|
|
this._systemActions.bind_property('can-switch-user',
|
|
|
|
this._loginScreenItem, 'visible',
|
2020-07-01 15:38:41 +00:00
|
|
|
bindFlags);
|
2013-08-23 15:09:51 +00:00
|
|
|
|
2019-10-15 18:51:33 +00:00
|
|
|
this.menu.addMenuItem(this._sessionSubMenu);
|
2017-08-02 20:57:54 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|