Skip to content

Commit be50b79

Browse files
author
Akos Kitta
committed
Use DI in theme service to handle the default IDE2 theme.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 352adb4 commit be50b79

File tree

8 files changed

+89
-30
lines changed

8 files changed

+89
-30
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+11
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ import { SelectedBoard } from './contributions/selected-board';
309309
import { CheckForUpdates } from './contributions/check-for-updates';
310310
import { OpenBoardsConfig } from './contributions/open-boards-config';
311311
import { SketchFilesTracker } from './contributions/sketch-files-tracker';
312+
import { ThemeService } from './theia/core/theming';
313+
import { ThemeService as TheiaThemeService } from '@theia/core/lib/browser/theming';
314+
import { MonacoThemingService } from './theia/monaco/monaco-theming-service';
315+
import { MonacoThemingService as TheiaMonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
312316

313317
export default new ContainerModule((bind, unbind, isBound, rebind) => {
314318
// Commands and toolbar items
@@ -599,6 +603,13 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
599603
bind(WindowContribution).toSelf().inSingletonScope();
600604
rebind(TheiaWindowContribution).toService(WindowContribution);
601605

606+
// Customized theme service to dispatch the default IDE2 theme based on the OS' theme.
607+
bind(ThemeService).toSelf().inSingletonScope();
608+
rebind(TheiaThemeService).toService(ThemeService);
609+
// The monaco part of the theme customization
610+
bind(MonacoThemingService).toSelf().inSingletonScope();
611+
rebind(TheiaMonacoThemingService).toService(MonacoThemingService);
612+
602613
bind(ArduinoDaemon)
603614
.toDynamicValue((context) =>
604615
WebSocketConnectionProvider.createProxy(

Diff for: arduino-ide-extension/src/browser/contributions/first-startup-installer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class FirstStartupInstaller extends Contribution {
4343
// If arduino:avr installation fails because it's already installed we don't want to retry on next start-up
4444
console.error(e);
4545
} else {
46-
// But if there is any other error (e.g.: no interntet cconnection), we want to retry next time
46+
// But if there is any other error (e.g.: no Internet connection), we want to retry next time
4747
avrPackageError = e;
4848
}
4949
}
@@ -64,7 +64,7 @@ export class FirstStartupInstaller extends Contribution {
6464
// If Arduino_BuiltIn installation fails because it's already installed we don't want to retry on next start-up
6565
console.log('error installing core', e);
6666
} else {
67-
// But if there is any other error (e.g.: no interntet cconnection), we want to retry next time
67+
// But if there is any other error (e.g.: no Internet connection), we want to retry next time
6868
builtInLibraryError = e;
6969
}
7070
}

Diff for: arduino-ide-extension/src/browser/dialogs/settings/settings.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@theia/core/shared/inversify';
66
import URI from '@theia/core/lib/common/uri';
77
import { Emitter } from '@theia/core/lib/common/event';
8-
import { Deferred, timeout } from '@theia/core/lib/common/promise-util';
8+
import { Deferred } from '@theia/core/lib/common/promise-util';
99
import { deepClone } from '@theia/core/lib/common/objects';
1010
import { FileService } from '@theia/filesystem/lib/browser/file-service';
1111
import { ThemeService } from '@theia/core/lib/browser/theming';
@@ -25,6 +25,7 @@ import {
2525
LanguageInfo,
2626
} from '@theia/core/lib/common/i18n/localization';
2727
import { ElectronCommands } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
28+
import { ArduinoThemes } from '../../theia/core/theming';
2829

2930
export const EDITOR_SETTING = 'editor';
3031
export const FONT_SIZE_SETTING = `${EDITOR_SETTING}.fontSize`;
@@ -142,7 +143,7 @@ export class SettingsService {
142143
this.preferenceService.get<number>(FONT_SIZE_SETTING, 12),
143144
this.preferenceService.get<string>(
144145
'workbench.colorTheme',
145-
'arduino-theme'
146+
ArduinoThemes.Default.id
146147
),
147148
this.preferenceService.get<Settings.AutoSave>(
148149
AUTO_SAVE_SETTING,
@@ -246,7 +247,6 @@ export class SettingsService {
246247

247248
private async savePreference(name: string, value: unknown): Promise<void> {
248249
await this.preferenceService.set(name, value, PreferenceScope.User);
249-
await timeout(5);
250250
}
251251

252252
async save(): Promise<string | true> {
@@ -277,19 +277,21 @@ export class SettingsService {
277277
(config as any).network = network;
278278
(config as any).locale = currentLanguage;
279279

280-
await this.savePreference('editor.fontSize', editorFontSize);
281-
await this.savePreference('workbench.colorTheme', themeId);
282-
await this.savePreference(AUTO_SAVE_SETTING, autoSave);
283-
await this.savePreference('editor.quickSuggestions', quickSuggestions);
284-
await this.savePreference(AUTO_SCALE_SETTING, autoScaleInterface);
285-
await this.savePreference(ZOOM_LEVEL_SETTING, interfaceScale);
286-
await this.savePreference(ZOOM_LEVEL_SETTING, interfaceScale);
287-
await this.savePreference(COMPILE_VERBOSE_SETTING, verboseOnCompile);
288-
await this.savePreference(COMPILE_WARNINGS_SETTING, compilerWarnings);
289-
await this.savePreference(UPLOAD_VERBOSE_SETTING, verboseOnUpload);
290-
await this.savePreference(UPLOAD_VERIFY_SETTING, verifyAfterUpload);
291-
await this.savePreference(SHOW_ALL_FILES_SETTING, sketchbookShowAllFiles);
292-
await this.configService.setConfiguration(config);
280+
await Promise.all([
281+
this.savePreference('editor.fontSize', editorFontSize),
282+
this.savePreference('workbench.colorTheme', themeId),
283+
this.savePreference(AUTO_SAVE_SETTING, autoSave),
284+
this.savePreference('editor.quickSuggestions', quickSuggestions),
285+
this.savePreference(AUTO_SCALE_SETTING, autoScaleInterface),
286+
this.savePreference(ZOOM_LEVEL_SETTING, interfaceScale),
287+
this.savePreference(ZOOM_LEVEL_SETTING, interfaceScale),
288+
this.savePreference(COMPILE_VERBOSE_SETTING, verboseOnCompile),
289+
this.savePreference(COMPILE_WARNINGS_SETTING, compilerWarnings),
290+
this.savePreference(UPLOAD_VERBOSE_SETTING, verboseOnUpload),
291+
this.savePreference(UPLOAD_VERIFY_SETTING, verifyAfterUpload),
292+
this.savePreference(SHOW_ALL_FILES_SETTING, sketchbookShowAllFiles),
293+
this.configService.setConfiguration(config),
294+
]);
293295
this.onDidChangeEmitter.fire(this._settings);
294296

295297
// after saving all the settings, if we need to change the language we need to perform a reload
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ApplicationProps } from '@theia/application-package/lib/application-props';
2+
import { ThemeService as TheiaThemeService } from '@theia/core/lib/browser/theming';
3+
import type { Theme } from '@theia/core/lib/common/theme';
4+
import { injectable } from '@theia/core/shared/inversify';
5+
6+
@injectable()
7+
export class ThemeService extends TheiaThemeService {
8+
override get defaultTheme(): Theme {
9+
// TODO: provide a PR in Theia to support `light` and `dark` themes natively.
10+
return (
11+
this.themes[ArduinoThemes.Default.id] ||
12+
this.themes[ApplicationProps.DEFAULT.frontend.config.defaultTheme]
13+
);
14+
}
15+
}
16+
17+
export namespace ArduinoThemes {
18+
export const Light: Theme = {
19+
id: 'arduino-theme',
20+
type: 'light',
21+
label: 'Light (Arduino)',
22+
editorTheme: 'arduino-theme',
23+
};
24+
export const Dark: Theme = {
25+
id: 'arduino-dark-theme',
26+
type: 'dark',
27+
label: 'Dark (Arduino)',
28+
editorTheme: 'arduino-dark-theme',
29+
};
30+
export const Default =
31+
window.matchMedia &&
32+
window.matchMedia('(prefers-color-scheme: dark)').matches
33+
? Dark
34+
: Light;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { injectable } from '@theia/core/shared/inversify';
2+
import { MonacoThemingService as TheiaMonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
3+
4+
@injectable()
5+
export class MonacoThemingService extends TheiaMonacoThemingService {
6+
override initialize(): void {
7+
super.initialize();
8+
this.registerParsedTheme({
9+
id: 'arduino-theme',
10+
label: 'Light (Arduino)',
11+
uiTheme: 'vs',
12+
json: require('../../../../src/browser/data/default.color-theme.json'),
13+
});
14+
this.registerParsedTheme({
15+
id: 'arduino-theme-dark',
16+
label: 'Dark (Arduino)',
17+
uiTheme: 'vs-dark',
18+
json: require('../../../../src/browser/data/dark.color-theme.json'),
19+
});
20+
}
21+
}

Diff for: electron/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ working-copy/
66
src-gen/
77
node_modules/
88
build/yarn.lock
9+
webpack.config.js
910
lib/
1011

1112
# The electron-builder output.

Diff for: electron/build/webpack.config.js

-10
This file was deleted.

Diff for: electron/packager/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@
5151
'patch',
5252
'resources',
5353
'scripts',
54-
'template-package.json',
55-
'webpack.config.js'
54+
'template-package.json'
5655
];
5756
fs.readdirSync(path('..', 'build'))
5857
.filter((filename) => resourcesToKeep.indexOf(filename) === -1)

0 commit comments

Comments
 (0)