-
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add in-app guest browser for localhost pages #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2f83f59
3426cd7
4c30aa4
62f1362
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,213 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.yugahashimoto.andcode.feature.browser | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import android.annotation.SuppressLint | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import android.view.ViewGroup | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import android.webkit.WebChromeClient | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import android.webkit.WebView | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import android.webkit.WebViewClient | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.activity.compose.BackHandler | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.Column | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.Row | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.fillMaxSize | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.fillMaxWidth | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.foundation.layout.padding | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material.icons.Icons | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material.icons.automirrored.filled.ArrowForward | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material.icons.filled.Refresh | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.Button | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.Icon | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.IconButton | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.LinearProgressIndicator | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.OutlinedTextField | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.Scaffold | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.Text | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.material3.TopAppBar | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.Composable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.getValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.mutableIntStateOf | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.mutableStateOf | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.remember | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.runtime.setValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.Modifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.res.stringResource | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.unit.dp | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import androidx.compose.ui.viewinterop.AndroidView | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.yugahashimoto.andcode.R | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** In-app browser for pages served inside the guest runtime (e.g. http://127.0.0.1:PORT/). */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OptIn(ExperimentalMaterial3Api::class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Composable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fun GuestBrowserScreen( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialUrl: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBack: () -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var urlInput by remember { mutableStateOf(initialUrl) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var progress by remember { mutableIntStateOf(0) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var canGoBack by remember { mutableStateOf(false) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var canGoForward by remember { mutableStateOf(false) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| var webView by remember { mutableStateOf<WebView?>(null) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| BackHandler { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| val view = webView | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (view != null && view.canGoBack()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| view.goBack() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBack() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Scaffold( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| topBar = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GuestBrowserTopBar( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| canGoBack = canGoBack, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| canGoForward = canGoForward, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBack = onBack, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHistoryBack = { webView?.goBack() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onForward = { webView?.goForward() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onReload = { webView?.reload() }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { padding -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Column(modifier = Modifier.padding(padding).fillMaxSize()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| GuestBrowserUrlBar( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| urlInput = urlInput, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUrlChange = { urlInput = it }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onGo = { webView?.loadUrl(normalizeUrl(urlInput)) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (progress in 1..99) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| LinearProgressIndicator(progress = { progress / 100f }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| AndroidView( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| modifier = Modifier.weight(1f), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| factory = { context -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| WebView(context).apply { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+82
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · high] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| layoutParams = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ViewGroup.LayoutParams( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ViewGroup.LayoutParams.MATCH_PARENT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ViewGroup.LayoutParams.MATCH_PARENT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| configure( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onProgress = { progress = it }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onNavigationStateChange = { url, back, forward -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| urlInput = url | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| canGoBack = back | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| canGoForward = forward | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| webView = this | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · medium] |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (initialUrl.isNotBlank()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| loadUrl(normalizeUrl(initialUrl)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+99
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · high] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OptIn(ExperimentalMaterial3Api::class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Composable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun GuestBrowserTopBar( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| canGoBack: Boolean, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| canGoForward: Boolean, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBack: () -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHistoryBack: () -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onForward: () -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onReload: () -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| TopAppBar( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| title = { Text(stringResource(R.string.guest_browser_title)) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| navigationIcon = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IconButton(onClick = onBack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · medium] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icon( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icons.AutoMirrored.Filled.ArrowBack, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| contentDescription = stringResource(R.string.nav_back), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| actions = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IconButton(enabled = canGoBack, onClick = onHistoryBack) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icon( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icons.AutoMirrored.Filled.ArrowBack, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| contentDescription = stringResource(R.string.guest_browser_back), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+131
to
+136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [style · low] |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| IconButton(enabled = canGoForward, onClick = onForward) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icon( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icons.AutoMirrored.Filled.ArrowForward, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| contentDescription = stringResource(R.string.guest_browser_forward), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| IconButton(onClick = onReload) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icon( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Icons.Default.Refresh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| contentDescription = stringResource(R.string.guest_browser_reload), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Composable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun GuestBrowserUrlBar( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| urlInput: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onUrlChange: (String) -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onGo: () -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| OutlinedTextField( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| value = urlInput, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onValueChange = onUrlChange, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| modifier = Modifier.weight(1f), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| singleLine = true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| placeholder = { Text(stringResource(R.string.guest_browser_url_hint)) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Button(onClick = onGo, modifier = Modifier.padding(start = 8.dp)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Text(stringResource(R.string.guest_browser_go)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun normalizeUrl(raw: String): String { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · medium] |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| val trimmed = raw.trim() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return if (trimmed.startsWith("http://") || trimmed.startsWith("https://")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| trimmed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "http://$trimmed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+173
to
+180
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · low] Suggestion:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| @SuppressLint("SetJavaScriptEnabled") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private fun WebView.configure( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onProgress: (Int) -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onNavigationStateChange: (url: String, canGoBack: Boolean, canGoForward: Boolean) -> Unit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Guest pages (dev servers, dashboards, tool UIs) are interactive web apps that need JS. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| settings.javaScriptEnabled = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [security · high] |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| settings.domStorageEnabled = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+187
to
+189
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [security · medium] |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| webChromeClient = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| object : WebChromeClient() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| override fun onProgressChanged( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| view: WebView?, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| newProgress: Int, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onProgress(newProgress) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| webViewClient = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| object : WebViewClient() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| override fun onPageFinished( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| view: WebView?, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: String?, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onProgress(100) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| onNavigationStateChange( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| url.orEmpty(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| view?.canGoBack() == true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| view?.canGoForward() == true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ import androidx.navigation.NavController | |||||||||||||
| import androidx.navigation.NavGraphBuilder | ||||||||||||||
| import androidx.navigation.compose.composable | ||||||||||||||
| import com.yugahashimoto.andcode.AndCodeApplication | ||||||||||||||
| import com.yugahashimoto.andcode.feature.browser.GuestBrowserScreen | ||||||||||||||
| import com.yugahashimoto.andcode.feature.workspace.CodeViewerScreen | ||||||||||||||
| import com.yugahashimoto.andcode.feature.workspace.CodeViewerViewModel | ||||||||||||||
| import com.yugahashimoto.andcode.feature.workspace.LocalRuntimeManagementScreen | ||||||||||||||
|
|
@@ -184,6 +185,13 @@ fun NavGraphBuilder.workspaceNavGraph( | |||||||||||||
| ) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| composable(ROUTE_GUEST_BROWSER) { | ||||||||||||||
| GuestBrowserScreen( | ||||||||||||||
| initialUrl = app.localRuntimeManager.installedPort()?.let { "http://127.0.0.1:$it/" }.orEmpty(), | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance · low] Suggestion:
Suggested change
Comment on lines
+188
to
+190
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [bug · medium] |
||||||||||||||
| onBack = { navController.popBackStack() }, | ||||||||||||||
| ) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| composable(CODE_VIEWER_ROUTE_PATTERN) { backStack -> | ||||||||||||||
| val arguments = | ||||||||||||||
| runCatching { | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1052,4 +1052,11 @@ | |
| <string name="pr_collapse">Fewer</string> | ||
| <string name="cd_pull_request_expand">Show %1$d more pull requests</string> | ||
| <string name="cd_pull_request_collapse">Show fewer pull requests</string> | ||
| <string name="guest_browser_title">Guest Browser</string> | ||
| <string name="guest_browser_row">Guest Browser</string> | ||
| <string name="guest_browser_url_hint">http://127.0.0.1:port</string> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [maintainability · low] |
||
| <string name="guest_browser_go">Open</string> | ||
| <string name="guest_browser_back">Back</string> | ||
| <string name="guest_browser_forward">Forward</string> | ||
| <string name="guest_browser_reload">Reload</string> | ||
| </resources> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[bug · medium]
rememberで保持しているため、画面回転などの設定変更で URL 入力値・進捗・履歴状態がすべてリセットされ、ブラウザが初期 URL に戻ってしまいます。urlInputはrememberSaveableに変更するか、WebView のonSaveInstanceState/restoreStateを利用して設定変更後も状態を復元できるようにしてください。Suggestion: