Skip to content

Commit 64ef89b

Browse files
committed
MOBILE-4912 menu: Listen to config updates to update the handlers
1 parent 93b22c3 commit 64ef89b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/core/features/mainmenu/services/mainmenu-delegate.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import { CoreSortedDelegate } from '@classes/delegate-sorted';
2020
import { makeSingleton } from '@singletons';
2121
import { MAIN_MENU_FEATURE_PREFIX } from '../constants';
2222
import { CoreConstants } from '@/core/constants';
23+
import { CoreEvents } from '@singletons/events';
24+
import { CoreConfigProvider } from '@services/config';
25+
import { CoreMainMenuOverrideItem } from './mainmenu';
2326

2427
/**
2528
* Interface that all main menu handlers must implement.
@@ -109,6 +112,19 @@ export interface CoreMainMenuHandlerToDisplay extends CoreDelegateToDisplay, Cor
109112
export class CoreMainMenuDelegateService extends CoreSortedDelegate<CoreMainMenuHandlerToDisplay, CoreMainMenuHandler> {
110113

111114
protected featurePrefix = MAIN_MENU_FEATURE_PREFIX;
115+
protected previousEnvironment: CoreMainMenuOverrideItem[] = [];
116+
117+
constructor() {
118+
super();
119+
120+
CoreEvents.on(CoreConfigProvider.ENVIRONMENT_UPDATED, (config) => {
121+
const newConfig = config.overrideMainMenuButtons ?? [];
122+
if (JSON.stringify(this.previousEnvironment) === JSON.stringify(newConfig)) {
123+
return;
124+
}
125+
this.updateHandlers();
126+
});
127+
}
112128

113129
/**
114130
* @inheritdoc
@@ -118,6 +134,8 @@ export class CoreMainMenuDelegateService extends CoreSortedDelegate<CoreMainMenu
118134

119135
// Override priority and icon if needed.
120136
const config = CoreConstants.CONFIG.overrideMainMenuButtons ?? [];
137+
this.previousEnvironment = config;
138+
121139
const override = config.find((entry) => entry.handler === name);
122140
if (override) {
123141
if (override.priority !== undefined) {

0 commit comments

Comments
 (0)