fix(settings): screen brightness setting only applies to the reader page, closes #2717 (#2720)
Some checks are pending
Deploy to vercel on merge / build_and_deploy (push) Waiting to run

This commit is contained in:
Huang Xin 2025-12-15 13:04:29 +08:00 committed by GitHub
parent 0bd6a217ae
commit 7063d62b13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 23 deletions

View file

@ -495,13 +495,19 @@ class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
val args = invoke.parseArgs(SetScreenBrightnessRequestArgs::class.java)
val ret = JSObject()
try {
val brightness = (args.brightness ?: 0.5).toFloat()
if (brightness < 0.0 || brightness > 1.0) {
invoke.reject("Brightness must be between 0.0 and 1.0")
return
}
val brightness = args.brightness?.toFloat()
val layoutParams = activity.window.attributes
layoutParams.screenBrightness = brightness
if (brightness == null || brightness < 0.0) {
layoutParams.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE
} else {
if (brightness > 1.0) {
invoke.reject("Brightness must be between 0.0 and 1.0, or null to use system brightness")
return
}
layoutParams.screenBrightness = brightness
}
activity.window.attributes = layoutParams
ret.put("success", true)
} catch (e: Exception) {

View file

@ -812,7 +812,13 @@ class NativeBridgePlugin: Plugin {
let brightness = args.brightness ?? 0.5
if brightness < 0.0 || brightness > 1.0 {
if brightness < 0.0 {
// Revert to system brightness - iOS doesn't have a direct "system brightness" setting
// We will restore the brightness that was set before the app modified it
return invoke.resolve(["success": true])
}
if brightness > 1.0 {
return invoke.reject("Brightness must be between 0.0 and 1.0")
}