mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 01:33:33 +00:00
Use theme enum and platformUtilsService helpers (#2089)
* Use theme enum and platformUtilsService helpers * Update jslib
This commit is contained in:
@@ -62,6 +62,7 @@ import { StateService } from 'jslib-common/services/state.service';
|
||||
|
||||
import { PopupSearchService } from './popup-search.service';
|
||||
import { PopupUtilsService } from './popup-utils.service';
|
||||
import { ThemeType } from 'jslib-common/enums/themeType';
|
||||
|
||||
function getBgService<T>(service: string) {
|
||||
return (): T => {
|
||||
@@ -96,17 +97,17 @@ export function initFactory(platformUtilsService: PlatformUtilsService, i18nServ
|
||||
await stateService.save(ConstantsService.disableBadgeCounterKey,
|
||||
await storageService.get<boolean>(ConstantsService.disableBadgeCounterKey));
|
||||
|
||||
let theme = await storageService.get<string>(ConstantsService.themeKey);
|
||||
if (theme == null) {
|
||||
theme = await platformUtilsService.getDefaultSystemTheme();
|
||||
|
||||
platformUtilsService.onDefaultSystemThemeChange(sysTheme => {
|
||||
window.document.documentElement.classList.remove('theme_light', 'theme_dark');
|
||||
window.document.documentElement.classList.add('theme_' + sysTheme);
|
||||
});
|
||||
}
|
||||
window.document.documentElement.classList.add('locale_' + i18nService.translationLocale);
|
||||
window.document.documentElement.classList.add('theme_' + theme);
|
||||
const htmlEl = window.document.documentElement;
|
||||
const theme = await platformUtilsService.getEffectiveTheme();
|
||||
htmlEl.classList.add('theme_' + theme);
|
||||
platformUtilsService.onDefaultSystemThemeChange(async sysTheme => {
|
||||
const bwTheme = await storageService.get<ThemeType>(ConstantsService.themeKey);
|
||||
if (bwTheme == null || bwTheme === ThemeType.System) {
|
||||
htmlEl.classList.remove('theme_' + ThemeType.Light, 'theme_' + ThemeType.Dark);
|
||||
htmlEl.classList.add('theme_' + sysTheme);
|
||||
}
|
||||
});
|
||||
htmlEl.classList.add('locale_' + i18nService.translationLocale);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { StorageService } from 'jslib-common/abstractions/storage.service';
|
||||
import { TotpService } from 'jslib-common/abstractions/totp.service';
|
||||
|
||||
import { ConstantsService } from 'jslib-common/services/constants.service';
|
||||
import { ThemeType } from 'jslib-common/enums/themeType';
|
||||
|
||||
@Component({
|
||||
selector: 'app-options',
|
||||
@@ -44,10 +45,10 @@ export class OptionsComponent implements OnInit {
|
||||
private stateService: StateService, private totpService: TotpService, i18nService: I18nService) {
|
||||
this.themeOptions = [
|
||||
{ name: i18nService.t('default'), value: null },
|
||||
{ name: i18nService.t('light'), value: 'light' },
|
||||
{ name: i18nService.t('dark'), value: 'dark' },
|
||||
{ name: 'Nord', value: 'nord' },
|
||||
{ name: i18nService.t('solarizedDark'), value: 'solarizedDark' },
|
||||
{ name: i18nService.t('light'), value: ThemeType.Light },
|
||||
{ name: i18nService.t('dark'), value: ThemeType.Dark },
|
||||
{ name: 'Nord', value: ThemeType.Nord },
|
||||
{ name: i18nService.t('solarizedDark'), value: ThemeType.SolarizedDark },
|
||||
];
|
||||
this.uriMatchOptions = [
|
||||
{ name: i18nService.t('baseDomain'), value: UriMatchType.Domain },
|
||||
|
||||
Reference in New Issue
Block a user