From 094e6ad5582e689c5cc3a64dcb611b944bf16093 Mon Sep 17 00:00:00 2001 From: Martin Fleck Date: Fri, 13 Dec 2024 15:32:29 +0100 Subject: [PATCH] Properly set default light and dark theme - Concrete Theme will be derived from default OS theme - Remove built-in themes as soon as the actual theme is loaded --- applications/browser-app/package.json | 5 +++- applications/electron-app/package.json | 5 +++- packages/product/package.json | 2 ++ .../src/browser/cross-model-theme-service.ts | 27 +++++++++++++++++++ .../src/browser/product-frontend-module.ts | 11 ++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 packages/product/src/browser/cross-model-theme-service.ts create mode 100644 packages/product/src/browser/product-frontend-module.ts diff --git a/applications/browser-app/package.json b/applications/browser-app/package.json index c0dd066e..a95d9362 100644 --- a/applications/browser-app/package.json +++ b/applications/browser-app/package.json @@ -54,7 +54,10 @@ "frontend": { "config": { "applicationName": "CrossModel Community Edition", - "defaultTheme": "crossmodel-light", + "defaultTheme": { + "light": "crossmodel-light", + "dark": "crossmodel-dark" + }, "preferences": { "security.workspace.trust.enabled": false, "files.associations": { diff --git a/applications/electron-app/package.json b/applications/electron-app/package.json index d2e1cc48..973165fc 100644 --- a/applications/electron-app/package.json +++ b/applications/electron-app/package.json @@ -64,7 +64,10 @@ "frontend": { "config": { "applicationName": "CrossModel Community Edition", - "defaultTheme": "crossmodel-light", + "defaultTheme": { + "light": "crossmodel-light", + "dark": "crossmodel-dark" + }, "reloadOnReconnect": true, "preferences": { "security.workspace.trust.enabled": false, diff --git a/packages/product/package.json b/packages/product/package.json index e4f8b89c..ce35ae34 100644 --- a/packages/product/package.json +++ b/packages/product/package.json @@ -31,10 +31,12 @@ "dependencies": { "@theia/core": "1.49.1", "@theia/getting-started": "1.49.1", + "@theia/monaco": "1.49.1", "@theia/workspace": "1.49.1" }, "theiaExtensions": [ { + "frontend": "lib/browser/product-frontend-module", "electronMain": "lib/electron-main/product-electron-main-module" } ] diff --git a/packages/product/src/browser/cross-model-theme-service.ts b/packages/product/src/browser/cross-model-theme-service.ts new file mode 100644 index 00000000..e86531a8 --- /dev/null +++ b/packages/product/src/browser/cross-model-theme-service.ts @@ -0,0 +1,27 @@ +/******************************************************************************** + * Copyright (c) 2024 CrossBreeze. + ********************************************************************************/ + +import { BuiltinThemeProvider } from '@theia/core/lib/browser/theming'; +import { injectable } from '@theia/core/shared/inversify'; +import { ThemeServiceWithDB } from '@theia/monaco/lib/browser/monaco-indexed-db'; + +@injectable() +export class CrossModelThemeService extends ThemeServiceWithDB { + override setCurrentTheme(themeId: string, persist?: boolean): void { + super.setCurrentTheme(themeId, persist); + this.removeBuiltInThemes(themeId); + } + + protected removeBuiltInThemes(themeId: string): void { + if (!this.tryGetTheme(BuiltinThemeProvider.themes[0].id)) { + // the built-in themes are already removed + return; + } + const configuredTheme = this.getConfiguredTheme(); + if (configuredTheme && configuredTheme.id === themeId) { + // remove built-in themes as soon as we have the configured theme ready, which may be loaded delayed through an extension + BuiltinThemeProvider.themes.forEach(theme => this.register(theme).dispose()); + } + } +} diff --git a/packages/product/src/browser/product-frontend-module.ts b/packages/product/src/browser/product-frontend-module.ts new file mode 100644 index 00000000..c4bade54 --- /dev/null +++ b/packages/product/src/browser/product-frontend-module.ts @@ -0,0 +1,11 @@ +/******************************************************************************** + * Copyright (c) 2024 CrossBreeze. + ********************************************************************************/ +import { ContainerModule } from '@theia/core/shared/inversify'; +import { ThemeServiceWithDB } from '@theia/monaco/lib/browser/monaco-indexed-db'; +import { CrossModelThemeService } from './cross-model-theme-service'; + +export default new ContainerModule((bind, _unbind, _isBound, rebind) => { + bind(CrossModelThemeService).toSelf().inSingletonScope(); + rebind(ThemeServiceWithDB).toService(CrossModelThemeService); +});