1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 23:33:31 +00:00

feat: Use system theme if available

Depends on https://github.com/bitwarden/jslib/pull/161.

Closes https://github.com/bitwarden/browser/issues/1256.
This commit is contained in:
Sorin Davidoi
2020-08-31 22:33:01 +02:00
parent b795f0e587
commit 260820711e
2 changed files with 19 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
private showDialogResolves = new Map<number, { resolve: (value: boolean) => void, date: Date }>();
private deviceCache: DeviceType = null;
private analyticsIdCache: string = null;
private prefersColorSchemeDark = window.matchMedia('(prefers-color-scheme: dark)');
constructor(private messagingService: MessagingService,
private clipboardWriteCallback: (clipboardValue: string, clearMs: number) => void) { }
@@ -308,4 +309,14 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
private isSafariExtension(): boolean {
return (window as any).safariAppExtension === true;
}
getDefaultSystemTheme() {
return this.prefersColorSchemeDark.matches ? 'dark' : 'light';
}
onDefaultSystemThemeChange(callback: ((theme: 'light' | 'dark') => unknown)) {
this.prefersColorSchemeDark.addListener(({ matches }) => {
callback(matches ? 'dark' : 'light');
});
}
}