feat(settings): add an option to set auto screen brightness (#2297)
This commit is contained in:
@@ -626,5 +626,6 @@
|
||||
"{{number}} pages left in chapter": "تبقّت {{number}} صفحات في هذا الفصل",
|
||||
"Device": "الجهاز",
|
||||
"E-Ink Mode": "وضع الحبر الإلكتروني",
|
||||
"Highlight Colors": "ألوان التمييز"
|
||||
"Highlight Colors": "ألوان التمييز",
|
||||
"Auto Screen Brightness": "سطوع الشاشة التلقائي"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "অধ্যায়ে {{number}} পৃষ্ঠা বাকি",
|
||||
"Device": "যন্ত্র",
|
||||
"E-Ink Mode": "ই-ইঙ্ক মোড",
|
||||
"Highlight Colors": "হাইলাইট রঙ"
|
||||
"Highlight Colors": "হাইলাইট রঙ",
|
||||
"Auto Screen Brightness": "স্বয়ংক্রিয় স্ক্রিন উজ্জ্বলতা"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "དོན་ཚན་ནང་ཤོག་ཨང་ {{number}} ལོག་གི་འདུག།",
|
||||
"Device": "རྐྱབ་སྐོར",
|
||||
"E-Ink Mode": "ཡིག་སྒྱུར་སྤོ་བ",
|
||||
"Highlight Colors": "མདོག་ཚད་ཀྱི་བསྡུར་བ།"
|
||||
"Highlight Colors": "མདོག་ཚད་ཀྱི་བསྡུར་བ།",
|
||||
"Auto Screen Brightness": "རྒྱབ་སྐོར་གྱི་འོད་ཟེར་རང་འགུལ།"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "{{number}} Seiten verbleibend im Kapitel",
|
||||
"Device": "Gerät",
|
||||
"E-Ink Mode": "E-Ink-Modus",
|
||||
"Highlight Colors": "Hervorhebungsfarben"
|
||||
"Highlight Colors": "Hervorhebungsfarben",
|
||||
"Auto Screen Brightness": "Automatische Bildschirmhelligkeit"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "Μένουν {{number}} σελίδες στο κεφάλαιο",
|
||||
"Device": "Συσκευή",
|
||||
"E-Ink Mode": "Λειτουργία E-Ink",
|
||||
"Highlight Colors": "Χρώματα επισήμανσης"
|
||||
"Highlight Colors": "Χρώματα επισήμανσης",
|
||||
"Auto Screen Brightness": "Αυτόματη φωτεινότητα οθόνης"
|
||||
}
|
||||
|
||||
@@ -614,5 +614,6 @@
|
||||
"{{number}} pages left in chapter": "{{number}} páginas restantes en el capítulo",
|
||||
"Device": "Dispositivo",
|
||||
"E-Ink Mode": "Modo E-Ink",
|
||||
"Highlight Colors": "Colores de resaltado"
|
||||
"Highlight Colors": "Colores de resaltado",
|
||||
"Auto Screen Brightness": "Brillo automático de pantalla"
|
||||
}
|
||||
|
||||
@@ -614,5 +614,6 @@
|
||||
"{{number}} pages left in chapter": "{{number}} pages restantes dans le chapitre",
|
||||
"Device": "Appareil",
|
||||
"E-Ink Mode": "Mode E-Ink",
|
||||
"Highlight Colors": "Couleurs de Surlignage"
|
||||
"Highlight Colors": "Couleurs de Surlignage",
|
||||
"Auto Screen Brightness": "Luminosité Automatique de l'Écran"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "इस अध्याय में {{number}} पृष्ठ शेष हैं",
|
||||
"Device": "डिवाइस",
|
||||
"E-Ink Mode": "ई-इंक मोड",
|
||||
"Highlight Colors": "हाइलाइट रंग"
|
||||
"Highlight Colors": "हाइलाइट रंग",
|
||||
"Auto Screen Brightness": "स्वचालित स्क्रीन ब्राइटनेस"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "{{number}} halaman tersisa di bab",
|
||||
"Device": "Perangkat",
|
||||
"E-Ink Mode": "Mode E-Ink",
|
||||
"Highlight Colors": "Warna Sorotan"
|
||||
"Highlight Colors": "Warna Sorotan",
|
||||
"Auto Screen Brightness": "Auto Kecerahan Layar"
|
||||
}
|
||||
|
||||
@@ -614,5 +614,6 @@
|
||||
"{{number}} pages left in chapter": "{{number}} pagine rimaste nel capitolo",
|
||||
"Device": "Dispositivo",
|
||||
"E-Ink Mode": "Modalità E-Ink",
|
||||
"Highlight Colors": "Colori Evidenziazione"
|
||||
"Highlight Colors": "Colori Evidenziazione",
|
||||
"Auto Screen Brightness": "Luminosità schermo automatica"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "章に{{number}}ページ残り",
|
||||
"Device": "デバイス",
|
||||
"E-Ink Mode": "E-Inkモード",
|
||||
"Highlight Colors": "ハイライトカラー"
|
||||
"Highlight Colors": "ハイライトカラー",
|
||||
"Auto Screen Brightness": "自動画面の明るさ"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "남은 페이지 {{number}}장",
|
||||
"Device": "장치",
|
||||
"E-Ink Mode": "E-Ink 모드",
|
||||
"Highlight Colors": "하이라이트 색상"
|
||||
"Highlight Colors": "하이라이트 색상",
|
||||
"Auto Screen Brightness": "자동 화면 밝기"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "Nog {{number}} pagina’s in hoofdstuk",
|
||||
"Device": "Apparaat",
|
||||
"E-Ink Mode": "E-Ink Modus",
|
||||
"Highlight Colors": "Markeerkleuren"
|
||||
"Highlight Colors": "Markeerkleuren",
|
||||
"Auto Screen Brightness": "Automatische Schermhelderheid"
|
||||
}
|
||||
|
||||
@@ -618,5 +618,6 @@
|
||||
"{{number}} pages left in chapter": "Pozostało {{number}} stron w rozdziale",
|
||||
"Device": "Urządzenie",
|
||||
"E-Ink Mode": "Tryb E-Ink",
|
||||
"Highlight Colors": "Kolory wyróżnień"
|
||||
"Highlight Colors": "Kolory wyróżnień",
|
||||
"Auto Screen Brightness": "Automatyczna jasność ekranu"
|
||||
}
|
||||
|
||||
@@ -614,5 +614,6 @@
|
||||
"{{number}} pages left in chapter": "Faltam {{number}} páginas neste capítulo",
|
||||
"Device": "Dispositivo",
|
||||
"E-Ink Mode": "Modo E-Ink",
|
||||
"Highlight Colors": "Cores de Destaque"
|
||||
"Highlight Colors": "Cores de Destaque",
|
||||
"Auto Screen Brightness": "Brilho Automático da Tela"
|
||||
}
|
||||
|
||||
@@ -618,5 +618,6 @@
|
||||
"{{number}} pages left in chapter": "Осталось {{number}} страниц в главе",
|
||||
"Device": "Устройство",
|
||||
"E-Ink Mode": "E-Ink режим",
|
||||
"Highlight Colors": "Цвета выделения"
|
||||
"Highlight Colors": "Цвета выделения",
|
||||
"Auto Screen Brightness": "Автояркость экрана"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "පරිච්ඡේදයේ පිටු {{number}} ඉතිරිව ඇත",
|
||||
"Device": "උපකරණය",
|
||||
"E-Ink Mode": "E-Ink ආකාරය",
|
||||
"Highlight Colors": "ඉස්මතු වර්ණ"
|
||||
"Highlight Colors": "ඉස්මතු වර්ණ",
|
||||
"Auto Screen Brightness": "ස්වයංක්රීය තිර දිදුලනුම"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "{{number}} sidor kvar i kapitlet",
|
||||
"Device": "Enhet",
|
||||
"E-Ink Mode": "E-Ink-läge",
|
||||
"Highlight Colors": "Markeringsfärger"
|
||||
"Highlight Colors": "Markeringsfärger",
|
||||
"Auto Screen Brightness": "Auto-skärmens ljusstyrka"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "அத்தியாயத்தில் {{number}} பக்கங்கள் மீதமுள்ளன",
|
||||
"Device": "சாதனம்",
|
||||
"E-Ink Mode": "E-Ink முறை",
|
||||
"Highlight Colors": "முத்திரை நிறங்கள்"
|
||||
"Highlight Colors": "முத்திரை நிறங்கள்",
|
||||
"Auto Screen Brightness": "தானியங்கி திரை பிரகாசம்"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "เหลือ {{number}} หน้าในบท",
|
||||
"Device": "อุปกรณ์",
|
||||
"E-Ink Mode": "โหมด E-Ink",
|
||||
"Highlight Colors": "สีไฮไลต์"
|
||||
"Highlight Colors": "สีไฮไลต์",
|
||||
"Auto Screen Brightness": "ความสว่างหน้าจออัตโนมัติ"
|
||||
}
|
||||
|
||||
@@ -610,5 +610,6 @@
|
||||
"{{number}} pages left in chapter": "Bu bölümde {{number}} sayfa kaldı",
|
||||
"Device": "Cihaz",
|
||||
"E-Ink Mode": "E-Ink Modu",
|
||||
"Highlight Colors": "Vurgu Renkleri"
|
||||
"Highlight Colors": "Vurgu Renkleri",
|
||||
"Auto Screen Brightness": "Otomatik Ekran Parlaklığı"
|
||||
}
|
||||
|
||||
@@ -618,5 +618,6 @@
|
||||
"{{number}} pages left in chapter": "Залишилось {{number}} сторінок у розділі",
|
||||
"Device": "Пристрій",
|
||||
"E-Ink Mode": "E-Ink режим",
|
||||
"Highlight Colors": "Кольори виділення"
|
||||
"Highlight Colors": "Кольори виділення",
|
||||
"Auto Screen Brightness": "Автоматична яскравість екрану"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "Còn {{number}} trang trong chương",
|
||||
"Device": "Thiết bị",
|
||||
"E-Ink Mode": "Chế độ E-Ink",
|
||||
"Highlight Colors": "Màu nổi bật"
|
||||
"Highlight Colors": "Màu nổi bật",
|
||||
"Auto Screen Brightness": "Độ sáng màn hình tự động"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "本章剩余{{number}}页",
|
||||
"Device": "设备",
|
||||
"E-Ink Mode": "E-Ink 模式",
|
||||
"Highlight Colors": "高亮颜色"
|
||||
"Highlight Colors": "高亮颜色",
|
||||
"Auto Screen Brightness": "自动屏幕亮度"
|
||||
}
|
||||
|
||||
@@ -606,5 +606,6 @@
|
||||
"{{number}} pages left in chapter": "本章剩餘{{number}}頁",
|
||||
"Device": "設備",
|
||||
"E-Ink Mode": "E-Ink 模式",
|
||||
"Highlight Colors": "高亮顏色"
|
||||
"Highlight Colors": "高亮顏色",
|
||||
"Auto Screen Brightness": "自動螢幕亮度"
|
||||
}
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -46,7 +46,8 @@ const Providers = ({ children }: { children: React.ReactNode }) => {
|
||||
const globalViewSettings = settings.globalViewSettings;
|
||||
applyUILanguage(globalViewSettings.uiLanguage);
|
||||
const brightness = settings.screenBrightness;
|
||||
if (appService.hasScreenBrightness && brightness >= 0) {
|
||||
const autoBrightness = settings.autoScreenBrightness;
|
||||
if (appService.hasScreenBrightness && !autoBrightness && brightness >= 0) {
|
||||
setScreenBrightness(brightness / 100);
|
||||
}
|
||||
applyBackgroundTexture(envConfig, globalViewSettings);
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useEinkMode } from '@/hooks/useEinkMode';
|
||||
import { getStyles } from '@/utils/style';
|
||||
import { saveAndReload } from '@/utils/reload';
|
||||
import { getMaxInlineSize } from '@/utils/config';
|
||||
import { saveViewSettings } from '@/helpers/settings';
|
||||
import { saveSysSettings, saveViewSettings } from '@/helpers/settings';
|
||||
import { SettingsPanelPanelProp } from './SettingsDialog';
|
||||
import NumberInput from './NumberInput';
|
||||
|
||||
@@ -34,6 +34,7 @@ const ControlPanel: React.FC<SettingsPanelPanelProp> = ({ bookKey, onRegisterRes
|
||||
const [isDisableDoubleClick, setIsDisableDoubleClick] = useState(viewSettings.disableDoubleClick);
|
||||
const [animated, setAnimated] = useState(viewSettings.animated);
|
||||
const [isEink, setIsEink] = useState(viewSettings.isEink);
|
||||
const [autoScreenBrightness, setAutoScreenBrightness] = useState(settings.autoScreenBrightness);
|
||||
const [allowScript, setAllowScript] = useState(viewSettings.allowScript);
|
||||
|
||||
const resetToDefaults = useResetViewSettings();
|
||||
@@ -128,6 +129,12 @@ const ControlPanel: React.FC<SettingsPanelPanelProp> = ({ bookKey, onRegisterRes
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isEink]);
|
||||
|
||||
useEffect(() => {
|
||||
if (autoScreenBrightness === settings.autoScreenBrightness) return;
|
||||
saveSysSettings(envConfig, 'autoScreenBrightness', autoScreenBrightness);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [autoScreenBrightness]);
|
||||
|
||||
useEffect(() => {
|
||||
if (viewSettings.allowScript === allowScript) return;
|
||||
saveViewSettings(envConfig, bookKey, 'allowScript', allowScript, true, false);
|
||||
@@ -236,18 +243,29 @@ const ControlPanel: React.FC<SettingsPanelPanelProp> = ({ bookKey, onRegisterRes
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{appService?.isAndroidApp && (
|
||||
{appService?.isMobileApp && (
|
||||
<div className='w-full'>
|
||||
<h2 className='mb-2 font-medium'>{_('Device')}</h2>
|
||||
<div className='card border-base-200 bg-base-100 border shadow'>
|
||||
<div className='divide-base-200 divide-y'>
|
||||
{appService?.isAndroidApp && (
|
||||
<div className='config-item'>
|
||||
<span className=''>{_('E-Ink Mode')}</span>
|
||||
<input
|
||||
type='checkbox'
|
||||
className='toggle'
|
||||
checked={isEink}
|
||||
onChange={() => setIsEink(!isEink)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className='config-item'>
|
||||
<span className=''>{_('E-Ink Mode')}</span>
|
||||
<span className=''>{_('Auto Screen Brightness')}</span>
|
||||
<input
|
||||
type='checkbox'
|
||||
className='toggle'
|
||||
checked={isEink}
|
||||
onChange={() => setIsEink(!isEink)}
|
||||
checked={autoScreenBrightness}
|
||||
onChange={() => setAutoScreenBrightness(!autoScreenBrightness)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -62,6 +62,7 @@ export const DEFAULT_SYSTEM_SETTINGS: Partial<SystemSettings> = {
|
||||
autoCheckUpdates: true,
|
||||
screenWakeLock: false,
|
||||
screenBrightness: -1, // -1~100, -1 for system default
|
||||
autoScreenBrightness: true,
|
||||
openLastBooks: false,
|
||||
lastOpenBooks: [],
|
||||
autoImportBooksOnOpen: false,
|
||||
|
||||
@@ -49,6 +49,7 @@ export interface SystemSettings {
|
||||
autoCheckUpdates: boolean;
|
||||
screenWakeLock: boolean;
|
||||
screenBrightness: number;
|
||||
autoScreenBrightness: boolean;
|
||||
alwaysShowStatusBar: boolean;
|
||||
alwaysInForeground: boolean;
|
||||
openLastBooks: boolean;
|
||||
|
||||
@@ -172,13 +172,6 @@ export async function getScreenBrightness(): Promise<GetScreenBrightnessResponse
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getExternalSDCardPath(): Promise<GetExternalSDCardPathResponse> {
|
||||
const result = await invoke<GetExternalSDCardPathResponse>(
|
||||
'plugin:native-bridge|get_external_sdcard_path',
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function setScreenBrightness(
|
||||
request: SetScreenBrightnessRequest,
|
||||
): Promise<SetScreenBrightnessResponse> {
|
||||
@@ -190,3 +183,10 @@ export async function setScreenBrightness(
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getExternalSDCardPath(): Promise<GetExternalSDCardPathResponse> {
|
||||
const result = await invoke<GetExternalSDCardPathResponse>(
|
||||
'plugin:native-bridge|get_external_sdcard_path',
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user