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
|
|
|
|
2023-06-08 00:52:46 -04:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const GLib = imports.gi.GLib;
|
|
|
|
const GObject = imports.gi.GObject;
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2022-07-24 14:45:45 -04:00
|
|
|
const {QuickToggle, SystemIndicator} = imports.ui.quickSettings;
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2022-07-18 14:44:28 -04:00
|
|
|
const {loadInterfaceXML} = imports.misc.fileUtils;
|
2018-09-05 20:55:20 -04:00
|
|
|
|
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');
|
2022-07-18 14:44:28 -04:00
|
|
|
const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
|
2013-05-27 17:54:50 -04:00
|
|
|
|
2022-07-18 14:28:13 -04: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-30 21:19:44 -04:00
|
|
|
constructor() {
|
2022-07-04 18:30:44 -04:00
|
|
|
super();
|
|
|
|
|
2022-07-18 14:44:28 -04: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-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
2022-07-18 14:28:13 -04:00
|
|
|
/* eslint-disable camelcase */
|
|
|
|
get airplane_mode() {
|
2014-01-29 16:24:50 -05:00
|
|
|
return this._proxy.AirplaneMode;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
2022-07-18 14:28:13 -04:00
|
|
|
set airplane_mode(v) {
|
2014-01-29 16:24:50 -05:00
|
|
|
this._proxy.AirplaneMode = v;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
2022-07-18 14:28:13 -04:00
|
|
|
get hw_airplane_mode() {
|
2014-01-29 16:24:50 -05:00
|
|
|
return this._proxy.HardwareAirplaneMode;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
|
2022-07-18 14:28:13 -04:00
|
|
|
get show_airplane_mode() {
|
2022-07-18 14:47:47 -04:00
|
|
|
return this._proxy.HasAirplaneMode && this._proxy.ShouldShowAirplaneMode;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2022-07-18 14:28:13 -04:00
|
|
|
/* eslint-enable camelcase */
|
|
|
|
|
|
|
|
_changed(proxy, properties) {
|
2022-08-10 05:56:14 -04:00
|
|
|
for (const prop in properties.deepUnpack()) {
|
2022-07-18 14:28:13 -04:00
|
|
|
switch (prop) {
|
|
|
|
case 'AirplaneMode':
|
|
|
|
this.notify('airplane-mode');
|
|
|
|
break;
|
|
|
|
case 'HardwareAirplaneMode':
|
|
|
|
this.notify('hw-airplane-mode');
|
|
|
|
break;
|
2022-07-18 14:47:47 -04:00
|
|
|
case 'HasAirplaneMode':
|
2022-07-18 14:28:13 -04:00
|
|
|
case 'ShouldShowAirplaneMode':
|
|
|
|
this.notify('show-airplane-mode');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-29 16:24:50 -05:00
|
|
|
}
|
2022-07-18 14:28:13 -04:00
|
|
|
});
|
2014-01-29 16:24:50 -05:00
|
|
|
|
|
|
|
var _manager;
|
|
|
|
function getRfkillManager() {
|
|
|
|
if (_manager != null)
|
|
|
|
return _manager;
|
|
|
|
|
|
|
|
_manager = new RfkillManager();
|
|
|
|
return _manager;
|
|
|
|
}
|
|
|
|
|
2022-07-24 14:45:45 -04:00
|
|
|
const RfkillToggle = GObject.registerClass(
|
|
|
|
class RfkillToggle extends QuickToggle {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init() {
|
2022-07-24 14:45:45 -04:00
|
|
|
super._init({
|
2023-01-30 15:32:39 -05:00
|
|
|
title: _('Airplane Mode'),
|
2022-07-24 14:45:45 -04:00
|
|
|
iconName: 'airplane-mode-symbolic',
|
|
|
|
});
|
2014-01-29 16:24:50 -05:00
|
|
|
|
|
|
|
this._manager = getRfkillManager();
|
2022-07-24 14:45:45 -04:00
|
|
|
this._manager.bind_property('show-airplane-mode',
|
|
|
|
this, 'visible',
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
this._manager.bind_property('airplane-mode',
|
|
|
|
this, 'checked',
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
|
|
|
|
this.connect('clicked',
|
|
|
|
() => (this._manager.airplaneMode = !this._manager.airplaneMode));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends SystemIndicator {
|
|
|
|
_init() {
|
|
|
|
super._init();
|
2013-05-27 17:54:50 -04:00
|
|
|
|
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'airplane-mode-symbolic';
|
2014-04-29 17:24:27 -04:00
|
|
|
|
2022-07-24 14:45:45 -04:00
|
|
|
this._rfkillToggle = new RfkillToggle();
|
|
|
|
this._rfkillToggle.connectObject(
|
|
|
|
'notify::visible', () => this._sync(),
|
|
|
|
'notify::checked', () => this._sync(),
|
|
|
|
this);
|
|
|
|
this.quickSettingsItems.push(this._rfkillToggle);
|
2020-07-31 17:11:48 -04:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2014-04-29 17:24:27 -04:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2022-07-24 14:45:45 -04:00
|
|
|
// Only show indicator when airplane mode is on
|
|
|
|
const {visible, checked} = this._rfkillToggle;
|
|
|
|
this._indicator.visible = visible && checked;
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|