This commit is contained in:
+13
-6
@@ -457,12 +457,19 @@ class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
|
||||
fun get_screen_brightness(invoke: Invoke) {
|
||||
val ret = JSObject()
|
||||
try {
|
||||
val brightness = Settings.System.getInt(
|
||||
activity.contentResolver,
|
||||
Settings.System.SCREEN_BRIGHTNESS
|
||||
)
|
||||
val normalizedBrightness = brightness / 255.0
|
||||
ret.put("brightness", normalizedBrightness)
|
||||
val window = activity.window
|
||||
val layoutParams = window.attributes
|
||||
val brightness = layoutParams.screenBrightness
|
||||
|
||||
if (brightness >= 0.0f) {
|
||||
ret.put("brightness", brightness.toDouble())
|
||||
} else {
|
||||
val systemBrightness = Settings.System.getInt(
|
||||
activity.contentResolver,
|
||||
Settings.System.SCREEN_BRIGHTNESS
|
||||
)
|
||||
ret.put("brightness", systemBrightness / 255.0)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
ret.put("error", e.message)
|
||||
ret.put("brightness", -1.0)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import clsx from 'clsx';
|
||||
import React, { useCallback, useEffect, useMemo } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { PiSun, PiMoon } from 'react-icons/pi';
|
||||
import { TbSunMoon } from 'react-icons/tb';
|
||||
import { useEnv } from '@/context/EnvContext';
|
||||
@@ -30,7 +30,7 @@ export const ColorPanel: React.FC<ColorPanelProps> = ({ actionTab, bottomOffset
|
||||
const { getScreenBrightness, setScreenBrightness } = useDeviceControlStore();
|
||||
const { themeMode, themeColor, isDarkMode, setThemeMode, setThemeColor } = useThemeStore();
|
||||
|
||||
const [screenBrightnessValue, setScreenBrightnessValue] = React.useState(
|
||||
const [screenBrightnessValue, setScreenBrightnessValue] = useState(
|
||||
settings.screenBrightness >= 0 ? settings.screenBrightness : SCREEN_BRIGHTNESS_LIMITS.DEFAULT,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user