feat(settings): add an option to set auto screen brightness (#2297)

This commit is contained in:
Huang Xin
2025-10-23 00:45:51 +08:00
committed by GitHub
parent 5bdcd3124b
commit f890a9633b
31 changed files with 88 additions and 41 deletions
@@ -26,7 +26,7 @@ interface ColorPanelProps {
export const ColorPanel: React.FC<ColorPanelProps> = ({ actionTab, bottomOffset }) => {
const _ = useTranslation();
const { envConfig, appService } = useEnv();
const { settings, setSettings } = useSettingsStore();
const { settings } = useSettingsStore();
const { getScreenBrightness, setScreenBrightness } = useDeviceControlStore();
const { themeMode, themeColor, isDarkMode, setThemeMode, setThemeColor } = useThemeStore();
@@ -36,7 +36,7 @@ export const ColorPanel: React.FC<ColorPanelProps> = ({ actionTab, bottomOffset
useEffect(() => {
if (!appService?.isMobileApp) return;
if (settings.screenBrightness >= 0) return;
if (actionTab !== 'color') return;
getScreenBrightness().then((brightness) => {
if (brightness >= 0.0 && brightness <= 1.0) {
@@ -44,12 +44,13 @@ export const ColorPanel: React.FC<ColorPanelProps> = ({ actionTab, bottomOffset
setScreenBrightnessValue(screenBrightness);
}
});
}, [appService, settings, setSettings, getScreenBrightness]);
}, [actionTab, appService, getScreenBrightness]);
const debouncedSetScreenBrightness = useMemo(
() =>
debounce(async (value: number) => {
saveSysSettings(envConfig, 'screenBrightness', value);
saveSysSettings(envConfig, 'autoScreenBrightness', false);
await setScreenBrightness(value / 100);
}, 100),
[envConfig, setScreenBrightness],