2013-05-27 17:54:50 -04:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported Indicator */
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2019-07-16 05:24:13 -04:00
|
|
|
const { Gio, GObject } = imports.gi;
|
2014-01-29 16:24:50 -05:00
|
|
|
const Signals = imports.signals;
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2014-04-29 17:24:27 -04:00
|
|
|
const Main = imports.ui.main;
|
2013-05-27 17:54:50 -04:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2013-05-27 17:54:50 -04:00
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const RfkillManagerInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Rfkill');
|
2013-05-27 17:54:50 -04:00
|
|
|
const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface);
|
|
|
|
|
2017-10-30 21:19:44 -04:00
|
|
|
var RfkillManager = class {
|
|
|
|
constructor() {
|
2013-05-27 17:54:50 -04:00
|
|
|
this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
|
2017-10-30 20:38:18 -04:00
|
|
|
(proxy, error) => {
|
2013-05-27 17:54:50 -04:00
|
|
|
if (error) {
|
|
|
|
log(error.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._proxy.connect('g-properties-changed',
|
2017-12-01 19:27:35 -05:00
|
|
|
this._changed.bind(this));
|
2014-01-29 16:24:50 -05:00
|
|
|
this._changed();
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
|
|
|
get airplaneMode() {
|
|
|
|
return this._proxy.AirplaneMode;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
|
|
|
set airplaneMode(v) {
|
|
|
|
this._proxy.AirplaneMode = v;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
|
|
|
get hwAirplaneMode() {
|
|
|
|
return this._proxy.HardwareAirplaneMode;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
2014-09-08 18:17:24 -04:00
|
|
|
get shouldShowAirplaneMode() {
|
|
|
|
return this._proxy.ShouldShowAirplaneMode;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-09-08 18:17:24 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_changed() {
|
2014-01-29 16:24:50 -05:00
|
|
|
this.emit('airplane-mode-changed');
|
|
|
|
}
|
2017-10-30 21:19:44 -04:00
|
|
|
};
|
2014-01-29 16:24:50 -05:00
|
|
|
Signals.addSignalMethods(RfkillManager.prototype);
|
|
|
|
|
|
|
|
var _manager;
|
|
|
|
function getRfkillManager() {
|
|
|
|
if (_manager != null)
|
|
|
|
return _manager;
|
|
|
|
|
|
|
|
_manager = new RfkillManager();
|
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
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();
|
2014-01-29 16:24:50 -05:00
|
|
|
|
|
|
|
this._manager = getRfkillManager();
|
2017-12-01 19:27:35 -05:00
|
|
|
this._manager.connect('airplane-mode-changed', this._sync.bind(this));
|
2013-05-27 17:54:50 -04:00
|
|
|
|
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'airplane-mode-symbolic';
|
|
|
|
this._indicator.hide();
|
|
|
|
|
|
|
|
// The menu only appears when airplane mode is on, so just
|
|
|
|
// statically build it as if it was on, rather than dynamically
|
|
|
|
// changing the menu contents.
|
2015-08-06 05:19:37 -04:00
|
|
|
this._item = new PopupMenu.PopupSubMenuMenuItem(_("Airplane Mode On"), true);
|
2013-05-27 17:54:50 -04:00
|
|
|
this._item.icon.icon_name = 'airplane-mode-symbolic';
|
2017-10-30 20:38:18 -04:00
|
|
|
this._offItem = this._item.menu.addAction(_("Turn Off"), () => {
|
2014-04-21 12:58:56 -04:00
|
|
|
this._manager.airplaneMode = false;
|
2017-10-30 20:38:18 -04:00
|
|
|
});
|
2013-05-27 17:54:50 -04:00
|
|
|
this._item.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
|
|
|
|
this.menu.addMenuItem(this._item);
|
2014-04-29 17:24:27 -04:00
|
|
|
|
2017-12-01 19:27:35 -05:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2014-04-29 17:24:27 -04:00
|
|
|
this._sessionUpdated();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-04-29 17:24:27 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sessionUpdated() {
|
2014-04-29 17:24:27 -04:00
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
this.menu.setSensitive(sensitive);
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2014-01-29 16:24:50 -05:00
|
|
|
let airplaneMode = this._manager.airplaneMode;
|
|
|
|
let hwAirplaneMode = this._manager.hwAirplaneMode;
|
2014-09-08 18:17:24 -04:00
|
|
|
let showAirplaneMode = this._manager.shouldShowAirplaneMode;
|
2013-10-08 17:34:33 -04:00
|
|
|
|
2014-09-08 18:17:24 -04:00
|
|
|
this._indicator.visible = (airplaneMode && showAirplaneMode);
|
2019-04-12 17:00:49 -04:00
|
|
|
this._item.visible = (airplaneMode && showAirplaneMode);
|
2013-10-08 17:34:33 -04:00
|
|
|
this._offItem.setSensitive(!hwAirplaneMode);
|
|
|
|
|
|
|
|
if (hwAirplaneMode)
|
|
|
|
this._offItem.label.text = _("Use hardware switch to turn off");
|
|
|
|
else
|
|
|
|
this._offItem.label.text = _("Turn Off");
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|