diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 275daf547..63fade7ba 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -175,7 +175,7 @@ export class AppComponent implements OnInit, AfterViewInit { this.lastInAppUrl = ''; if (CoreLoginHelper.isWaitingForBrowser()) { - CoreLoginHelper.setWaitingForBrowser(false); + CoreLoginHelper.stopWaitingForBrowser(); CoreLoginHelper.checkLogout(); } }); @@ -184,7 +184,7 @@ export class AppComponent implements OnInit, AfterViewInit { // Wait a second before setting it to false since in iOS there could be some frozen WS calls. setTimeout(() => { if (CoreLoginHelper.isWaitingForBrowser()) { - CoreLoginHelper.setWaitingForBrowser(false); + CoreLoginHelper.stopWaitingForBrowser(); CoreLoginHelper.checkLogout(); } }, 1000); diff --git a/src/core/classes/delegate.ts b/src/core/classes/delegate.ts index 588f0ce9f..3651bcc67 100644 --- a/src/core/classes/delegate.ts +++ b/src/core/classes/delegate.ts @@ -103,6 +103,11 @@ export class CoreDelegate { this.updateHandlers(); } }); + CoreEvents.on(CoreEvents.COMPLETE_REQUIRED_PROFILE_DATA_FINISHED, (data) => { + if (data.siteId === CoreSites.getCurrentSiteId()) { + this.updateHandlers(); + } + }); } } diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index fb14d6eea..108cff604 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -37,6 +37,7 @@ import { CoreCanceledError } from '@classes/errors/cancelederror'; import { CoreCustomURLSchemes } from '@services/urlschemes'; import { CorePushNotifications } from '@features/pushnotifications/services/pushnotifications'; import { CoreText } from '@singletons/text'; +import { CorePromisedValue } from '@classes/promised-value'; /** * Helper provider that provides some common features regarding authentication. @@ -56,7 +57,7 @@ export class CoreLoginHelperProvider { protected logger: CoreLogger; protected sessionExpiredCheckingSite: Record = {}; protected isOpenEditAlertShown = false; - protected waitingForBrowser = false; + protected waitingForBrowser?: CorePromisedValue; constructor() { this.logger = CoreLogger.getInstance('CoreLoginHelper'); @@ -768,11 +769,15 @@ export class CoreLoginHelperProvider { try { await currentSite.openInAppWithAutoLogin(siteUrl + path, undefined, alertMessage); - - this.waitingForBrowser = true; } finally { this.isOpenEditAlertShown = false; } + + await this.waitForBrowser(); + + CoreEvents.trigger(CoreEvents.COMPLETE_REQUIRED_PROFILE_DATA_FINISHED, { + path, + }, siteId); } } @@ -917,7 +922,7 @@ export class CoreLoginHelperProvider { (currentSite.isLoggedOut() ? 'loggedoutssodescription' : 'reconnectssodescription'))); } - this.waitingForBrowser = true; + this.waitForBrowser(); this.openBrowserForSSOLogin( result.siteUrl, @@ -950,7 +955,7 @@ export class CoreLoginHelperProvider { try { await CoreDomUtils.showConfirm(confirmMessage); - this.waitingForBrowser = true; + this.waitForBrowser(); CoreSites.unsetCurrentSite(); // Unset current site to make authentication work fine. this.openBrowserForOAuthLogin( @@ -1223,16 +1228,28 @@ export class CoreLoginHelperProvider { * @return Whether the app is waiting for browser. */ isWaitingForBrowser(): boolean { - return this.waitingForBrowser; + return !!this.waitingForBrowser; } /** - * Set whether the app is waiting for browser. + * Start waiting when opening a browser/IAB. * - * @param value New value. + * @return Promise resolved when the app is resumed. */ - setWaitingForBrowser(value: boolean): void { - this.waitingForBrowser = value; + async waitForBrowser(): Promise { + if (!this.waitingForBrowser) { + this.waitingForBrowser = new CorePromisedValue(); + } + + await this.waitingForBrowser; + } + + /** + * Stop waiting for browser. + */ + stopWaitingForBrowser(): void { + this.waitingForBrowser?.resolve(); + this.waitingForBrowser = undefined; } /** diff --git a/src/core/singletons/events.ts b/src/core/singletons/events.ts index 9f303efa7..35f3968b2 100644 --- a/src/core/singletons/events.ts +++ b/src/core/singletons/events.ts @@ -61,6 +61,7 @@ export interface CoreEventsData { [CoreEvents.APP_LAUNCHED_URL]: CoreEventAppLaunchedData; [CoreEvents.ORIENTATION_CHANGE]: CoreEventOrientationData; [CoreEvents.COURSE_MODULE_VIEWED]: CoreEventCourseModuleViewed; + [CoreEvents.COMPLETE_REQUIRED_PROFILE_DATA_FINISHED]: CoreEventCompleteRequiredProfileDataFinished; } /* @@ -115,6 +116,7 @@ export class CoreEvents { static readonly ACTIVITY_DATA_SENT = 'activity_data_sent'; static readonly DEVICE_REGISTERED_IN_MOODLE = 'device_registered_in_moodle'; static readonly COURSE_MODULE_VIEWED = 'course_module_viewed'; + static readonly COMPLETE_REQUIRED_PROFILE_DATA_FINISHED = 'complete_required_profile_data_finished'; protected static logger = CoreLogger.getInstance('CoreEvents'); protected static observables: { [eventName: string]: Subject } = {}; @@ -467,3 +469,10 @@ export type CoreEventCourseModuleViewed = { timeaccess: number; sectionId?: number; }; + +/** + * Data passed to COMPLETE_REQUIRED_PROFILE_DATA_FINISHED event. + */ +export type CoreEventCompleteRequiredProfileDataFinished = { + path: string; +}; diff --git a/upgrade.txt b/upgrade.txt index 2ee2fb749..b146617fb 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -25,7 +25,7 @@ information provided here is intended especially for developers. - The variable "loaded" in CoreCourseModuleMainResourceComponent has been changed to "showLoading" to reflect its purpose better. - The function getCurrentSection of course formats can now return a forceSelected boolean along with the section (defaults to false if not returned). - The link handlers functions (CoreContentLinksHandler) will now always receive a relative URL instead of an absolute URL. The CoreContentLinksHandlerBase class now adds "^" to the start of the pattern by default to prevent false positives. - +- The function CoreLoginHelper.setWaitingForBrowser has been removed, use CoreLoginHelper.waitForBrowser and CoreLoginHelper.stopWaitingForBrowser instead. === 3.9.5 ===