Repository navigation
feat: reconnect after sleep and lost connections - #3
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When the connection to Spotify dropped, librespot shut its session down and the Spotify Connect task ended. cloofy never looked at that task again, so after the computer slept long enough, or the network was gone for a while, playback stayed unavailable until a restart. - The TUI keeps the device connected: a supervisor connects again whenever the connection ends without being asked to, with backoff while Spotify can't be reached and librespot's limit of five reconnects in ten minutes. What played gets ready to continue, as after a restart. This works on every OS. - macOS: cloofy-os reports sleep and wake through IOKit's power notifications, which reach non-Cocoa processes too. cloofy pauses before the Mac sleeps, which waits a second for it, and reconnects as soon as it wakes after more than a minute asleep, instead of waiting for the keep-alive to time out. The saved volume never applied: librespot ignores volume commands until the device is active, so cloofy always started at 50% and then saved that. It is now the device's initial volume, and reconnecting keeps the current one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The supervisor gave up after five reconnects in ten minutes, like librespot's binary. That left a dead player in the app, which still looked connected and only answered with channel errors until a restart. Forced reconnects after sleep counted toward the limit too, and a connection that dropped right after it started was retried at once. Now a connection that drops within 30 seconds waits like a failed attempt, with the backoff doubling up to a minute, so Spotify isn't hammered. There's no limit and so no dead end. Waking up cuts a running wait short, for the case where Spotify was out of reach before sleep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
629ad77 to
015e57f
Compare
8498fe1 to
5e9aeac
Compare
|
Merged through #7, unchanged. It met the audit work's own retry for failed connections; your supervisor now does all the retrying and feeds the loader's session state (see the note in its commit message). Fixed on top, 151f4da:
🤖 Generated with Claude Code |
Stacked on #2.
Problem
When the connection to Spotify drops, librespot shuts its session down (
TODO: Optionally reconnectinsession.rs), and the Spirc loop exits. cloofy spawned that task and never looked at it again. So after the Mac slept long enough, or the network was gone for a while, playback stayed unavailable until cloofy was restarted.What changes
playback::spawnis now a small supervisor: it connects again whenever the connection ends without being asked to.player.set_session, as librespot's own binary does.cloofy-os::powerreports both through IOKit'sIORegisterForSystemPower, which, unlike NSWorkspace, reaches processes without a Cocoa app.mainit never did: the app restored it withset_volume, which librespot ignores while the device isn't active (SetVolume(36043) will be ignored while Not Activein the log). cloofy always started at 50% and then saved 50%. The volume is now the device'sinitial_volume, and reconnecting keeps the current one.Verified
connection to Spotify lost, connecting again, followed by a freshAuthenticated as ….state.jsonwas unchanged after the run.cargo run -p cloofy-os --example sleep_wakeregisters with IOKit and prints sleep and wake events.Not included
cloofy connect(headless) still exits when the connection drops, as before.To test by hand
🤖 Generated with Claude Code