1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

feat(platform-utils): Get and react to changes to the system theme (#161)

These changes will allow the WebExtension (and later the desktop application) to respect the system theme.

I've added the Electron implementation until I realized that the required API [has been implemented but not released yet](https://www.electronjs.org/docs/api/native-theme/history). Let me know if you I should remove the code.

Part of https://github.com/bitwarden/browser/issues/1256.

https://www.electronjs.org/docs/api/native-theme

Co-authored-by: Chad Scharf <3904944+cscharf@users.noreply.github.com>
This commit is contained in:
Sorin Davidoi 2020-12-15 23:22:24 +01:00 committed by GitHub
parent f7d8887304
commit 58f5369adc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -34,5 +34,7 @@ export abstract class PlatformUtilsService {
readFromClipboard: (options?: any) => Promise<string>; readFromClipboard: (options?: any) => Promise<string>;
supportsBiometric: () => Promise<boolean>; supportsBiometric: () => Promise<boolean>;
authenticateBiometric: () => Promise<boolean>; authenticateBiometric: () => Promise<boolean>;
getDefaultSystemTheme: () => 'light' | 'dark';
onDefaultSystemThemeChange: (callback: ((theme: 'light' | 'dark') => unknown)) => unknown;
supportsSecureStorage: () => boolean; supportsSecureStorage: () => boolean;
} }

View File

@ -146,6 +146,13 @@ export class CliPlatformUtilsService implements PlatformUtilsService {
return Promise.resolve(false); return Promise.resolve(false);
} }
getDefaultSystemTheme() {
return 'light' as 'light' | 'dark';
}
onDefaultSystemThemeChange() {
}
supportsSecureStorage(): boolean { supportsSecureStorage(): boolean {
return false; return false;
} }

View File

@ -3,6 +3,7 @@ import {
ipcRenderer, ipcRenderer,
remote, remote,
shell, shell,
// nativeTheme,
} from 'electron'; } from 'electron';
import * as fs from 'fs'; import * as fs from 'fs';
@ -220,6 +221,17 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
}); });
} }
getDefaultSystemTheme() {
return 'light' as 'light' | 'dark';
// return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
}
onDefaultSystemThemeChange(callback: ((theme: 'light' | 'dark') => unknown)) {
// nativeTheme.on('updated', () => {
// callback(this.getDefaultSystemTheme());
// });
}
supportsSecureStorage(): boolean { supportsSecureStorage(): boolean {
return true; return true;
} }