Skip to content

Commit 6f93af5

Browse files
committed
AirplaneMode: use RFKill
Set state based on rfkill device change Change to airplane mode less namespace Try all rather than any All hardware OR all software
1 parent 5ae27af commit 6f93af5

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

src/Indicator.vala

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class Network.Indicator : Wingpanel.Indicator {
2222

2323
NetworkMonitor network_monitor;
2424

25+
private RFKillManager rfkill;
2526
private Gtk.GestureMultiPress gesture_click;
2627
private SimpleAction airplane_action;
2728

@@ -65,19 +66,16 @@ public class Network.Indicator : Wingpanel.Indicator {
6566
});
6667
}
6768

68-
airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (popover_widget.nm_client.networking_get_enabled ()));
69+
rfkill = new RFKillManager ();
70+
rfkill.open ();
71+
72+
airplane_action = new SimpleAction.stateful ("airplane-mode", null, new Variant.boolean (rfkill.get_airplane_mode ()));
6973
airplane_action.activate.connect (() => {
70-
popover_widget.nm_client.dbus_call.begin (
71-
NM.DBUS_PATH, NM.DBUS_INTERFACE,
72-
"Enable", new Variant.tuple ({new Variant.boolean (!popover_widget.nm_client.networking_get_enabled ())}),
73-
null, -1, null, (obj, res) => {
74-
try {
75-
((NM.Client) obj).dbus_set_property.end (res);
76-
} catch (Error e) {
77-
warning ("Error setting airplane mode: %s", e.message);
78-
}
79-
}
80-
);
74+
rfkill.set_software_lock (ALL, !rfkill.get_airplane_mode ());
75+
});
76+
77+
rfkill.device_changed.connect (() => {
78+
airplane_action.set_state (new Variant.boolean (rfkill.get_airplane_mode ()));
8179
});
8280

8381
var action_group = (SimpleActionGroup) popover_widget.get_action_group ("network");
@@ -102,8 +100,6 @@ public class Network.Indicator : Wingpanel.Indicator {
102100

103101
display_widget.update_state (popover_widget.state, popover_widget.secure, popover_widget.extra_info);
104102

105-
airplane_action.set_state (new Variant.boolean (!popover_widget.nm_client.networking_get_enabled ()));
106-
107103
update_tooltip ();
108104
}
109105

src/Widgets/PopoverWidget.vala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public class Network.Widgets.PopoverWidget : Gtk.Box {
6565

6666
var action_group = new SimpleActionGroup ();
6767
action_group.action_state_changed.connect ((action_name, state) => {
68-
critical ("got a state change");
6968
if (action_name == "airplane-mode") {
7069
if (state.get_boolean ()) {
7170
airplane_toggle.icon_name = "airplane-mode-symbolic";

src/rfkill.vala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ public class RFKillManager : Object {
8080
return devices;
8181
}
8282

83+
/*
84+
* Checks for Airplane mode
85+
* Setting airplane mode from here does all software lock, whereas setting
86+
* from a key press does all hardware lock. We need one of these two things—
87+
* all devices to be locked somehow—to consider it Airplane Mode
88+
*/
89+
public bool get_airplane_mode () {
90+
var all_hardware_locked = true;
91+
var all_software_locked = true;
92+
93+
foreach (unowned var device in get_devices ()) {
94+
if (!device.software_lock) {
95+
all_software_locked = false;
96+
}
97+
98+
if (!device.hardware_lock) {
99+
all_hardware_locked = false;
100+
}
101+
}
102+
103+
return all_hardware_locked || all_software_locked;
104+
}
105+
83106
public void set_software_lock (RFKillDeviceType type, bool lock_enabled) {
84107
var event = RFKillEvent ();
85108
event.type = type;

0 commit comments

Comments
 (0)