Skip to content

Commit

Permalink
fix: enabled window.titleBarStyle on macOS
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Feb 9, 2023
1 parent 65add68 commit 479628b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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>(PreferenceService);
const contribution = ctx.container.get<PreferenceContribution>(
ElectronWindowPreferenceContribution
);
return createElectronWindowPreferences(preferences, contribution.schema);
})
.inSingletonScope();
rebind(ElectronWindowPreferenceContribution).toConstantValue({
schema: electronWindowPreferencesSchema,
});
}

0 comments on commit 479628b

Please sign in to comment.