-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Introduce FrontendTarget and use it instead of WebViewActivity #7087
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
5398cea
cff2b50
6ce2db3
2aa44c9
910db32
406524a
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 |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import io.homeassistant.companion.android.frontend.haptic.HapticFeedbackPerforme | |
| import io.homeassistant.companion.android.util.compose.webview.settings | ||
| import io.homeassistant.companion.android.util.sensitive | ||
| import kotlinx.coroutines.CompletableDeferred | ||
| import kotlinx.serialization.json.Json | ||
| import timber.log.Timber | ||
|
|
||
| /** | ||
|
|
@@ -177,6 +178,29 @@ sealed interface WebViewAction { | |
| webView.evaluateJavascript(viewportZoomScript(pinchToZoomEnabled)) {} | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Opens the more-info dialog for [entityId] by dispatching the frontend's `hass-more-info` | ||
| * DOM event. | ||
| * | ||
| * Fallback for servers older than HA 2025.6, which ignore the `more-info-entity-id` URL query | ||
| * parameter. There is no external bus message to open more-info on those servers, so dispatching | ||
| * the frontend DOM event is the only option. | ||
| */ | ||
| data class OpenMoreInfo(val entityId: String) : WebViewAction { | ||
| // [entityId] originates from server/registry data, so it is treated as untrusted: it is | ||
| // JSON-encoded (quotes/backslashes escaped) so it cannot break out of the JS string literal. | ||
| private fun moreInfoScript(entityId: String): String { | ||
| val entityIdJson = Json.encodeToString(entityId) | ||
| return """document.querySelector("home-assistant")""" + | ||
| """.dispatchEvent(new CustomEvent("hass-more-info", { detail: { entityId: $entityIdJson }}))""" | ||
| } | ||
|
Comment on lines
+193
to
+197
Member
Author
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. @jpelgrom wdyt?
Member
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. It's a fallback and has been pretty reliable as far as I'm aware, so I wouldn't change it now. It is only a JS error you'd get, not an app crash, right? |
||
|
|
||
| override fun run(webView: WebView) { | ||
| @OptIn(EvaluateJavascriptUsage::class) | ||
| webView.evaluateJavascript(moreInfoScript(entityId)) {} | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** Gates direct JavaScript evaluation in the WebView behind an explicit opt-in. */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.