Skip to content

fix: don't reopen the popup when the AirPods reappear with the lid open - #246

Open
z1pp090 wants to merge 1 commit into
SpriteOvO:mainfrom
z1pp090:fix/lid-popup-reappear
Open

z1pp090 wants to merge 1 commit into
SpriteOvO:mainfrom
z1pp090:fix/lid-popup-reappear

Conversation

@z1pp090

@z1pp090 z1pp090 commented Sep 23, 2026 •

Copy link
Copy Markdown

Fixes the repeated popups in #233, the "lid-open event is being detected repeatedly" part Kashionz mentioned there. It doesn't add the setting to turn the popup off.

Cause

StateManager drops its state when no advertisement arrives for 10 seconds (_lostTimer). With the lid open and both pods in the case, that happens every 10–60 seconds on my machine, and the log shows the same Device is lost → UpdateState loop as the log WolfCTOS posted. The first state after the gap has no oldState, so Manager::OnStateChanged did

if (!oldState.has_value()) {
    lidStateSwitched = newLidOpened;
}

and every reappearance with the lid open counted as a fresh opening, which emitted LidToggled(true) and showed the popup again.

Change

A small Details::LidTracker:

  • remembers the last lid state and the time the device was lost (it hooks into the existing SetOnDiscardState callback);
  • when the device comes back within 60 seconds, the lid only counts as opened if the last state it saw was closed;
  • after a longer gap, or when nothing was seen before, it behaves as before;
  • it is reset when the bound device's Bluetooth connection drops and when another device is bound. That one matters: closing the lid makes the AirPods drop the connection, and the scanner stops before any closed-lid advertisement arrives. Without the reset, a quick close and reopen would not show the popup. I found this during testing (details below).

TracksLidAcrossShortGaps in AirPodsDomainTests covers these cases.

How I tested it

Windows 11, AirPods Pro, a UGREEN BT 6.0 adapter, built locally with --trace. I counted Device is lost and MainWindow: Show in the log:

Build Scenario Losses Popups
v0.6.1 (release) lid open, untouched, 3 min 7 8
this PR lid open, untouched, 5 min 9 1 (at startup)
this PR lid open, untouched, 3 min, after the reset change 5 0
this PR close the lid, reopen about 30 s later — shown ✅
this PR close the lid, reopen after longer gaps — shown ✅

The first version of this fix, without the reset on disconnect, failed the quick close and reopen case (switched=false, no popup). That's why the reset is there.

Also:

This doesn't touch the auto-hide or the popup logic that #238 changes, so the two shouldn't conflict.

🤖 Generated with Claude Code

StateManager drops its state after 10 seconds without advertisements,
and that also happens while the case lid stays open. The first state
after such a gap had no previous state to compare with, so Manager
counted it as a fresh lid opening every time and the battery popup came
back every 10-60 seconds (SpriteOvO#233).

LidTracker remembers the last lid state and when the device was lost. If
the device comes back within 60 seconds, the new state is compared with
that last state, so the lid only counts as opened when it was last seen
closed or when the gap was longer.

It is reset when the bound device's Bluetooth connection drops and when
another device is bound. Closing the lid drops the connection before the
closed lid is advertised, so without the reset a quick reopening would
not show the popup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01StkifHpSLWH4J5TvuP56ur
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