March 12th, 2023
Fixing an Annoying Connection Issue
Currently really trying to nail down initializing a connection to a media server with project blue, so that it is portable and hopefully transitions easily to Jetpack Compose and navigation. I wonder what the best way is to initialize connection state? Here's my requirements:
- If initializing the connection fails, need to send user to settings.
- If no media server connection is selected, send user to the settings.
- If initializing succeeds, continue normal execution.
This piece of code has also caused me numerous, hard to track issues for years, so if I could make as much of it as testable as possible, then this would be a win. My current idea is to do this:
- Have an interface
ControlConnectionInitializationthat defines a single function,promiseInitializedConnection(libraryId: LibraryId): ProgressingPromise<BuildingConnectionStatus, IConnectionProvider?>, through delegation, I can build up different behaviors as needed. - Have a simple implementation of this interface that just proxies the connection:
class ConnectionInitializationProxy(
private val manageConnectionSessions: ManageConnectionSessions,
) : ControlConnectionInitialization {
override fun promiseInitializedConnection(libraryId: LibraryId): ProgressingPromise<BuildingConnectionStatus, IConnectionProvider?> =
ProgressingPromiseProxy(manageConnectionSessions.promiseLibraryConnection(libraryId))
}
- Have another implementation of
ControlConnectionInitializationthat handles error state and routes the user to the settings in failure. This will be passed an innerControlConnectionInitialization, which we will assume is handling the basic connection (and maybe success case). - At the top level, have another implementation of
ControlConnectionInitializationwhich handles the normal execution states, and delegates error-handling to the error-handling implementation.
I finished this work in this pull request.
Note posted on Sunday, March 12, 2023 11:35 PM CDT - link