MOBILE-2333 redirect: Check if there are site plugins loaded
parent
046b300051
commit
db3fb84547
|
@ -27,6 +27,7 @@ import { CoreLoginHelperProvider } from '../../login/providers/helper';
|
||||||
import { CoreContentLinksDelegate, CoreContentLinksAction } from './delegate';
|
import { CoreContentLinksDelegate, CoreContentLinksAction } from './delegate';
|
||||||
import { CoreConstants } from '../../constants';
|
import { CoreConstants } from '../../constants';
|
||||||
import { CoreConfigConstants } from '../../../configconstants';
|
import { CoreConfigConstants } from '../../../configconstants';
|
||||||
|
import { CoreSitePluginsProvider } from '../../siteplugins/providers/siteplugins';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service that provides some features regarding content links.
|
* Service that provides some features regarding content links.
|
||||||
|
@ -38,7 +39,8 @@ export class CoreContentLinksHelperProvider {
|
||||||
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
|
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider,
|
||||||
private contentLinksDelegate: CoreContentLinksDelegate, private appProvider: CoreAppProvider,
|
private contentLinksDelegate: CoreContentLinksDelegate, private appProvider: CoreAppProvider,
|
||||||
private domUtils: CoreDomUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private translate: TranslateService,
|
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');
|
this.logger = logger.getInstance('CoreContentLinksHelperProvider');
|
||||||
|
|
||||||
// Listen for app launched URLs. If we receive one, check if it's a content link.
|
// 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) => {
|
return this.sitesProvider.checkSite(siteUrl).then((result) => {
|
||||||
// Site exists. We'll allow to add it.
|
// Site exists. We'll allow to add it.
|
||||||
const ssoNeeded = this.loginHelper.isSSOLoginNeeded(result.code),
|
const ssoNeeded = this.loginHelper.isSSOLoginNeeded(result.code),
|
||||||
hasRemoteAddonsLoaded = false,
|
|
||||||
pageName = 'CoreLoginCredentialsPage',
|
pageName = 'CoreLoginCredentialsPage',
|
||||||
pageParams = {
|
pageParams = {
|
||||||
siteUrl: result.siteUrl,
|
siteUrl: result.siteUrl,
|
||||||
|
@ -152,7 +153,8 @@ export class CoreContentLinksHelperProvider {
|
||||||
urlToOpen: url,
|
urlToOpen: url,
|
||||||
siteConfig: result.config
|
siteConfig: result.config
|
||||||
};
|
};
|
||||||
let promise;
|
let promise,
|
||||||
|
hasSitePluginsLoaded = false;
|
||||||
|
|
||||||
modal.dismiss(); // Dismiss modal so it doesn't collide with confirms.
|
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');
|
const confirmMsg = this.translate.instant('core.contentlinks.confirmurlothersite');
|
||||||
promise = this.domUtils.showConfirm(confirmMsg).then(() => {
|
promise = this.domUtils.showConfirm(confirmMsg).then(() => {
|
||||||
if (!ssoNeeded) {
|
if (!ssoNeeded) {
|
||||||
// @todo hasRemoteAddonsLoaded = $mmAddonManager.hasRemoteAddonsLoaded(); @todo
|
hasSitePluginsLoaded = this.sitePluginsProvider.hasSitePluginsLoaded;
|
||||||
if (hasRemoteAddonsLoaded) {
|
if (hasSitePluginsLoaded) {
|
||||||
// Store the redirect since logout will restart the app.
|
// Store the redirect since logout will restart the app.
|
||||||
this.appProvider.storeRedirect(CoreConstants.NO_SITE_ID, pageName, pageParams);
|
this.appProvider.storeRedirect(CoreConstants.NO_SITE_ID, pageName, pageParams);
|
||||||
}
|
}
|
||||||
|
@ -181,7 +183,7 @@ export class CoreContentLinksHelperProvider {
|
||||||
if (ssoNeeded) {
|
if (ssoNeeded) {
|
||||||
this.loginHelper.confirmAndOpenBrowserForSSOLogin(
|
this.loginHelper.confirmAndOpenBrowserForSSOLogin(
|
||||||
result.siteUrl, result.code, result.service, result.config && result.config.launchurl);
|
result.siteUrl, result.code, result.service, result.config && result.config.launchurl);
|
||||||
} else if (!hasRemoteAddonsLoaded) {
|
} else if (!hasSitePluginsLoaded) {
|
||||||
this.appProvider.getRootNavController().setRoot(pageName, pageParams);
|
this.appProvider.getRootNavController().setRoot(pageName, pageParams);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,8 +26,9 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||||
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
||||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||||
|
import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins';
|
||||||
import { CoreConfigConstants } from '../../../configconstants';
|
import { CoreConfigConstants } from '../../../configconstants';
|
||||||
import { CoreConstants } from '../../constants';
|
import { CoreConstants } from '@core/constants';
|
||||||
import { Md5 } from 'ts-md5/dist/md5';
|
import { Md5 } from 'ts-md5/dist/md5';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +81,7 @@ export class CoreLoginHelperProvider {
|
||||||
private wsProvider: CoreWSProvider, private translate: TranslateService, private textUtils: CoreTextUtilsProvider,
|
private wsProvider: CoreWSProvider, private translate: TranslateService, private textUtils: CoreTextUtilsProvider,
|
||||||
private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider,
|
private eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider,
|
||||||
private urlUtils: CoreUrlUtilsProvider, private configProvider: CoreConfigProvider, private platform: Platform,
|
private urlUtils: CoreUrlUtilsProvider, private configProvider: CoreConfigProvider, private platform: Platform,
|
||||||
private initDelegate: CoreInitDelegate) {
|
private initDelegate: CoreInitDelegate, private sitePluginsProvider: CoreSitePluginsProvider) {
|
||||||
this.logger = logger.getInstance('CoreLoginHelper');
|
this.logger = logger.getInstance('CoreLoginHelper');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -768,10 +769,15 @@ export class CoreLoginHelperProvider {
|
||||||
if (this.sitesProvider.isLoggedIn()) {
|
if (this.sitesProvider.isLoggedIn()) {
|
||||||
if (siteId && siteId != this.sitesProvider.getCurrentSiteId()) {
|
if (siteId && siteId != this.sitesProvider.getCurrentSiteId()) {
|
||||||
// Target page belongs to a different site. Change site.
|
// Target page belongs to a different site. Change site.
|
||||||
// @todo Store redirect once we have addon manager.
|
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.sitesProvider.logout().then(() => {
|
||||||
this.loadSiteAndPage(page, params, siteId);
|
this.loadSiteAndPage(page, params, siteId);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.loadPageInMainMenu(page, params);
|
this.loadPageInMainMenu(page, params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ import { CoreSitePluginsUserProfileFieldHandler } from '../classes/user-profile-
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CoreSitePluginsHelperProvider {
|
export class CoreSitePluginsHelperProvider {
|
||||||
protected logger;
|
protected logger;
|
||||||
protected hasSitePluginsLoaded = false;
|
|
||||||
|
|
||||||
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private injector: Injector,
|
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private injector: Injector,
|
||||||
private mainMenuDelegate: CoreMainMenuDelegate, private moduleDelegate: CoreCourseModuleDelegate,
|
private mainMenuDelegate: CoreMainMenuDelegate, private moduleDelegate: CoreCourseModuleDelegate,
|
||||||
|
@ -80,7 +79,7 @@ export class CoreSitePluginsHelperProvider {
|
||||||
|
|
||||||
// Unload plugins on logout if any.
|
// Unload plugins on logout if any.
|
||||||
eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
|
eventsProvider.on(CoreEventsProvider.LOGOUT, () => {
|
||||||
if (this.hasSitePluginsLoaded) {
|
if (this.sitePluginsProvider.hasSitePluginsLoaded) {
|
||||||
// Temporary fix. Reload the page to unload all plugins.
|
// Temporary fix. Reload the page to unload all plugins.
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
@ -251,7 +250,7 @@ export class CoreSitePluginsHelperProvider {
|
||||||
plugin.parsedHandlers = JSON.parse(plugin.handlers);
|
plugin.parsedHandlers = JSON.parse(plugin.handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hasSitePluginsLoaded = true;
|
this.sitePluginsProvider.hasSitePluginsLoaded = true;
|
||||||
|
|
||||||
// Register all the handlers.
|
// Register all the handlers.
|
||||||
for (const name in plugin.parsedHandlers) {
|
for (const name in plugin.parsedHandlers) {
|
||||||
|
|
|
@ -62,6 +62,7 @@ export class CoreSitePluginsProvider {
|
||||||
|
|
||||||
protected logger;
|
protected logger;
|
||||||
protected sitePlugins: {[name: string]: CoreSitePluginsHandler} = {}; // Site plugins registered.
|
protected sitePlugins: {[name: string]: CoreSitePluginsHandler} = {}; // Site plugins registered.
|
||||||
|
hasSitePluginsLoaded = false;
|
||||||
|
|
||||||
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider,
|
constructor(logger: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider,
|
||||||
private langProvider: CoreLangProvider, private appProvider: CoreAppProvider, private platform: Platform,
|
private langProvider: CoreLangProvider, private appProvider: CoreAppProvider, private platform: Platform,
|
||||||
|
|
Loading…
Reference in New Issue