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