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