android: Improve changing web theme (#402)

This commit is contained in:
NullVector 2026-10-10 20:50:19 +10:30 committed by GitHub
parent 3178a7f5ca
commit 775b63bc77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 50 additions and 0 deletions

View File

@ -33,6 +33,37 @@ html.light {
--band: #f2f5f7;
}
@property --bg {
syntax: "<color>";
inherits: true;
initial-value: #ffffff;
}
@property --text {
syntax: "<color>";
inherits: true;
initial-value: #111111;
}
@property --muted {
syntax: "<color>";
inherits: true;
initial-value: #4a555c;
}
@property --line {
syntax: "<color>";
inherits: true;
initial-value: rgba(128, 128, 128, 0.2);
}
@property --card {
syntax: "<color>";
inherits: true;
initial-value: rgba(128, 128, 128, 0.1);
}
@property --band {
syntax: "<color>";
inherits: true;
initial-value: #f2f5f7;
}
* {
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;

View File

@ -52,6 +52,9 @@ open class MainActivity : ComponentActivity() {
}
private val settingChangedForwarder: (String) -> Unit = { setting ->
runOnUiThread {
if (setting == NXUISetting.ThemeMode) {
applyWebViewTheme()
}
webView.evaluateJavascript(
"onSettingChanged('${setting.replace("'", "\\'")}')",
null
@ -175,6 +178,7 @@ open class MainActivity : ComponentActivity() {
emulationLaunchPending = false
InputHandler.updateControllerData()
inputManager()?.registerInputDeviceListener(inputDeviceListener, null)
applyWebViewTheme()
refreshConnectedControllers()
resumeRunningGame()
}
@ -359,6 +363,12 @@ open class MainActivity : ComponentActivity() {
fun editOverlayLayout() {
startActivity(Intent(this, OverlayLayoutActivity::class.java))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
overrideActivityTransition(Activity.OVERRIDE_TRANSITION_OPEN, 0, 0)
} else {
@Suppress("DEPRECATION")
overridePendingTransition(0, 0)
}
}
override fun onDestroy() {
@ -389,6 +399,15 @@ open class MainActivity : ComponentActivity() {
)
}
private fun applyWebViewTheme() {
if (!::webView.isInitialized) {
return
}
webView.setBackgroundColor(ThemeHelper.backgroundColor(this))
ThemeHelper.applySystemBars(this)
webView.evaluateJavascript("typeof applyTheme==='function'&&applyTheme()", null)
}
companion object {
private const val STICK_REPEAT_MS = 220L
private const val STICK_DEADZONE = 0.5f