Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wingpanel bluetooth indicator settings fight #205

Merged
merged 3 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public class Bluetooth.MainView : Granite.SimpleSettingsPage {
});

manager.bind_property ("is-discovering", overlaybar, "visible", GLib.BindingFlags.DEFAULT);
manager.bind_property ("is-powered", status_switch, "active", GLib.BindingFlags.DEFAULT);
manager.bind_property ("is-powered", status_switch, "active", GLib.BindingFlags.BIDIRECTIONAL | GLib.BindingFlags.SYNC_CREATE);

show_all ();
}
Expand Down
55 changes: 18 additions & 37 deletions src/Services/Manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,11 @@ public class Bluetooth.Services.ObjectManager : Object {

private bool is_registered = false;

private Settings? settings = null;
private GLib.DBusObjectManagerClient object_manager;
private Bluetooth.Services.AgentManager agent_manager;
private Bluetooth.Services.Agent agent;

construct {
var settings_schema = SettingsSchemaSource.get_default ().lookup (SCHEMA, true);
if (settings_schema != null) {
settings = new Settings (SCHEMA);
}
create_manager.begin ();

notify["discoverable"].connect (() => {
Expand Down Expand Up @@ -123,27 +118,19 @@ public class Bluetooth.Services.ObjectManager : Object {
device_added (device);
((DBusProxy) device).g_properties_changed.connect ((changed, invalid) => {
var connected = changed.lookup_value ("Connected", GLib.VariantType.BOOLEAN);
if (connected != null) {
check_global_state ();
}

var paired = changed.lookup_value ("Paired", GLib.VariantType.BOOLEAN);
if (paired != null) {
if (connected != null || paired != null) {
check_global_state ();
}
});

check_global_state ();
} else if (iface is Bluetooth.Services.Adapter) {
unowned Bluetooth.Services.Adapter adapter = (Bluetooth.Services.Adapter) iface;
has_object = true;

adapter_added (adapter);
((DBusProxy) adapter).g_properties_changed.connect ((changed, invalid) => {
var powered = changed.lookup_value ("Powered", GLib.VariantType.BOOLEAN);
if (powered != null) {
check_global_state ();
}

var discovering = changed.lookup_value ("Discovering", GLib.VariantType.BOOLEAN);
if (discovering != null) {
Expand All @@ -154,10 +141,14 @@ public class Bluetooth.Services.ObjectManager : Object {
if (adapter_discoverable != null) {
check_discoverable ();
}
});

check_global_state ();
if (powered != null) {
check_global_state ();
}
});
}

check_global_state ();
}

private void on_interface_removed (GLib.DBusObject object, GLib.DBusInterface iface) {
Expand Down Expand Up @@ -287,26 +278,20 @@ public class Bluetooth.Services.ObjectManager : Object {
}
}

public void check_global_state () {
/* As this is called within a signal handler and emits a signal
* it should be in a Idle loop else races occur */
Idle.add (() => {
var powered = get_global_state ();
var connected = get_connected ();

/* Only signal if actually changed */
if (powered != is_powered || connected != is_connected) {
if (!powered) {
discoverable = false;
}
private void check_global_state () {
var powered = get_global_state ();
var connected = get_connected ();

is_connected = connected;
is_powered = powered;
/* Only signal if actually changed */
if (powered != is_powered || connected != is_connected) {
if (!powered) {
discoverable = false;
}

return false;
});
}
is_connected = connected;
is_powered = powered;
}
}

public async void start_discovery () {
var adapters = get_adapters ();
Expand Down Expand Up @@ -377,10 +362,6 @@ public class Bluetooth.Services.ObjectManager : Object {
adapter.discoverable = state;
}

if (settings != null) {
settings.set_boolean ("bluetooth-enabled", state);
}

if (!state) {
var devices = get_devices ();
foreach (var device in devices) {
Expand Down