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