From 03f0f8fd4c8ba2b4b8a45c18815bf646a44771f4 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sun, 5 Apr 2026 13:54:16 +0100 Subject: [PATCH] fix(bluetooth): fix locate button not switching to bt_locate mode Remove the split fast-path in doLocateHandoff that called BtLocate.handoff() directly when the module was already loaded. That path relied on handoff() internally calling switchMode, causing a double switchMode in the lazy-load path and no guaranteed mode switch in the fast path. Now doLocateHandoff always calls switchMode('bt_locate') first (lazy-loading script/styles as needed), then calls BtLocate.handoff() in .then(). Removed the redundant switchMode call from BtLocate.handoff() since the caller owns the mode transition. Co-Authored-By: Claude Sonnet 4.6 --- static/js/modes/bluetooth.js | 10 ++-------- static/js/modes/bt_locate.js | 5 ----- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/static/js/modes/bluetooth.js b/static/js/modes/bluetooth.js index cd7c563..4647dee 100644 --- a/static/js/modes/bluetooth.js +++ b/static/js/modes/bluetooth.js @@ -1790,14 +1790,8 @@ const BluetoothMode = (function() { mac_cluster_count: device.mac_cluster_count || 0 }; - // If BtLocate is already loaded, hand off directly - if (typeof BtLocate !== 'undefined') { - BtLocate.handoff(payload); - return; - } - - // Switch to bt_locate mode first — this loads the script, styles, - // and initializes the module. Then hand off the device data. + // Always switch to bt_locate mode first (loads script + styles if needed, + // initializes the module), then hand off device data. if (typeof switchMode === 'function') { switchMode('bt_locate').then(function() { if (typeof BtLocate !== 'undefined') { diff --git a/static/js/modes/bt_locate.js b/static/js/modes/bt_locate.js index a52d127..ee5f521 100644 --- a/static/js/modes/bt_locate.js +++ b/static/js/modes/bt_locate.js @@ -1792,11 +1792,6 @@ const BtLocate = (function() { const irkInput = document.getElementById('btLocateIrk'); if (irkInput) irkInput.value = deviceInfo.irk_hex; } - - // Switch to bt_locate mode - if (typeof switchMode === 'function') { - switchMode('bt_locate'); - } } function clearHandoff() {