mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 22:33:35 +00:00
Merge pull request #1373 from sorin-davidoi/system-theme
feat: Use system theme if available
This commit is contained in:
@@ -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,
|
||||
@@ -313,4 +314,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');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user