MOBILE-2333 redirect: Check if there are site plugins loaded

main
Dani Palou 2018-03-09 14:52:55 +01:00
parent 046b300051
commit db3fb84547
4 changed files with 23 additions and 15 deletions

View File

@ -27,6 +27,7 @@ import { CoreLoginHelperProvider } from '../../login/providers/helper';
import { CoreContentLinksDelegate, CoreContentLinksAction } from './delegate';
import { CoreConstants } from '../../constants';
import { CoreConfigConstants } from '../../../configconstants';
import { CoreSitePluginsProvider } from '../../siteplugins/providers/siteplugins';
/**
* Service that provides some features regarding content links.
@ -38,7 +39,8 @@ export class CoreContentLinksHelperProvider {
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
private contentLinksDelegate: CoreContentLinksDelegate, private appProvider: CoreAppProvider,
private domUtils: CoreDomUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private translate: TranslateService,
private initDelegate: CoreInitDelegate, eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider) {
private initDelegate: CoreInitDelegate, eventsProvider: CoreEventsProvider, private textUtils: CoreTextUtilsProvider,
private sitePluginsProvider: CoreSitePluginsProvider) {
this.logger = logger.getInstance('CoreContentLinksHelperProvider');
// Listen for app launched URLs. If we receive one, check if it's a content link.
@ -144,7 +146,6 @@ export class CoreContentLinksHelperProvider {
return this.sitesProvider.checkSite(siteUrl).then((result) => {
// Site exists. We'll allow to add it.
const ssoNeeded = this.loginHelper.isSSOLoginNeeded(result.code),
hasRemoteAddonsLoaded = false,
pageName = 'CoreLoginCredentialsPage',
pageParams = {
siteUrl: result.siteUrl,
@ -152,7 +153,8 @@ export class CoreContentLinksHelperProvider {
urlToOpen: url,
siteConfig: result.config
};
let promise;
let promise,
hasSitePluginsLoaded = false;
modal.dismiss(); // Dismiss modal so it doesn't collide with confirms.
@ -164,8 +166,8 @@ export class CoreContentLinksHelperProvider {
const confirmMsg = this.translate.instant('core.contentlinks.confirmurlothersite');
promise = this.domUtils.showConfirm(confirmMsg).then(() => {
if (!ssoNeeded) {
// @todo hasRemoteAddonsLoaded = $mmAddonManager.hasRemoteAddonsLoaded(); @todo
if (hasRemoteAddonsLoaded) {
hasSitePluginsLoaded = this.sitePluginsProvider.hasSitePluginsLoaded;
if (hasSitePluginsLoaded) {
// Store the redirect since logout will restart the app.
this.appProvider.storeRedirect(CoreConstants.NO_SITE_ID, pageName, pageParams);
}
@ -181,7 +183,7 @@ export class CoreContentLinksHelperProvider {
if (ssoNeeded) {
this.loginHelper.confirmAndOpenBrowserForSSOLogin(
result.siteUrl, result.code, result.service, result.config && result.config.launchurl);
} else if (!hasRemoteAddonsLoaded) {
} else if (!hasSitePluginsLoaded) {
this.appProvider.getRootNavController().setRoot(pageName, pageParams);
}
});

View File

@ -26,8 +26,9 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreUrlUtilsProvider } from '@providers/utils/url';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins';
import { CoreConfigConstants } from '../../../configconstants';
import { CoreConstants } from '../../constants';
import { CoreConstants } from '@core/constants';
import { Md5 } from 'ts-md5/dist/md5';
/**
@ -80,7 +81,7 @@ export class CoreLoginHelperProvider {
private wsProvider: CoreWSProvider, private translate: TranslateService, private textUtils: CoreTextUtilsProvider,
private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider,
private urlUtils: CoreUrlUtilsProvider, private configProvider: CoreConfigProvider, private platform: Platform,
private initDelegate: CoreInitDelegate) {
private initDelegate: CoreInitDelegate, private sitePluginsProvider: CoreSitePluginsProvider) {
this.logger = logger.getInstance('CoreLoginHelper');
}
@ -768,10 +769,15 @@ export class CoreLoginHelperProvider {
if (this.sitesProvider.isLoggedIn()) {
if (siteId && siteId != this.sitesProvider.getCurrentSiteId()) {
// Target page belongs to a different site. Change site.
// @todo Store redirect once we have addon manager.
this.sitesProvider.logout().then(() => {
this.loadSiteAndPage(page, params, siteId);
});
if (this.sitePluginsProvider.hasSitePluginsLoaded) {
// The site has site plugins so the app will be restarted. Store the data and logout.
this.appProvider.storeRedirect(siteId, page, params);
this.sitesProvider.logout();
} else {
this.sitesProvider.logout().then(() => {
this.loadSiteAndPage(page, params, siteId);
});
}
} else {
this.loadPageInMainMenu(page, params);
}

View File

@ -52,7 +52,6 @@ import { CoreSitePluginsUserProfileFieldHandler } from '../classes/user-profile-
@Injectable()
export class CoreSitePluginsHelperProvider {
protected logger;
protected hasSitePluginsLoaded = false;
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private injector: Injector,
private mainMenuDelegate: CoreMainMenuDelegate, private moduleDelegate: CoreCourseModuleDelegate,
@ -80,7 +79,7 @@ export class CoreSitePluginsHelperProvider {
// Unload plugins on logout if any.
eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
if (this.hasSitePluginsLoaded) {
if (this.sitePluginsProvider.hasSitePluginsLoaded) {
// Temporary fix. Reload the page to unload all plugins.
window.location.reload();
}
@ -251,7 +250,7 @@ export class CoreSitePluginsHelperProvider {
plugin.parsedHandlers = JSON.parse(plugin.handlers);
}
this.hasSitePluginsLoaded = true;
this.sitePluginsProvider.hasSitePluginsLoaded = true;
// Register all the handlers.
for (const name in plugin.parsedHandlers) {

View File

@ -62,6 +62,7 @@ export class CoreSitePluginsProvider {
protected logger;
protected sitePlugins: {[name: string]: CoreSitePluginsHandler} = {}; // Site plugins registered.
hasSitePluginsLoaded = false;
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider,
private langProvider: CoreLangProvider, private appProvider: CoreAppProvider, private platform: Platform,