Fix crash in getBackgroundColor

This commit is contained in:
Fedor Indutny 2023-09-06 22:54:44 +02:00 committed by GitHub
parent 4d2910d696
commit aabcc71c3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -319,30 +319,32 @@ type GetThemeSettingOptionsType = Readonly<{
async function getThemeSetting({ async function getThemeSetting({
ephemeralOnly = false, ephemeralOnly = false,
}: GetThemeSettingOptionsType = {}): Promise<ThemeSettingType> { }: GetThemeSettingOptionsType = {}): Promise<ThemeSettingType> {
let result: unknown;
const fastValue = ephemeralConfig.get('theme-setting'); const fastValue = ephemeralConfig.get('theme-setting');
if (fastValue !== undefined) { if (fastValue !== undefined) {
getLogger().info('got fast theme-setting value', fastValue); getLogger().info('got fast theme-setting value', fastValue);
return fastValue as ThemeSettingType; result = fastValue;
} } else if (ephemeralOnly) {
if (ephemeralOnly) {
return 'system'; return 'system';
} } else {
const json = await sql.sqlCall('getItemById', 'theme-setting');
const json = await sql.sqlCall('getItemById', 'theme-setting'); result = json?.value;
}
// Default to `system` if setting doesn't exist or is invalid // Default to `system` if setting doesn't exist or is invalid
const setting: unknown = json?.value; const validatedResult =
const slowValue = result === 'light' || result === 'dark' || result === 'system'
setting === 'light' || setting === 'dark' || setting === 'system' ? result
? setting
: 'system'; : 'system';
ephemeralConfig.set('theme-setting', slowValue); if (fastValue !== validatedResult) {
ephemeralConfig.set('theme-setting', validatedResult);
getLogger().info('got slow theme-setting value', result);
}
getLogger().info('got slow theme-setting value', slowValue); return validatedResult;
return slowValue;
} }
async function getResolvedThemeSetting( async function getResolvedThemeSetting(