diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index 284d5be8d..cea18382e 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -348,6 +348,7 @@ import { ValidateSketch } from './contributions/validate-sketch'; import { RenameCloudSketch } from './contributions/rename-cloud-sketch'; import { CreateFeatures } from './create/create-features'; import { NativeImageCache } from './native-image-cache'; +import { rebindWindowPreferences } from '../electron-browser/theia/core/electron-window-preferences'; export default new ContainerModule((bind, unbind, isBound, rebind) => { // Commands and toolbar items @@ -1019,4 +1020,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { // manages native images for the electron menu icons bind(NativeImageCache).toSelf().inSingletonScope(); bind(FrontendApplicationContribution).toService(NativeImageCache); + // enable `'window.titleBarStyle'` on all supported OSs + rebindWindowPreferences(bind, rebind); }); diff --git a/arduino-ide-extension/src/electron-browser/theia/core/electron-menu-contribution.ts b/arduino-ide-extension/src/electron-browser/theia/core/electron-menu-contribution.ts index 9327637d7..b05929fc1 100644 --- a/arduino-ide-extension/src/electron-browser/theia/core/electron-menu-contribution.ts +++ b/arduino-ide-extension/src/electron-browser/theia/core/electron-menu-contribution.ts @@ -1,4 +1,4 @@ -import { inject, injectable } from '@theia/core/shared/inversify'; +import { injectable } from '@theia/core/shared/inversify'; import { CommandRegistry } from '@theia/core/lib/common/command'; import { MenuModelRegistry } from '@theia/core/lib/common/menu'; import { KeybindingRegistry } from '@theia/core/lib/browser/keybinding'; @@ -7,7 +7,6 @@ import { ElectronCommands, } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution'; import { MainMenuManager } from '../../../common/main-menu-manager'; -import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state'; import { FrontendApplication } from '@theia/core/lib/browser/frontend-application'; import { ZoomLevel } from '@theia/core/lib/electron-browser/window/electron-window-preferences'; import { PreferenceScope } from '@theia/core/lib/browser/preferences/preference-scope'; @@ -21,33 +20,22 @@ export class ElectronMenuContribution extends TheiaElectronMenuContribution implements MainMenuManager { - @inject(FrontendApplicationStateService) - private readonly appStateService: FrontendApplicationStateService; - - // private appReady = false; - // private updateWhenReady = false; + private app: FrontendApplication; override onStart(app: FrontendApplication): void { + this.app = app; super.onStart(app); - this.appStateService.reachedState('ready').then(() => { - // this.appReady = true; - // if (this.updateWhenReady) { - // this.update(); - // } - }); } protected override hideTopPanel(): void { // NOOP - // We reuse the `div` for the Arduino toolbar. + // IDE2 reuses the `div` for the toolbar. } update(): void { - // if (this.appReady) { - (this as any).setMenu(); - // } else { - // this.updateWhenReady = true; - // } + if (this.app) { + this.setMenu(this.app); + } } override registerCommands(registry: CommandRegistry): void { diff --git a/arduino-ide-extension/src/electron-browser/theia/core/electron-window-preferences.ts b/arduino-ide-extension/src/electron-browser/theia/core/electron-window-preferences.ts new file mode 100644 index 000000000..b16ae5cbb --- /dev/null +++ b/arduino-ide-extension/src/electron-browser/theia/core/electron-window-preferences.ts @@ -0,0 +1,34 @@ +import { PreferenceContribution } from '@theia/core/lib/browser/preferences/preference-contribution'; +import { PreferenceService } from '@theia/core/lib/browser/preferences/preference-service'; +import { deepClone } from '@theia/core/lib/common/objects'; +import { PreferenceSchema } from '@theia/core/lib/common/preferences/preference-schema'; +import { + createElectronWindowPreferences, + ElectronWindowPreferenceContribution, + ElectronWindowPreferences, + electronWindowPreferencesSchema as theiaElectronWindowPreferencesSchema, +} from '@theia/core/lib/electron-browser/window/electron-window-preferences'; +import { interfaces } from '@theia/core/shared/inversify'; + +const copy = deepClone(theiaElectronWindowPreferencesSchema); +copy.properties['window.titleBarStyle'].included = true; // https://github.com/eclipse-theia/theia/pull/10044#issuecomment-1423841453 +const electronWindowPreferencesSchema: PreferenceSchema = copy; + +export function rebindWindowPreferences( + bind: interfaces.Bind, + rebind: interfaces.Rebind +): void { + rebind(ElectronWindowPreferences) + .toDynamicValue((ctx) => { + const preferences = + ctx.container.get(PreferenceService); + const contribution = ctx.container.get( + ElectronWindowPreferenceContribution + ); + return createElectronWindowPreferences(preferences, contribution.schema); + }) + .inSingletonScope(); + rebind(ElectronWindowPreferenceContribution).toConstantValue({ + schema: electronWindowPreferencesSchema, + }); +}