Skip to content

Commit

Permalink
Introduce ThemeMode type
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Richter <[email protected]>
  • Loading branch information
mvtec-richter committed Feb 27, 2025
1 parent 354f83e commit 2d78c6f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/common/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { URI } from 'vscode-uri';

export type ThemeType = 'light' | 'dark' | 'hc' | 'hcLight';

export type ThemeMode = 'light' | 'dark';

export interface Theme {
readonly id: string;
readonly type: ThemeType;
Expand All @@ -32,8 +34,8 @@ export function isHighContrast(scheme: ThemeType): boolean {
return scheme === 'hc' || scheme === 'hcLight';
}

export function isLightOrDark(type: ThemeType): 'light' | 'dark' {
return type === 'hc' || type === 'dark' ? 'dark' : 'light';
export function getThemeMode(type: ThemeType): ThemeMode {
return (type === 'hc' || type === 'dark') ? 'dark' : 'light';
}

export interface ThemeChangeEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { WindowTitleService } from '../../browser/window/window-title-service';

import '../../../src/electron-browser/menu/electron-menu-style.css';
import { ThemeService } from '../../browser/theming';
import { isLightOrDark, ThemeChangeEvent } from '../../common/theme';
import { getThemeMode, ThemeChangeEvent } from '../../common/theme';

export namespace ElectronCommands {
export const TOGGLE_DEVELOPER_TOOLS = Command.toDefaultLocalizedCommand({
Expand Down Expand Up @@ -424,7 +424,7 @@ export class ElectronMenuContribution extends BrowserMenuBarContribution impleme
protected handleThemeChange(e: ThemeChangeEvent): void {
const backgroundColor = window.getComputedStyle(document.body).backgroundColor;
window.electronTheiaCore.setBackgroundColor(backgroundColor);
window.electronTheiaCore.setTheme(isLightOrDark(e.newTheme.type));
window.electronTheiaCore.setTheme(getThemeMode(e.newTheme.type));
}

}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/electron-common/electron-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { NativeKeyboardLayout } from '../common/keyboard/keyboard-layout-provider';
import { Disposable } from '../common';
import { FrontendApplicationState, StopReason } from '../common/frontend-application-state';
import { ThemeMode } from '../common/theme';

export type MenuRole = ('undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'selectAll' | 'about' | 'services' | 'hide' | 'hideOthers' | 'unhide' | 'quit');

Expand Down Expand Up @@ -65,7 +66,7 @@ export interface TheiaCoreAPI {
getTitleBarStyleAtStartup(): Promise<string>;
setTitleBarStyle(style: string): void;
setBackgroundColor(backgroundColor: string): void;
setTheme(theme: 'dark' | 'light'): void;
setTheme(theme: ThemeMode): void;
minimize(): void;
isMaximized(): boolean; // TODO: this should really be async, since it blocks the renderer process
maximize(): void;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/electron-main/electron-main-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { createDisposableListener } from './event-utils';
import { TheiaRendererAPI } from './electron-api-main';
import { StopReason } from '../common/frontend-application-state';
import { dynamicRequire } from '../node/dynamic-require';
import { ThemeMode } from '../common/theme';

export { ElectronMainApplicationGlobals };

Expand Down Expand Up @@ -277,7 +278,7 @@ export class ElectronMainApplication {
this.saveState(webContents);
}

public setTheme(theme: 'light' | 'dark'): void {
public setTheme(theme: ThemeMode): void {
nativeTheme.themeSource = theme;
}

Expand Down

0 comments on commit 2d78c6f

Please sign in to comment.