diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 5b75b9b9a..a4f2c7c0f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -34,7 +34,6 @@ import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreDom } from '@singletons/dom'; import { CorePlatform } from '@services/platform'; -import { CoreUserHelper } from '@features/user/services/user-helper'; const MOODLE_VERSION_PREFIX = 'version-'; const MOODLEAPP_VERSION_PREFIX = 'moodleapp-'; @@ -53,13 +52,6 @@ export class AppComponent implements OnInit, AfterViewInit { /** * Component being initialized. - * - * @todo Review all old code to see if something is missing: - * - IAB events listening. - * - Platform pause/resume subscriptions. - * - handleOpenURL and openWindowSafely. - * - Back button registering to close modal first. - * - Note: HideKeyboardFormAccessoryBar has been moved to config.xml. */ ngOnInit(): void { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -101,24 +93,6 @@ export class AppComponent implements OnInit, AfterViewInit { content.classList.toggle('core-footer-shadow', !CoreDom.scrollIsBottom(scrollElement)); }); - // Listen for session expired events. - CoreEvents.on(CoreEvents.SESSION_EXPIRED, (data) => { - CoreLoginHelper.sessionExpired(data); - }); - - // Listen for passwordchange and usernotfullysetup events to open InAppBrowser. - CoreEvents.on(CoreEvents.PASSWORD_CHANGE_FORCED, (data) => { - CoreLoginHelper.passwordChangeForced(data.siteId!); - }); - CoreEvents.on(CoreEvents.USER_NOT_FULLY_SETUP, (data) => { - CoreUserHelper.openCompleteProfile(data.siteId!); - }); - - // Listen for sitepolicynotagreed event to accept the site policy. - CoreEvents.on(CoreEvents.SITE_POLICY_NOT_AGREED, (data) => { - CoreLoginHelper.sitePolicyNotAgreed(data.siteId); - }); - // Check URLs loaded in any InAppBrowser. CoreEvents.on(CoreEvents.IAB_LOAD_START, (event) => { // URLs with a custom scheme can be prefixed with "http://" or "https://", we need to remove this. @@ -280,6 +254,9 @@ export class AppComponent implements OnInit, AfterViewInit { CoreApp.closeApp(); }); }); + + // @todo: Pause Youtube videos in Android when app is put in background or screen is locked? + // See: https://github.com/moodlehq/moodleapp/blob/ionic3/src/app/app.component.ts#L312 } /** diff --git a/src/core/features/login/login.module.ts b/src/core/features/login/login.module.ts index fdbb39639..47102a5bf 100644 --- a/src/core/features/login/login.module.ts +++ b/src/core/features/login/login.module.ts @@ -16,10 +16,11 @@ import { APP_INITIALIZER, NgModule } from '@angular/core'; import { Routes } from '@angular/router'; import { AppRoutingModule } from '@/app/app-routing.module'; -import { CoreLoginHelperProvider } from './services/login-helper'; +import { CoreLoginHelper, CoreLoginHelperProvider } from './services/login-helper'; import { CoreRedirectGuard } from '@guards/redirect'; import { CoreLoginCronHandler } from './services/handlers/cron'; import { CoreCronDelegate } from '@services/cron'; +import { CoreEvents } from '@singletons/events'; export const CORE_LOGIN_SERVICES = [ CoreLoginHelperProvider, @@ -44,6 +45,18 @@ const appRoutes: Routes = [ multi: true, useValue: () => { CoreCronDelegate.register(CoreLoginCronHandler.instance); + + CoreEvents.on(CoreEvents.SESSION_EXPIRED, (data) => { + CoreLoginHelper.sessionExpired(data); + }); + + CoreEvents.on(CoreEvents.PASSWORD_CHANGE_FORCED, (data) => { + CoreLoginHelper.passwordChangeForced(data.siteId); + }); + + CoreEvents.on(CoreEvents.SITE_POLICY_NOT_AGREED, (data) => { + CoreLoginHelper.sitePolicyNotAgreed(data.siteId); + }); }, }, ], diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index f12480039..d56be6fb1 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -784,10 +784,12 @@ export class CoreLoginHelperProvider { /** * Function that should be called when password change is forced. Reserved for core use. * - * @param siteId The site ID. + * @param siteId The site ID. Undefined for current site. */ - async passwordChangeForced(siteId: string): Promise { + async passwordChangeForced(siteId?: string): Promise { const currentSite = CoreSites.getCurrentSite(); + siteId = siteId ?? currentSite?.getId(); + if (!currentSite || siteId !== currentSite.getId()) { return; // Site that triggered the event is not current site. } diff --git a/src/core/features/user/services/user-helper.ts b/src/core/features/user/services/user-helper.ts index 5e3779eb5..3448fac48 100644 --- a/src/core/features/user/services/user-helper.ts +++ b/src/core/features/user/services/user-helper.ts @@ -65,10 +65,12 @@ export class CoreUserHelperProvider { /** * Open a page with instructions on how to complete profile. * - * @param siteId The site ID. + * @param siteId The site ID. Undefined for current site. */ - async openCompleteProfile(siteId: string): Promise { + async openCompleteProfile(siteId?: string): Promise { const currentSite = CoreSites.getCurrentSite(); + siteId = siteId ?? currentSite?.getId(); + if (!currentSite || siteId !== currentSite.getId()) { return; // Site that triggered the event is not current site. } diff --git a/src/core/features/user/user.module.ts b/src/core/features/user/user.module.ts index c5816dabe..d231658db 100644 --- a/src/core/features/user/user.module.ts +++ b/src/core/features/user/user.module.ts @@ -32,13 +32,14 @@ import { CoreCourseOptionsDelegate } from '@features/course/services/course-opti import { CoreUserCourseOptionHandler } from './services/handlers/course-option'; import { CoreUserProfileFieldDelegateService } from './services/user-profile-field-delegate'; import { CoreUserProvider } from './services/user'; -import { CoreUserHelperProvider } from './services/user-helper'; +import { CoreUserHelper, CoreUserHelperProvider } from './services/user-helper'; import { CoreUserOfflineProvider } from './services/user-offline'; import { CoreUserSyncProvider } from './services/user-sync'; import { AppRoutingModule, conditionalRoutes } from '@/app/app-routing.module'; import { CoreScreen } from '@services/screen'; import { COURSE_PAGE_NAME } from '@features/course/course.module'; import { COURSE_INDEX_PATH } from '@features/course/course-lazy.module'; +import { CoreEvents } from '@singletons/events'; export const CORE_USER_SERVICES: Type[] = [ CoreUserDelegateService, @@ -106,6 +107,10 @@ const courseIndexRoutes: Routes = [ CoreCronDelegate.register(CoreUserSyncCronHandler.instance); CoreTagAreaDelegate.registerHandler(CoreUserTagAreaHandler.instance); CoreCourseOptionsDelegate.registerHandler(CoreUserCourseOptionHandler.instance); + + CoreEvents.on(CoreEvents.USER_NOT_FULLY_SETUP, (data) => { + CoreUserHelper.openCompleteProfile(data.siteId); + }); }, }, ],