rfkill: Turn manager into a GObject
That will allow us to use it in property bindings. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2385>
This commit is contained in:
parent
bb043bb761
commit
98cbc31e86
@ -750,8 +750,10 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
|
|||||||
this._syncView.bind(this), this);
|
this._syncView.bind(this), this);
|
||||||
|
|
||||||
this._rfkill = Rfkill.getRfkillManager();
|
this._rfkill = Rfkill.getRfkillManager();
|
||||||
this._rfkill.connectObject('airplane-mode-changed',
|
this._rfkill.connectObject(
|
||||||
this._syncView.bind(this), this);
|
'notify::airplane-mode', () => this._syncView(),
|
||||||
|
'notify::hw-airplane-mode', () => this._syncView(),
|
||||||
|
this);
|
||||||
|
|
||||||
this._networks = [];
|
this._networks = [];
|
||||||
this._buildLayout();
|
this._buildLayout();
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
/* exported Indicator */
|
/* exported Indicator */
|
||||||
|
|
||||||
const {Gio, GLib, GObject} = imports.gi;
|
const {Gio, GLib, GObject} = imports.gi;
|
||||||
const Signals = imports.misc.signals;
|
|
||||||
|
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const PanelMenu = imports.ui.panelMenu;
|
const PanelMenu = imports.ui.panelMenu;
|
||||||
@ -16,7 +15,22 @@ const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
|
|||||||
const RfkillManagerInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Rfkill');
|
const RfkillManagerInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Rfkill');
|
||||||
const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
|
const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
|
||||||
|
|
||||||
var RfkillManager = class extends Signals.EventEmitter {
|
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 {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -32,26 +46,40 @@ var RfkillManager = class extends Signals.EventEmitter {
|
|||||||
.catch(e => console.error(e.message));
|
.catch(e => console.error(e.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
get airplaneMode() {
|
/* eslint-disable camelcase */
|
||||||
|
get airplane_mode() {
|
||||||
return this._proxy.AirplaneMode;
|
return this._proxy.AirplaneMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
set airplaneMode(v) {
|
set airplane_mode(v) {
|
||||||
this._proxy.AirplaneMode = v;
|
this._proxy.AirplaneMode = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
get hwAirplaneMode() {
|
get hw_airplane_mode() {
|
||||||
return this._proxy.HardwareAirplaneMode;
|
return this._proxy.HardwareAirplaneMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
get shouldShowAirplaneMode() {
|
get show_airplane_mode() {
|
||||||
return this._proxy.ShouldShowAirplaneMode;
|
return this._proxy.ShouldShowAirplaneMode;
|
||||||
}
|
}
|
||||||
|
/* eslint-enable camelcase */
|
||||||
|
|
||||||
_changed() {
|
_changed(proxy, properties) {
|
||||||
this.emit('airplane-mode-changed');
|
for (const prop in properties.deep_unpack()) {
|
||||||
|
switch (prop) {
|
||||||
|
case 'AirplaneMode':
|
||||||
|
this.notify('airplane-mode');
|
||||||
|
break;
|
||||||
|
case 'HardwareAirplaneMode':
|
||||||
|
this.notify('hw-airplane-mode');
|
||||||
|
break;
|
||||||
|
case 'ShouldShowAirplaneMode':
|
||||||
|
this.notify('show-airplane-mode');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
|
||||||
var _manager;
|
var _manager;
|
||||||
function getRfkillManager() {
|
function getRfkillManager() {
|
||||||
@ -68,7 +96,7 @@ class Indicator extends PanelMenu.SystemIndicator {
|
|||||||
super._init();
|
super._init();
|
||||||
|
|
||||||
this._manager = getRfkillManager();
|
this._manager = getRfkillManager();
|
||||||
this._manager.connect('airplane-mode-changed', this._sync.bind(this));
|
this._manager.connect('notify', () => this._sync());
|
||||||
|
|
||||||
this._indicator = this._addIndicator();
|
this._indicator = this._addIndicator();
|
||||||
this._indicator.icon_name = 'airplane-mode-symbolic';
|
this._indicator.icon_name = 'airplane-mode-symbolic';
|
||||||
@ -97,9 +125,7 @@ class Indicator extends PanelMenu.SystemIndicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_sync() {
|
_sync() {
|
||||||
let airplaneMode = this._manager.airplaneMode;
|
const {airplaneMode, hwAirplaneMode, showAirplaneMode} = this._manager;
|
||||||
let hwAirplaneMode = this._manager.hwAirplaneMode;
|
|
||||||
let showAirplaneMode = this._manager.shouldShowAirplaneMode;
|
|
||||||
|
|
||||||
this._indicator.visible = airplaneMode && showAirplaneMode;
|
this._indicator.visible = airplaneMode && showAirplaneMode;
|
||||||
this._item.visible = airplaneMode && showAirplaneMode;
|
this._item.visible = airplaneMode && showAirplaneMode;
|
||||||
|
Loading…
Reference in New Issue
Block a user