1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

Add theme enums and platformUtilsService helper (#497)

* Use enum for themes, add getEffectiveTheme

* Update electron and cli to use theme refactor
This commit is contained in:
Thomas Rittson
2021-09-30 06:37:36 +10:00
committed by GitHub
parent 91b73fa777
commit ce71c0c0bd
5 changed files with 35 additions and 7 deletions

View File

@@ -3,6 +3,8 @@ import { promises as fs } from 'fs';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { RendererMenuItem } from '../utils';
import { ThemeType } from 'jslib-common/enums/themeType';
import { WindowMain } from '../window.main';
export class ElectronMainMessagingService implements MessagingService {
@@ -12,7 +14,7 @@ export class ElectronMainMessagingService implements MessagingService {
});
ipcMain.handle('systemTheme', () => {
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';
return nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light;
});
ipcMain.handle('showMessageBox', (event, options) => {
@@ -42,7 +44,7 @@ export class ElectronMainMessagingService implements MessagingService {
});
nativeTheme.on('updated', () => {
windowMain.win?.webContents.send('systemThemeUpdated', nativeTheme.shouldUseDarkColors ? 'dark' : 'light');
windowMain.win?.webContents.send('systemThemeUpdated', nativeTheme.shouldUseDarkColors ? ThemeType.Dark : ThemeType.Light);
});
}

View File

@@ -10,12 +10,15 @@ import {
} from '../utils';
import { DeviceType } from 'jslib-common/enums/deviceType';
import { ThemeType } from 'jslib-common/enums/themeType';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
import { MessagingService } from 'jslib-common/abstractions/messaging.service';
import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service';
import { StorageService } from 'jslib-common/abstractions/storage.service';
import { ConstantsService } from 'jslib-common/services/constants.service';
import { ElectronConstants } from '../electronConstants';
export class ElectronPlatformUtilsService implements PlatformUtilsService {
@@ -192,8 +195,17 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
return ipcRenderer.invoke('systemTheme');
}
onDefaultSystemThemeChange(callback: ((theme: 'light' | 'dark') => unknown)) {
ipcRenderer.on('systemThemeUpdated', (event, theme: 'light' | 'dark') => callback(theme));
onDefaultSystemThemeChange(callback: ((theme: ThemeType.Light | ThemeType.Dark) => unknown)) {
ipcRenderer.on('systemThemeUpdated', (event, theme: ThemeType.Light | ThemeType.Dark) => callback(theme));
}
async getEffectiveTheme() {
const theme = await this.storageService.get<ThemeType>(ConstantsService.themeKey);
if (theme == null || theme === ThemeType.System) {
return this.getDefaultSystemTheme();
} else {
return theme;
}
}
supportsSecureStorage(): boolean {