Merge pull request #1933 from dpalou/MOBILE-2938
MOBILE-2938 core: Fix race condition with open page in main menumain
commit
8d59445509
|
@ -78,6 +78,7 @@ export class CoreLoginHelperProvider {
|
|||
protected logger;
|
||||
protected isSSOConfirmShown = false;
|
||||
protected isOpenEditAlertShown = false;
|
||||
protected pageToLoad: {page: string, params: any, time: number}; // Page to load once main menu is opened.
|
||||
waitingForBrowser = false;
|
||||
|
||||
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private domUtils: CoreDomUtilsProvider,
|
||||
|
@ -87,6 +88,15 @@ export class CoreLoginHelperProvider {
|
|||
private initDelegate: CoreInitDelegate, private sitePluginsProvider: CoreSitePluginsProvider,
|
||||
private location: Location, private alertCtrl: AlertController, private courseProvider: CoreCourseProvider) {
|
||||
this.logger = logger.getInstance('CoreLoginHelper');
|
||||
|
||||
this.eventsProvider.on(CoreEventsProvider.MAIN_MENU_OPEN, () => {
|
||||
/* If there is any page pending to be opened, do it now. Don't open pages stored more than 5 seconds ago, probably
|
||||
the function to open the page was called when it shouldn't. */
|
||||
if (this.pageToLoad && Date.now() - this.pageToLoad.time < 5000) {
|
||||
this.loadPageInMainMenu(this.pageToLoad.page, this.pageToLoad.params);
|
||||
delete this.pageToLoad;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -620,6 +630,17 @@ export class CoreLoginHelperProvider {
|
|||
* @param {any} params Params to pass to the page.
|
||||
*/
|
||||
protected loadPageInMainMenu(page: string, params: any): void {
|
||||
if (!this.appProvider.isMainMenuOpen()) {
|
||||
// Main menu not open. Store the page to be loaded later.
|
||||
this.pageToLoad = {
|
||||
page: page,
|
||||
params: params,
|
||||
time: Date.now()
|
||||
};
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (page == CoreLoginHelperProvider.OPEN_COURSE) {
|
||||
// Use the openCourse function.
|
||||
this.courseProvider.openCourse(undefined, params.course, params);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
import { Component, OnDestroy, ViewChild, ChangeDetectorRef } from '@angular/core';
|
||||
import { IonicPage, NavController, NavParams } from 'ionic-angular';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreEventsProvider } from '@providers/events';
|
||||
import { CoreIonTabsComponent } from '@components/ion-tabs/ion-tabs';
|
||||
|
@ -43,13 +44,16 @@ export class CoreMainMenuPage implements OnDestroy {
|
|||
protected redirectObs: any;
|
||||
protected pendingRedirect: any;
|
||||
protected urlToOpen: string;
|
||||
protected mainMenuId: number;
|
||||
|
||||
@ViewChild('mainTabs') mainTabs: CoreIonTabsComponent;
|
||||
|
||||
constructor(private menuDelegate: CoreMainMenuDelegate, private sitesProvider: CoreSitesProvider, navParams: NavParams,
|
||||
private navCtrl: NavController, private eventsProvider: CoreEventsProvider, private cdr: ChangeDetectorRef,
|
||||
private mainMenuProvider: CoreMainMenuProvider, private linksDelegate: CoreContentLinksDelegate,
|
||||
private linksHelper: CoreContentLinksHelperProvider) {
|
||||
private linksHelper: CoreContentLinksHelperProvider, private appProvider: CoreAppProvider) {
|
||||
|
||||
this.mainMenuId = this.appProvider.getMainMenuId();
|
||||
|
||||
// Check if the menu was loaded with a redirect.
|
||||
const redirectPage = navParams.get('redirectPage');
|
||||
|
@ -105,6 +109,8 @@ export class CoreMainMenuPage implements OnDestroy {
|
|||
});
|
||||
|
||||
window.addEventListener('resize', this.initHandlers.bind(this));
|
||||
|
||||
this.appProvider.setMainMenuOpen(this.mainMenuId, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -211,5 +217,6 @@ export class CoreMainMenuPage implements OnDestroy {
|
|||
this.subscription && this.subscription.unsubscribe();
|
||||
this.redirectObs && this.redirectObs.off();
|
||||
window.removeEventListener('resize', this.initHandlers.bind(this));
|
||||
this.appProvider.setMainMenuOpen(this.mainMenuId, false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,9 +71,11 @@ export class CoreAppProvider {
|
|||
protected ssoAuthenticationPromise: Promise<any>;
|
||||
protected isKeyboardShown = false;
|
||||
protected backActions = [];
|
||||
protected mainMenuId = 0;
|
||||
protected mainMenuOpen: number;
|
||||
|
||||
constructor(dbProvider: CoreDbProvider, private platform: Platform, private keyboard: Keyboard, private appCtrl: App,
|
||||
private network: Network, logger: CoreLoggerProvider, events: CoreEventsProvider, zone: NgZone,
|
||||
private network: Network, logger: CoreLoggerProvider, private events: CoreEventsProvider, zone: NgZone,
|
||||
private menuCtrl: MenuController, private statusBar: StatusBar) {
|
||||
this.logger = logger.getInstance('CoreAppProvider');
|
||||
this.db = dbProvider.getDB(this.DBNAME);
|
||||
|
@ -138,6 +140,15 @@ export class CoreAppProvider {
|
|||
return this.db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an ID for a main menu.
|
||||
*
|
||||
* @return {number} Main menu ID.
|
||||
*/
|
||||
getMainMenuId(): number {
|
||||
return this.mainMenuId++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the app's root NavController.
|
||||
*
|
||||
|
@ -213,6 +224,15 @@ export class CoreAppProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the main menu is open.
|
||||
*
|
||||
* @return {boolean} Whether the main menu is open.
|
||||
*/
|
||||
isMainMenuOpen(): boolean {
|
||||
return typeof this.mainMenuOpen != 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the app is running in a mobile or tablet device (Cordova).
|
||||
*
|
||||
|
@ -299,6 +319,21 @@ export class CoreAppProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a main menu as open or not.
|
||||
*
|
||||
* @param {number} id Main menu ID.
|
||||
* @param {boolean} open Whether it's open or not.
|
||||
*/
|
||||
setMainMenuOpen(id: number, open: boolean): void {
|
||||
if (open) {
|
||||
this.mainMenuOpen = id;
|
||||
this.events.trigger(CoreEventsProvider.MAIN_MENU_OPEN);
|
||||
} else if (this.mainMenuOpen == id) {
|
||||
delete this.mainMenuOpen;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an SSO authentication process.
|
||||
* Please notice that this function should be called when the app receives the new token from the browser,
|
||||
|
|
|
@ -59,6 +59,7 @@ export class CoreEventsProvider {
|
|||
static ORIENTATION_CHANGE = 'orientation_change';
|
||||
static LOAD_PAGE_MAIN_MENU = 'load_page_main_menu';
|
||||
static SEND_ON_ENTER_CHANGED = 'send_on_enter_changed';
|
||||
static MAIN_MENU_OPEN = 'main_menu_open';
|
||||
|
||||
protected logger;
|
||||
protected observables: { [s: string]: Subject<any> } = {};
|
||||
|
|
Loading…
Reference in New Issue