From 4547b2151a168aa6c3eb9c51372cbc78c82784e9 Mon Sep 17 00:00:00 2001 From: ChayaLau Date: Tue, 24 Aug 2021 12:16:19 +0300 Subject: [PATCH] register to core preferences --- .../src/browser/shell/application-shell.ts | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/core/src/browser/shell/application-shell.ts b/packages/core/src/browser/shell/application-shell.ts index 7a51d27b269c2..0732c39415eba 100644 --- a/packages/core/src/browser/shell/application-shell.ts +++ b/packages/core/src/browser/shell/application-shell.ts @@ -253,6 +253,17 @@ export class ApplicationShell extends Widget { protected init(): void { this.initSidebarVisibleKeyContext(); this.initFocusKeyContexts(); + + if (!environment.electron.is()) { + this.corePreferences.ready.then(() => { + this.setTopPanelVisibily(this.corePreferences['window.menuBarVisibility']); + }); + this.corePreferences.onPreferenceChanged(preference => { + if (preference.preferenceName === 'window.menuBarVisibility') { + this.setTopPanelVisibily(preference.newValue); + } + }); + } } protected initSidebarVisibleKeyContext(): void { @@ -282,6 +293,11 @@ export class ApplicationShell extends Widget { this.activeChanged.connect(updateFocusContextKeys); } + protected setTopPanelVisibily(preference: string): void { + const hiddenPreferences = ['compact', 'hidden']; + this.topPanel.setHidden(hiddenPreferences.includes(preference)); + } + protected onBeforeAttach(msg: Message): void { document.addEventListener('p-dragenter', this, true); document.addEventListener('p-dragover', this, true); @@ -496,22 +512,7 @@ export class ApplicationShell extends Widget { protected createTopPanel(): Panel { const topPanel = new Panel(); topPanel.id = 'theia-top-panel'; - topPanel.setHidden(true); - - // Hide top panel when the `menuBarVisibility` preference changes. - if (!environment.electron.is()) { - this.corePreferences.onPreferenceChanged(preference => { - if (preference.preferenceName === 'window.menuBarVisibility') { - const hiddenPreferences = ['compact', 'hidden']; - const hiddenNew = hiddenPreferences.includes(preference.newValue); - const hiddenOld = preference.oldValue ? hiddenPreferences.includes(preference.oldValue) : true; - - if (preference.oldValue === undefined || (hiddenNew && !hiddenOld) || (!hiddenNew && hiddenOld)) { - topPanel.setHidden(hiddenNew); - } - } - }); - } + topPanel.hide(); return topPanel; }