LeoKlaus / plappa

An Audiobook client for Jellyfin and AudioBookShelf, written in Swift/SwiftUI.
https://plappa.me
160 stars 0 forks source link

[BUG] CarPlay not detecting server #8

Closed PleaseStopAsking closed 3 months ago

PleaseStopAsking commented 4 months ago

Describe the bug When launching plappa via CarPlay, it randomly reports..

No server found
Please open plappa on your iPhone

When opening the app via iPhone, the CarPlay issue persists. I can still start/stop a book via the phone when this happens however.

Debug logs show no failures or errors.

To Reproduce

  1. Connect iPhone to CarPlay
  2. Launch app via CarPlay

Expected behavior CarPlay shows plappa interface

Screenshots 1868574E-645B-4216-8764-9A33B4B94924_1_102_o F44278BF-9B8A-4B20-92D9-A9E259F2AA08_1_105_c

Environment(please complete the following information):

Additional context I know that CarPlay support is still a WIP but I wanted to log this for knowledge.

LeoKlaus commented 4 months ago

Hey Micheal,

thanks for reporting this! My current car doesn't have CarPlay, so I can only test in the CarPlay simulator, which is obviously not a real world test. In the Simulator, it does seem to work reliably, though.

This error is only shown when the ApiHandler cannot be initialized, which should only happen when the credentials are not saved properly. This would also lead to the iPhone app not working, so I guess I'm missing something here.

Did you have plappa open on your iPhone before connecting to your car or did you open it through CarPlay?

PleaseStopAsking commented 4 months ago

I tested a number of times using the below workflows but could never seem to isolate when it occurs.

In all workflows, it appears that the issue is random so far.

PleaseStopAsking commented 4 months ago

It came up again this afternoon but this time, I was able to see errors in the logs.

While these errors are thrown, I can use the app via phone with no issues.

[3/1/2024, 7:37 AM] [AudioBookShelfAPIHandler] Tried to init ABS APIHandler with no valid token in keychain
[3/1/2024, 7:37 AM] [PlaybackStateHandler] Couldnt instantiate APIHandler, not pushing updated playbackstates.
LeoKlaus commented 4 months ago

It came up again this afternoon but this time, I was able to see errors in the logs.

That's interesting, I'll have to look into this. Thanks for the update!

While these errors are thrown, I can use the app via phone with no issues.

That's just weird. Did you download the audiobooks you were trying to play? If the ApiHandler is not initialized, plappa shouldn't be able to send any requests to your server. I suspect the error only occurred in the CarPlay app.

PleaseStopAsking commented 4 months ago

That's just weird. Did you download the audiobooks you were trying to play? If the ApiHandler is not initialized, plappa shouldn't be able to send any requests to your server. I suspect the error only occurred in the CarPlay app.

no, nothing is downloaded.

LeoKlaus commented 3 months ago

Okay, I've found the issue with this and #1...

plappa uses the on-device keychain to store the token used to authenticate with the server. If the ApiHandler can't obtain that token from keychain, it will fail to initialize.

The reason this happens is that keychain isn't available when the device is locked.

You should be able to reliably reproduce this issue by not looking at your phone before opening plappa via CarPlay. It shouldn't matter whether plappa is open on your device beforehand as the CarPlay delegate spawns its own ApiHandler, which will fail whenever the device is locked (little lock icon above the date on your lockscreen).

I'll have to figure out a way to mitigate this without reducing security significantly (I really don't want to store the login token in UserDefaults...)

LeoKlaus commented 3 months ago

I've just pubished update 0.9 (build 19). It contains a fix for the ApiHandler failing to initialize while the device is locked in addition to some additional debug info if keychain operations fail.

I'll still leave this open for now but it should be fixed.

PleaseStopAsking commented 3 months ago

I will test later today and report back.

PleaseStopAsking commented 3 months ago

After countless uses via CarPlay, I have not seen this issue come up again.

LeoKlaus commented 3 months ago

After countless uses via CarPlay, I have not seen this issue come up again.

Great to hear! I'll mark this as closed then. If you have any other feedback, feel free to let me know!