Skip to content

Commit

Permalink
Properly set default light and dark theme
Browse files Browse the repository at this point in the history
- Concrete Theme will be derived from default OS theme
- Remove built-in themes as soon as the actual theme is loaded
  • Loading branch information
martin-fleck-at committed Dec 13, 2024
1 parent 4cb3ef9 commit 094e6ad
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
5 changes: 4 additions & 1 deletion applications/browser-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion applications/electron-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/product/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down
27 changes: 27 additions & 0 deletions packages/product/src/browser/cross-model-theme-service.ts
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
11 changes: 11 additions & 0 deletions packages/product/src/browser/product-frontend-module.ts
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 094e6ad

Please sign in to comment.