Repository navigation
Keep the Bluetooth adapter pairable only while its panel is open #14795
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
Open
kwsantiago
wants to merge
1
commit into
omacom:quattro
Choose a base branch
from
privkeyio:gate-bluetooth-pairable
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| pragma Singleton | ||
| import QtQuick | ||
| import Quickshell | ||
|
|
||
| // Holds that omarchy-bluetooth-device takes over IPC for the pairings it runs. | ||
| // The Bluetooth bar widget turns the adapters' Pairable property on while a | ||
| // hold is live, so a Low Energy device bonds even with every panel closed. | ||
| // Kept here rather than on a widget instance: the instance that answered the | ||
| // IPC call can go away with its monitor before the pairing finishes, and the | ||
| // widgets left on screen must still see the hold. | ||
| Singleton { | ||
| id: root | ||
|
|
||
| // One token per hold, so a command releases only the hold it took and two | ||
| // pairings at once cannot release each other. A command whose hold request | ||
| // got no answer has no token and leaves its hold to the expiry below. | ||
| property var tokens: [] | ||
| readonly property int holds: tokens.length | ||
|
|
||
| function hold() { | ||
| var token = "" | ||
| for (var i = 0; i < 4; i++) token += Math.floor(Math.random() * 0x100000000).toString(16).padStart(8, "0") | ||
| tokens = tokens.concat([token]) | ||
| expiry.restart() | ||
| return token | ||
| } | ||
|
|
||
| function release(token) { | ||
| var index = tokens.indexOf(String(token || "")) | ||
| if (index === -1) return "unknown" | ||
| tokens = tokens.slice(0, index).concat(tokens.slice(index + 1)) | ||
| if (tokens.length === 0) expiry.stop() | ||
| return "ok" | ||
| } | ||
|
|
||
| // A pairing that dies without releasing its hold must not leave pairing on. | ||
| Timer { | ||
| id: expiry | ||
| interval: 90000 | ||
| repeat: false | ||
| onTriggered: root.tokens = [] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import QtQuick | ||
|
|
||
| // The pairing agent in default/systemd/user/bt-agent.service answers every | ||
| // incoming pairing request without asking, so a nearby device must only be | ||
| // able to bond while someone is at the Bluetooth panel, or a pairing started | ||
| // from this machine is under way. BlueZ brings adapters up pairable with no | ||
| // timeout and nothing else in Omarchy touches the property, so this owns it: | ||
| // on while held, off the rest of the time, including right after login and | ||
| // when the adapter appears later. | ||
| // | ||
| // quickshell applies a pairable write to adapter.pairable at once and sends | ||
| // the D-Bus Set behind it, so the property reads as the requested state, a | ||
| // write never needs a retry, and a change BlueZ reports (a late adapter, or a | ||
| // `bluetoothctl pairable on` behind the shell's back) arrives as a change to | ||
| // react to. A Set that BlueZ refuses is only logged by quickshell and leaves | ||
| // the property reading the requested value, so that case is not recovered. | ||
| Item { | ||
| id: gate | ||
|
|
||
| visible: false | ||
|
|
||
| // Bluetooth.defaultAdapter, or a stand-in with a writable pairable property. | ||
| property var adapter: null | ||
| // True while this instance needs pairing possible. | ||
| property bool open: false | ||
| // One widget instance exists per monitor and they share the default adapter, | ||
| // so a closing instance leaves pairing on for another instance that holds it. | ||
| property var siblingOpen: function() { return false } | ||
|
|
||
| // Every instance must compute the same answer, or two of them write each | ||
| // other's value back forever; the panel's heldSibling reads one shared list | ||
| // for that. The guard keeps a write's own change notification from | ||
| // re-entering here, so even a disagreement cannot recurse. | ||
| property bool applying: false | ||
|
|
||
| function apply() { | ||
| if (adapter === null || applying) return | ||
| applying = true | ||
| var wanted = open || siblingOpen() | ||
| if (adapter.pairable !== wanted) adapter.pairable = wanted | ||
| applying = false | ||
| } | ||
|
|
||
| onOpenChanged: apply() | ||
| onAdapterChanged: apply() | ||
| Component.onCompleted: apply() | ||
|
|
||
| Connections { | ||
| target: gate.adapter | ||
| ignoreUnknownSignals: true | ||
| function onPairableChanged() { gate.apply() } | ||
| } | ||
|
|
||
| // A destroyed instance is no longer counted among the siblings, so it turns | ||
| // pairing off itself when it was the last one holding it. One replaced while | ||
| // its panel still holds (a controller appeared, and the gates were rebuilt) | ||
| // leaves that to its successor. | ||
| Component.onDestruction: { | ||
| if (adapter !== null && adapter.pairable === true && !open && !siblingOpen()) adapter.pairable = false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(dirname "$0")/base-test.sh" | ||
| require_compositor "the Bluetooth pairable gate" | ||
| require_command quickshell | ||
|
|
||
| stage=$(mktemp -d) | ||
| trap 'rm -rf "$stage"' EXIT | ||
| # The directory import scans Panel.qml too, whose own imports resolve here. | ||
| for component in Commons Ui; do | ||
| ln -s "$ROOT/shell/$component" "$stage/$component" | ||
| done | ||
| ln -s "$ROOT/shell/plugins/panels/bluetooth" "$stage/bluetooth" | ||
| cp "$SHELL_TEST_DIR/fixtures/bluetooth-pairable-gate/shell.qml" "$stage/shell.qml" | ||
|
|
||
| output=$(timeout 25 quickshell -p "$stage" --no-color 2>&1) || fail "the pairable gate fixture exits cleanly" "$output" | ||
| [[ $output == *"RESULT pass"* ]] || fail "the adapter is pairable only while a Bluetooth panel is open" "$output" | ||
| if rg -q 'RESULT fail|ReferenceError|TypeError|Unable to assign|Binding loop' <<<"$output"; then | ||
| fail "the pairable gate has no QML errors" "$output" | ||
| fi | ||
| pass "the adapter is pairable only while a Bluetooth panel is open" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After receiving a token,
hold_pairingreturns without keeping a hold outside the shell. If the shell restarts during pairing, the newBluetoothPairingstarts with no tokens. With the panels closed, its gates turn pairing off even though the detached pairing command is still running. A Low Energy device can then fail to bond and be forgotten after disconnecting.Keep command holds somewhere the replacement shell can read, or have the command renew its hold after a restart.
Knowledge Base Used: CLI command platform