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
|
|
|
|
2022-07-18 18:44:28 +00:00
|
|
|
const {Gio, GLib, GObject} = imports.gi;
|
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;
|
|
|
|
|
2022-07-18 18:44:28 +00:00
|
|
|
const {loadInterfaceXML} = imports.misc.fileUtils;
|
2018-09-06 00:55:20 +00:00
|
|
|
|
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');
|
2022-07-18 18:44:28 +00:00
|
|
|
const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
|
2013-05-27 21:54:50 +00:00
|
|
|
|
2022-07-18 18:28:13 +00:00
|
|
|
const RfkillManager = GObject.registerClass({
|
|
|
|
Properties: {
|
|
|
|
'airplane-mode': GObject.ParamSpec.boolean(
|
|
|
|
'airplane-mode', '', '',
|
|
|
|
GObject.ParamFlags.READWRITE,
|
|
|
|
false),
|
|
|
|
'hw-airplane-mode': GObject.ParamSpec.boolean(
|
|
|
|
'hw-airplane-mode', '', '',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
'show-airplane-mode': GObject.ParamSpec.boolean(
|
|
|
|
'show-airplane-mode', '', '',
|
|
|
|
GObject.ParamFlags.READABLE,
|
|
|
|
false),
|
|
|
|
},
|
|
|
|
}, class RfkillManager extends GObject.Object {
|
2017-10-31 01:19:44 +00:00
|
|
|
constructor() {
|
2022-07-04 22:30:44 +00:00
|
|
|
super();
|
|
|
|
|
2022-07-18 18:44:28 +00:00
|
|
|
this._proxy = new Gio.DBusProxy({
|
|
|
|
g_connection: Gio.DBus.session,
|
|
|
|
g_name: BUS_NAME,
|
|
|
|
g_object_path: OBJECT_PATH,
|
|
|
|
g_interface_name: rfkillManagerInfo.name,
|
|
|
|
g_interface_info: rfkillManagerInfo,
|
|
|
|
});
|
|
|
|
this._proxy.connect('g-properties-changed', this._changed.bind(this));
|
|
|
|
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
|
|
|
|
.catch(e => console.error(e.message));
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-29 21:24:50 +00:00
|
|
|
|
2022-07-18 18:28:13 +00:00
|
|
|
/* eslint-disable camelcase */
|
|
|
|
get airplane_mode() {
|
2014-01-29 21:24:50 +00:00
|
|
|
return this._proxy.AirplaneMode;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-29 21:24:50 +00:00
|
|
|
|
2022-07-18 18:28:13 +00:00
|
|
|
set airplane_mode(v) {
|
2014-01-29 21:24:50 +00:00
|
|
|
this._proxy.AirplaneMode = v;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-29 21:24:50 +00:00
|
|
|
|
2022-07-18 18:28:13 +00:00
|
|
|
get hw_airplane_mode() {
|
2014-01-29 21:24:50 +00:00
|
|
|
return this._proxy.HardwareAirplaneMode;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2014-01-29 21:24:50 +00:00
|
|
|
|
2022-07-18 18:28:13 +00:00
|
|
|
get show_airplane_mode() {
|
2022-07-18 18:47:47 +00:00
|
|
|
return this._proxy.HasAirplaneMode && this._proxy.ShouldShowAirplaneMode;
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2022-07-18 18:28:13 +00:00
|
|
|
/* eslint-enable camelcase */
|
|
|
|
|
|
|
|
_changed(proxy, properties) {
|
|
|
|
for (const prop in properties.deep_unpack()) {
|
|
|
|
switch (prop) {
|
|
|
|
case 'AirplaneMode':
|
|
|
|
this.notify('airplane-mode');
|
|
|
|
break;
|
|
|
|
case 'HardwareAirplaneMode':
|
|
|
|
this.notify('hw-airplane-mode');
|
|
|
|
break;
|
2022-07-18 18:47:47 +00:00
|
|
|
case 'HasAirplaneMode':
|
2022-07-18 18:28:13 +00:00
|
|
|
case 'ShouldShowAirplaneMode':
|
|
|
|
this.notify('show-airplane-mode');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-29 21:24:50 +00:00
|
|
|
}
|
2022-07-18 18:28:13 +00:00
|
|
|
});
|
2014-01-29 21:24:50 +00:00
|
|
|
|
|
|
|
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();
|
2022-07-18 18:28:13 +00:00
|
|
|
this._manager.connect('notify', () => this._sync());
|
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();
|
2020-07-31 21:11:48 +00:00
|
|
|
|
|
|
|
this._sync();
|
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() {
|
2022-07-18 18:28:13 +00:00
|
|
|
const {airplaneMode, hwAirplaneMode, showAirplaneMode} = this._manager;
|
2013-10-08 21:34:33 +00:00
|
|
|
|
2019-08-19 19:38:51 +00:00
|
|
|
this._indicator.visible = airplaneMode && showAirplaneMode;
|
|
|
|
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
|
|
|
});
|