diff --git a/src/addons/messages/services/handlers/mainmenu.ts b/src/addons/messages/services/handlers/mainmenu.ts index 5e083663e..d10d79d02 100644 --- a/src/addons/messages/services/handlers/mainmenu.ts +++ b/src/addons/messages/services/handlers/mainmenu.ts @@ -26,11 +26,11 @@ import { } from '@features/pushnotifications/services/pushnotifications'; import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate'; import { makeSingleton } from '@singletons'; -import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu'; import { ADDON_MESSAGES_UNREAD_CONVERSATION_COUNTS_EVENT, ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT, } from '@addons/messages/constants'; +import { MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT } from '@features/mainmenu/constants'; /** * Handler to inject an option into main menu. @@ -177,7 +177,7 @@ export class AddonMessagesMainMenuHandlerService implements CoreMainMenuHandler, // Update push notifications badge. CoreEvents.trigger( - CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED, + MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, { handler: AddonMessagesMainMenuHandlerService.name, value: totalCount, diff --git a/src/addons/notifications/services/handlers/mainmenu.ts b/src/addons/notifications/services/handlers/mainmenu.ts index ddf7ce72d..bf4e7accc 100644 --- a/src/addons/notifications/services/handlers/mainmenu.ts +++ b/src/addons/notifications/services/handlers/mainmenu.ts @@ -22,7 +22,7 @@ import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate'; import { AddonNotifications, AddonNotificationsProvider } from '../notifications'; -import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu'; +import { MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT } from '@features/mainmenu/constants'; /** * Handler to inject an option into main menu. @@ -120,7 +120,7 @@ export class AddonNotificationsMainMenuHandlerService implements CoreMainMenuHan CorePushNotifications.updateAddonCounter(AddonNotificationsMainMenuHandlerService.name, unreadCountData.count, siteId); CoreEvents.trigger( - CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED, + MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, { handler: AddonNotificationsMainMenuHandlerService.name, value: unreadCountData.count, diff --git a/src/core/features/compile/services/compile.ts b/src/core/features/compile/services/compile.ts index 3ba1f3c42..8c9f316b9 100644 --- a/src/core/features/compile/services/compile.ts +++ b/src/core/features/compile/services/compile.ts @@ -55,7 +55,7 @@ import { getFilterServices } from '@features/filter/filter.module'; import { getGradesServices } from '@features/grades/grades.module'; import { getH5PServices } from '@features/h5p/h5p.module'; import { getLoginServices } from '@features/login/login.module'; -import { getMainMenuServices } from '@features/mainmenu/mainmenu.module'; +import { getMainMenuExportedObjects, getMainMenuServices } from '@features/mainmenu/mainmenu.module'; import { getNativeServices } from '@features/native/native.module'; import { getPushNotificationsServices } from '@features/pushnotifications/pushnotifications.module'; import { getQuestionServices } from '@features/question/question.module'; @@ -420,6 +420,7 @@ export class CoreCompileProvider { getCoreErrorsExportedObjects(), getCourseExportedObjects(), getCoursesExportedObjects(), + getMainMenuExportedObjects(), getContentLinksExportedObjects(), getSitePluginsExportedObjects(), ]); diff --git a/src/core/features/mainmenu/constants.ts b/src/core/features/mainmenu/constants.ts new file mode 100644 index 000000000..16d6ea7a7 --- /dev/null +++ b/src/core/features/mainmenu/constants.ts @@ -0,0 +1,20 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +export const MAIN_MENU_NUM_MAIN_HANDLERS = 4; +export const MAIN_MENU_ITEM_MIN_WIDTH = 72; // Min with of every item, based on 5 items on a 360 pixel wide screen. +export const MAIN_MENU_MORE_PAGE_NAME = 'more'; + +export const MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT = 'main_menu_handler_badge_updated'; +export const MAIN_MENU_VISIBILITY_UPDATED_EVENT = 'main_menu_visbility_updated'; diff --git a/src/core/features/mainmenu/mainmenu-lazy.module.ts b/src/core/features/mainmenu/mainmenu-lazy.module.ts index 98c8fd587..c4f027e96 100644 --- a/src/core/features/mainmenu/mainmenu-lazy.module.ts +++ b/src/core/features/mainmenu/mainmenu-lazy.module.ts @@ -19,8 +19,8 @@ import { CoreSharedModule } from '@/core/shared.module'; import { resolveMainMenuRoutes } from './mainmenu-routing.module'; import { CoreMainMenuPage } from './pages/menu/menu'; import { CoreMainMenuHomeHandlerService } from './services/handlers/mainmenu'; -import { CoreMainMenuProvider } from './services/mainmenu'; import { CoreMainMenuComponentsModule } from './components/components.module'; +import { MAIN_MENU_MORE_PAGE_NAME } from './constants'; /** * Build module routes. @@ -41,7 +41,7 @@ function buildRoutes(injector: Injector): Routes { loadChildren: () => import('./mainmenu-home-lazy.module'), }, { - path: CoreMainMenuProvider.MORE_PAGE_NAME, + path: MAIN_MENU_MORE_PAGE_NAME, loadChildren: () => import('./mainmenu-more-lazy.module'), }, ...mainMenuRoutes.children, diff --git a/src/core/features/mainmenu/mainmenu-more-lazy.module.ts b/src/core/features/mainmenu/mainmenu-more-lazy.module.ts index 4f3b1aa11..b78ed0db4 100644 --- a/src/core/features/mainmenu/mainmenu-more-lazy.module.ts +++ b/src/core/features/mainmenu/mainmenu-more-lazy.module.ts @@ -17,9 +17,9 @@ import { Routes, ROUTES } from '@angular/router'; import { CoreSharedModule } from '@/core/shared.module'; import { buildTabMainRoutes } from '@features/mainmenu/mainmenu-tab-routing.module'; -import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu'; import { CoreMainMenuComponentsModule } from '@features/mainmenu/components/components.module'; import { CoreMainMenuMorePage } from '@features/mainmenu/pages/more/more'; +import { MAIN_MENU_MORE_PAGE_NAME } from './constants'; /** * Build module routes. @@ -31,7 +31,7 @@ function buildRoutes(injector: Injector): Routes { return buildTabMainRoutes(injector, { component: CoreMainMenuMorePage, data: { - mainMenuTabRoot: CoreMainMenuProvider.MORE_PAGE_NAME, + mainMenuTabRoot: MAIN_MENU_MORE_PAGE_NAME, }, }); } diff --git a/src/core/features/mainmenu/mainmenu.module.ts b/src/core/features/mainmenu/mainmenu.module.ts index 23d5ab607..fa4e0354b 100644 --- a/src/core/features/mainmenu/mainmenu.module.ts +++ b/src/core/features/mainmenu/mainmenu.module.ts @@ -38,6 +38,32 @@ export async function getMainMenuServices(): Promise[]> { ]; } +/** + * Get main menu exported objects. + * + * @returns Main menu exported objects. + */ +export async function getMainMenuExportedObjects(): Promise> { + const { + MAIN_MENU_NUM_MAIN_HANDLERS, + MAIN_MENU_ITEM_MIN_WIDTH, + MAIN_MENU_MORE_PAGE_NAME, + MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, + MAIN_MENU_VISIBILITY_UPDATED_EVENT, + + } = await import('@features/mainmenu/constants'); + + /* eslint-disable @typescript-eslint/naming-convention */ + return { + MAIN_MENU_NUM_MAIN_HANDLERS, + MAIN_MENU_ITEM_MIN_WIDTH, + MAIN_MENU_MORE_PAGE_NAME, + MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, + MAIN_MENU_VISIBILITY_UPDATED_EVENT, + }; + /* eslint-enable @typescript-eslint/naming-convention */ +} + const appRoutes: Routes = [ { path: '', diff --git a/src/core/features/mainmenu/pages/menu/menu.ts b/src/core/features/mainmenu/pages/menu/menu.ts index 1202ba83b..16ceee0f5 100644 --- a/src/core/features/mainmenu/pages/menu/menu.ts +++ b/src/core/features/mainmenu/pages/menu/menu.ts @@ -18,7 +18,7 @@ import { BackButtonEvent } from '@ionic/core'; import { Subscription } from 'rxjs'; import { CoreEvents, CoreEventObserver } from '@singletons/events'; -import { CoreMainMenu, CoreMainMenuProvider } from '../../services/mainmenu'; +import { CoreMainMenu } from '../../services/mainmenu'; import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu-delegate'; import { Router } from '@singletons'; import { CoreUtils } from '@services/utils/utils'; @@ -35,6 +35,11 @@ import { CoreWait } from '@singletons/wait'; import { CoreMainMenuDeepLinkManager } from '@features/mainmenu/classes/deep-link-manager'; import { CoreSiteInfoUserHomepage } from '@classes/sites/unauthenticated-site'; import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper'; +import { + MAIN_MENU_MORE_PAGE_NAME, + MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, + MAIN_MENU_VISIBILITY_UPDATED_EVENT, +} from '@features/mainmenu/constants'; const ANIMATION_DURATION = 500; @@ -72,7 +77,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy { loaded = false; showTabs = false; tabsPlacement: 'bottom' | 'side' = 'bottom'; - morePageName = CoreMainMenuProvider.MORE_PAGE_NAME; + morePageName = MAIN_MENU_MORE_PAGE_NAME; selectedTab?: string; isMainScreen = false; moreBadge = false; @@ -124,7 +129,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy { this.updateHandlers(previousHandlers); }); - this.badgeUpdateObserver = CoreEvents.on(CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED, (data) => { + this.badgeUpdateObserver = CoreEvents.on(MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, (data) => { if (data.siteId == CoreSites.getCurrentSiteId()) { this.updateMoreBadge(); } @@ -361,7 +366,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy { await CoreWait.wait(ANIMATION_DURATION); await CoreWait.nextTick(); - CoreEvents.trigger(CoreMainMenuProvider.MAIN_MENU_VISIBILITY_UPDATED); + CoreEvents.trigger(MAIN_MENU_VISIBILITY_UPDATED_EVENT); } } diff --git a/src/core/features/mainmenu/services/mainmenu.ts b/src/core/features/mainmenu/services/mainmenu.ts index 1ad919e16..1b1d08baa 100644 --- a/src/core/features/mainmenu/services/mainmenu.ts +++ b/src/core/features/mainmenu/services/mainmenu.ts @@ -22,6 +22,13 @@ import { Device, makeSingleton } from '@singletons'; import { CoreText } from '@singletons/text'; import { CoreScreen } from '@services/screen'; import { CorePlatform } from '@services/platform'; +import { + MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, + MAIN_MENU_ITEM_MIN_WIDTH, + MAIN_MENU_MORE_PAGE_NAME, + MAIN_MENU_NUM_MAIN_HANDLERS, + MAIN_MENU_VISIBILITY_UPDATED_EVENT, +} from '../constants'; declare module '@singletons/events' { @@ -31,8 +38,8 @@ declare module '@singletons/events' { * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation */ export interface CoreEventsData { - [CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED]: CoreMainMenuHandlerBadgeUpdatedEventData; - [CoreMainMenuProvider.MAIN_MENU_VISIBILITY_UPDATED]: void; + [MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT]: CoreMainMenuHandlerBadgeUpdatedEventData; + [MAIN_MENU_VISIBILITY_UPDATED_EVENT]: void; } } @@ -43,11 +50,26 @@ declare module '@singletons/events' { @Injectable({ providedIn: 'root' }) export class CoreMainMenuProvider { - static readonly NUM_MAIN_HANDLERS = 4; - static readonly ITEM_MIN_WIDTH = 72; // Min with of every item, based on 5 items on a 360 pixel wide screen. - static readonly MORE_PAGE_NAME = 'more'; - static readonly MAIN_MENU_HANDLER_BADGE_UPDATED = 'main_menu_handler_badge_updated'; - static readonly MAIN_MENU_VISIBILITY_UPDATED = 'main_menu_visbility_updated'; + /** + * @deprecated since 5.0. Use MAIN_MENU_NUM_MAIN_HANDLERS instead. + */ + static readonly NUM_MAIN_HANDLERS = MAIN_MENU_NUM_MAIN_HANDLERS; + /** + * @deprecated since 5.0. Use MAIN_MENU_ITEM_MIN_WIDTH instead. + */ + static readonly ITEM_MIN_WIDTH = MAIN_MENU_ITEM_MIN_WIDTH; + /** + * @deprecated since 5.0. Use MAIN_MENU_MORE_PAGE_NAME instead. + */ + static readonly MORE_PAGE_NAME = MAIN_MENU_MORE_PAGE_NAME; + /** + * @deprecated since 5.0. Use MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT instead. + */ + static readonly MAIN_MENU_HANDLER_BADGE_UPDATED = MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT; + /** + * @deprecated since 5.0. Use MAIN_MENU_VISIBILITY_UPDATED_EVENT instead. + */ + static readonly MAIN_MENU_VISIBILITY_UPDATED = MAIN_MENU_VISIBILITY_UPDATED_EVENT; /** * Get the current main menu handlers. @@ -229,9 +251,9 @@ export class CoreMainMenuProvider { if (CoreScreen.isTablet) { // Tablet, menu will be displayed vertically. - numElements = Math.floor(window.innerHeight / CoreMainMenuProvider.ITEM_MIN_WIDTH); + numElements = Math.floor(window.innerHeight / MAIN_MENU_ITEM_MIN_WIDTH); } else { - numElements = Math.floor(window.innerWidth / CoreMainMenuProvider.ITEM_MIN_WIDTH); + numElements = Math.floor(window.innerWidth / MAIN_MENU_ITEM_MIN_WIDTH); // Set a maximum elements to show and skip more button. numElements = numElements >= 5 ? 5 : numElements; @@ -241,7 +263,7 @@ export class CoreMainMenuProvider { return numElements > 1 ? numElements - 1 : 1; } - return CoreMainMenuProvider.NUM_MAIN_HANDLERS; + return MAIN_MENU_NUM_MAIN_HANDLERS; } /** @@ -260,7 +282,7 @@ export class CoreMainMenuProvider { * @returns Promise resolved with boolean: whether it's the root of a main menu tab. */ async isMainMenuTab(pageName: string): Promise { - if (pageName == CoreMainMenuProvider.MORE_PAGE_NAME) { + if (pageName == MAIN_MENU_MORE_PAGE_NAME) { return true; } diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 0ac678149..0e131e2dd 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -44,7 +44,6 @@ import { import { CoreError } from '@classes/errors/error'; import { CoreWSExternalWarning } from '@services/ws'; import { CoreSitesFactory } from '@services/sites-factory'; -import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu'; import { AsyncInstance, asyncInstance } from '@/core/utils/async-instance'; import { CoreDatabaseTable } from '@classes/database/database-table'; import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy'; @@ -56,6 +55,7 @@ import { CoreSiteInfo } from '@classes/sites/unauthenticated-site'; import { Push } from '@features/native/plugins'; import { CoreNavigator } from '@services/navigator'; import { CoreWait } from '@singletons/wait'; +import { MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT } from '@features/mainmenu/constants'; /** * Service to handle push notifications. @@ -149,7 +149,7 @@ export class CorePushNotificationsProvider { } }); - CoreEvents.on(CoreMainMenuProvider.MAIN_MENU_HANDLER_BADGE_UPDATED, (data) => { + CoreEvents.on(MAIN_MENU_HANDLER_BADGE_UPDATED_EVENT, (data) => { this.updateAddonCounter(data.handler, data.value, data.siteId); }); diff --git a/src/core/features/usertours/components/user-tour/user-tour.ts b/src/core/features/usertours/components/user-tour/user-tour.ts index 94c61ce2b..3b829ef72 100644 --- a/src/core/features/usertours/components/user-tour/user-tour.ts +++ b/src/core/features/usertours/components/user-tour/user-tour.ts @@ -33,8 +33,8 @@ import { AngularFrameworkDelegate } from '@singletons'; import { CoreDirectivesRegistry } from '@singletons/directives-registry'; import { CoreDom } from '@singletons/dom'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu'; import { COLLAPSIBLE_HEADER_UPDATED } from '@directives/collapsible-header'; +import { MAIN_MENU_VISIBILITY_UPDATED_EVENT } from '@features/mainmenu/constants'; const ANIMATION_DURATION = 200; const USER_TOURS_BACK_BUTTON_PRIORITY = 100; @@ -264,7 +264,7 @@ export class CoreUserToursUserTourComponent implements AfterViewInit, OnDestroy this.collapsibleHeaderListener = this.collapsibleHeaderListener ?? CoreEvents.on(COLLAPSIBLE_HEADER_UPDATED, () => this.calculateStyles()); this.mainMenuListener = this.mainMenuListener ?? - CoreEvents.on(CoreMainMenuProvider.MAIN_MENU_VISIBILITY_UPDATED, () => this.calculateStyles()); + CoreEvents.on(MAIN_MENU_VISIBILITY_UPDATED_EVENT, () => this.calculateStyles()); this.resizeListener = this.resizeListener ?? CoreDom.onWindowResize(() => this.calculateStyles()); this.content = this.content ?? CoreDom.closest(this.focus, 'ion-content'); diff --git a/src/core/services/app.ts b/src/core/services/app.ts index 88031995f..f5028cb8d 100644 --- a/src/core/services/app.ts +++ b/src/core/services/app.ts @@ -30,9 +30,9 @@ import { CoreDatabaseTable } from '@classes/database/database-table'; import { CorePromisedValue } from '@classes/promised-value'; import { Subscription } from 'rxjs'; import { CorePlatform } from '@services/platform'; -import { CoreMainMenuProvider } from '@features/mainmenu/services/mainmenu'; import { CoreKeyboard } from '@singletons/keyboard'; import { CoreNetwork } from './network'; +import { MAIN_MENU_VISIBILITY_UPDATED_EVENT } from '@features/mainmenu/constants'; /** * Factory to provide some global functionalities, like access to the global app database. @@ -61,7 +61,7 @@ export class CoreAppProvider { this.logger = CoreLogger.getInstance('CoreAppProvider'); if (CorePlatform.isAndroid()) { this.mainMenuListener = - CoreEvents.on(CoreMainMenuProvider.MAIN_MENU_VISIBILITY_UPDATED, () => this.setAndroidNavigationBarColor()); + CoreEvents.on(MAIN_MENU_VISIBILITY_UPDATED_EVENT, () => this.setAndroidNavigationBarColor()); } }