forked from CIT/Vmeda.Online
		
	MOBILE-2282 login: Call getPublicConfig in background when loading site
This commit is contained in:
		
							parent
							
								
									d1dcd71e74
								
							
						
					
					
						commit
						7d06bb5285
					
				@ -532,10 +532,8 @@ export class CoreNavigatorService {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const pathRoot = /^[^/]+/.exec(path)?.[0] ?? '';
 | 
					        const pathRoot = /^[^/]+/.exec(path)?.[0] ?? '';
 | 
				
			||||||
        const currentMainMenuTab = this.getCurrentMainMenuTab();
 | 
					        const currentMainMenuTab = this.getCurrentMainMenuTab();
 | 
				
			||||||
        const isMainMenuTab = await CoreUtils.ignoreErrors(
 | 
					        const isMainMenuTab = pathRoot === currentMainMenuTab || (!currentMainMenuTab && path === DEFAULT_MAIN_MENU_TAB) ||
 | 
				
			||||||
            CoreMainMenu.isMainMenuTab(pathRoot),
 | 
					            await CoreUtils.ignoreErrors(CoreMainMenu.isMainMenuTab(pathRoot), false);
 | 
				
			||||||
            false,
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!options.preferCurrentTab && isMainMenuTab) {
 | 
					        if (!options.preferCurrentTab && isMainMenuTab) {
 | 
				
			||||||
            return this.navigate(`/main/${path}`, options);
 | 
					            return this.navigate(`/main/${path}`, options);
 | 
				
			||||||
 | 
				
			|||||||
@ -713,10 +713,11 @@ export class CoreSitesProvider {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            const siteId = this.getCurrentSiteId();
 | 
					            const siteId = this.getCurrentSiteId();
 | 
				
			||||||
            const downloadUrl = CoreApp.getAppStoreUrl(storesConfig);
 | 
					            const downloadUrl = CoreApp.getAppStoreUrl(storesConfig);
 | 
				
			||||||
 | 
					            let promise: Promise<unknown>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (downloadUrl != null) {
 | 
					            if (downloadUrl != null) {
 | 
				
			||||||
                // Do not block interface.
 | 
					                // Do not block interface.
 | 
				
			||||||
                CoreDomUtils.showConfirm(
 | 
					                promise = CoreDomUtils.showConfirm(
 | 
				
			||||||
                    Translate.instant('core.updaterequireddesc', { $a: config.tool_mobile_minimumversion }),
 | 
					                    Translate.instant('core.updaterequireddesc', { $a: config.tool_mobile_minimumversion }),
 | 
				
			||||||
                    Translate.instant('core.updaterequired'),
 | 
					                    Translate.instant('core.updaterequired'),
 | 
				
			||||||
                    Translate.instant('core.download'),
 | 
					                    Translate.instant('core.download'),
 | 
				
			||||||
@ -725,19 +726,20 @@ export class CoreSitesProvider {
 | 
				
			|||||||
                    // Do nothing.
 | 
					                    // Do nothing.
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                CoreDomUtils.showAlert(
 | 
					                // Do not block interface.
 | 
				
			||||||
 | 
					                promise = CoreDomUtils.showAlert(
 | 
				
			||||||
                    Translate.instant('core.updaterequired'),
 | 
					                    Translate.instant('core.updaterequired'),
 | 
				
			||||||
                    Translate.instant('core.updaterequireddesc', { $a: config.tool_mobile_minimumversion }),
 | 
					                    Translate.instant('core.updaterequireddesc', { $a: config.tool_mobile_minimumversion }),
 | 
				
			||||||
                );
 | 
					                ).then((alert) => alert.onWillDismiss());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (siteId) {
 | 
					            promise.finally(() => {
 | 
				
			||||||
                // Logout the currentSite.
 | 
					                if (siteId) {
 | 
				
			||||||
                await this.logout();
 | 
					                    // Logout the currentSite and expire the token.
 | 
				
			||||||
 | 
					                    this.logout();
 | 
				
			||||||
                // Always expire the token.
 | 
					                    this.setSiteLoggedOut(siteId, true);
 | 
				
			||||||
                await this.setSiteLoggedOut(siteId, true);
 | 
					                }
 | 
				
			||||||
            }
 | 
					            });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            throw new CoreError('Current app version is lower than required version.');
 | 
					            throw new CoreError('Current app version is lower than required version.');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -794,24 +796,27 @@ export class CoreSitesProvider {
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let config: CoreSitePublicConfigResponse | undefined;
 | 
					        this.login(siteId);
 | 
				
			||||||
 | 
					        // Get some data in background, don't block the UI.
 | 
				
			||||||
 | 
					        this.getPublicConfigAndCheckApplication(site);
 | 
				
			||||||
 | 
					        this.updateSiteInfo(siteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        return true;
 | 
				
			||||||
            config = await site.getPublicConfig();
 | 
					    }
 | 
				
			||||||
        } catch (error) {
 | 
					 | 
				
			||||||
            // Error getting config, maybe the user is offline.
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Get site public config and check if app can access the site.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param site Site.
 | 
				
			||||||
 | 
					     * @return Promise resolved when done.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    protected async getPublicConfigAndCheckApplication(site: CoreSite): Promise<void> {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            const config = await site.getPublicConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await this.checkApplication(config);
 | 
					            await this.checkApplication(config);
 | 
				
			||||||
 | 
					        } catch {
 | 
				
			||||||
            this.login(siteId);
 | 
					            // Ignore errors, maybe the user is offline.
 | 
				
			||||||
            // Update site info. We don't block the UI.
 | 
					 | 
				
			||||||
            this.updateSiteInfo(siteId);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            return true;
 | 
					 | 
				
			||||||
        } catch (error) {
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user