Skip to content

bluetooth: reconnect to bluez when it starts or restarts - #1588

Open
ilyamiro wants to merge 1 commit into
quickshell-mirror:masterfrom
ilyamiro:bluetooth-service-restart
Open

ilyamiro wants to merge 1 commit into
quickshell-mirror:masterfrom
ilyamiro:bluetooth-service-restart

Conversation

@ilyamiro

@ilyamiro ilyamiro commented Dec 3, 2026

Copy link
Copy Markdown

Describe your changes

This change was written mostly by an AI and I wasn't involved deeply in technical details of it, but this I am writing myself from my own understanding of it. This PR is opened because I have a problem with my own quickshell so called "Shell" for linux, specifically with people on PC (not laptops) without a bluetooth module, who use bluetooth dongles. What happens is that on startup, quickshell checks "ONCE" whether bluetooth is available on the machine. But with bluetooth dongles, users regularly plug them in or unplug them while the quickshell process is running. And the problem then becomes that quickshell does not discover that bluetooth is available and therefore using it for in-shell panels doesn't properly work, as in my case the visible state of the panel is tied to whether bluetooth is available. So this change adds a monitor that watches on this change in bluetooth availability, essentially whether a bluetooth dongle had been plugged in during runtime. This allows to enable bluetooth if it "suddenly" becomes available on the system without having to restart the process.

Details and descisions

AI-written notes (Claude was used for the change)

I used QDBusServiceWatcher because the mpris watcher already does it this way, so it matches the rest of the codebase. I didn't want to poll or add a new pattern.

The watcher is set up before the first setInterface call. If BlueZ shows up in the small gap between the two, setInterface just runs twice. That's harmless: setInterface replaces the old interface, and onInterfacesAdded already handles paths it has seen before.

When BlueZ comes back I call setInterface again instead of adding separate reconnect code. That reuses fetchInitialObjects and the normal adapter/device tracking, so a restart goes through the same path as a normal start.

When BlueZ goes away it doesn't send InterfacesRemoved for its objects (a crash certainly won't), so I drop everything myself. Devices come off their adapters first, then both lists are emptied and defaultAdapter is updated to null. Only after that are the objects deleted, so nothing in QML is left with an adapter that no longer exists. When BlueZ returns, adapters and devices are created as new objects instead of reusing the old ones.

I removed the early return after the failed setInterface, since the watcher now takes care of BlueZ starting later. The log message changed to match.

Open concerns

AI-written notes

I tested against a fake BlueZ (one adapter, no devices) on a private D-Bus daemon used as the system bus. It covered starting late, stopping, and starting again. I didn't test a real dongle hotplug or a restart with devices connected. In that case the device objects are deleted and recreated, so QML holding a device reference gets null and then a new object. I think that's correct, but say so if you'd rather keep the objects.

After BlueZ stops, the object manager keeps its old interface until BlueZ comes back and replaces it. It doesn't receive anything in the meantime, so I left it alone instead of adding a way to clear it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant