Skip to content

Add frontend url manager#6382

Open
TimoPtr wants to merge 1 commit intofeature/server_session_managerfrom
feature/frontend_url_manager
Open

Add frontend url manager#6382
TimoPtr wants to merge 1 commit intofeature/server_session_managerfrom
feature/frontend_url_manager

Conversation

@TimoPtr
Copy link
Member

@TimoPtr TimoPtr commented Feb 4, 2026

Summary

Introduces FrontendUrlManager, a dedicated class for handling URL resolution and security checks for the frontend WebView. This extracts URL loading logic from WebViewPresenterImpl into a focused, testable component.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Any other notes

This code is not yet used but it is going to be in a next PR this is based on #6380

@TimoPtr TimoPtr requested a review from jpelgrom February 4, 2026 09:29
@TimoPtr TimoPtr added the WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav. label Feb 4, 2026
var pathConsumed = false
serverManager.connectionStateProvider(actualServerId).urlFlow().collect { urlState ->
val currentPath = if (pathConsumed) null else path
pathConsumed = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to not consume the path until the state actually returns an URL?

Example use case: I have sent a notification which deeplinks to something, but when I tap the notification I'm not yet connected to my home network so loading is blocked, and when I connect to Wi-Fi it reloads but ignores the path as it was already consumed by the blocked screen.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we want to change the behavior on this PR, but yes it would make sense. I saw also this PR #6403 that is somehow related.

*
* @param serverId The server ID that had security level configured
*/
fun onSecurityLevelConfigured(serverId: Int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user can ignore the screen so it is not known whether or not they actually configured it.

Suggested change
fun onSecurityLevelConfigured(serverId: Int) {
fun onSecurityLevelShown(serverId: Int) {

}

@Test
fun `Given insecure state when serverUrlFlow then returns InsecureBlocked`() = runTest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is for nothing setup. The next test is for home setup but not home + location disabled. I don't see tests for the other possible combinations. Why pick these two?

Comment on lines +269 to +290
@Test
fun `Given SERVER_ID_ACTIVE when serverUrlFlow then resolves to actual server ID`() = runTest {
val server = createTestServer(id = 42, externalUrl = "https://home.example.com")
coEvery { serverManager.getServer(ServerManager.SERVER_ID_ACTIVE) } returns server
coEvery { serverManager.getServer(42) } returns server
coEvery { sessionManager.isSessionConnected(42) } returns SessionCheckResult.Connected
coEvery { serverManager.activateServer(42) } just runs
coEvery { serverManager.connectionStateProvider(42) } returns connectionStateProvider
every { connectionStateProvider.urlFlow(any()) } returns flowOf(
UrlState.HasUrl(URL("https://home.example.com")),
)

urlManager.serverUrlFlow(serverId = ServerManager.SERVER_ID_ACTIVE, path = null).test {
val result = awaitItem()
assertTrue(result is UrlLoadResult.Success)
assertEquals(42, (result as UrlLoadResult.Success).serverId)
awaitComplete()
}

coVerify { serverManager.activateServer(42) }
coVerify { serverManager.connectionStateProvider(42) }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved up or down, right now it is in the middle of the connection security level related tests

coEvery { serverManager.activateServer(1) } just runs
coEvery { serverManager.connectionStateProvider(1) } returns connectionStateProvider
every { connectionStateProvider.urlFlow(any()) } returns flowOf(
UrlState.HasUrl(URL("http://home.example.com")),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it do this? HTTP + disallow insecure shouldn't return anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed WebViewActivity replacement Ongoing work to replace the WebViewActivity in favor of a well tested compose screen using nav.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants