forked from CIT/Vmeda.Online
		
	Merge pull request #2521 from crazyserver/MOBILE-3534
MOBILE-3534 ionic: Fix check device during loading
This commit is contained in:
		
						commit
						37b0447cfe
					
				@ -49,31 +49,33 @@ export class CoreSharedFilesModule {
 | 
			
		||||
        // Register the handler.
 | 
			
		||||
        delegate.registerHandler(handler);
 | 
			
		||||
 | 
			
		||||
        if (appsProvider.isIOS()) {
 | 
			
		||||
            let lastCheck = 0;
 | 
			
		||||
        platform.ready().then(() => {
 | 
			
		||||
            if (appsProvider.isIOS()) {
 | 
			
		||||
                let lastCheck = 0;
 | 
			
		||||
 | 
			
		||||
            // Check if there are new files at app start and when the app is resumed.
 | 
			
		||||
            helper.searchIOSNewSharedFiles();
 | 
			
		||||
            platform.resume.subscribe(() => {
 | 
			
		||||
                // Wait a bit to make sure that APP_LAUNCHED_URL is treated before this callback.
 | 
			
		||||
                setTimeout(() => {
 | 
			
		||||
                    if (Date.now() - lastCheck < 1000) {
 | 
			
		||||
                        // Last check less than 1s ago, don't do anything.
 | 
			
		||||
                        return;
 | 
			
		||||
                // Check if there are new files at app start and when the app is resumed.
 | 
			
		||||
                helper.searchIOSNewSharedFiles();
 | 
			
		||||
                platform.resume.subscribe(() => {
 | 
			
		||||
                    // Wait a bit to make sure that APP_LAUNCHED_URL is treated before this callback.
 | 
			
		||||
                    setTimeout(() => {
 | 
			
		||||
                        if (Date.now() - lastCheck < 1000) {
 | 
			
		||||
                            // Last check less than 1s ago, don't do anything.
 | 
			
		||||
                            return;
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        lastCheck = Date.now();
 | 
			
		||||
                        helper.searchIOSNewSharedFiles();
 | 
			
		||||
                    }, 200);
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, (url) => {
 | 
			
		||||
                    if (url && url.indexOf('file://') === 0) {
 | 
			
		||||
                        // We received a file in iOS, it's probably a shared file. Treat it.
 | 
			
		||||
                        lastCheck = Date.now();
 | 
			
		||||
                        helper.searchIOSNewSharedFiles(url);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    lastCheck = Date.now();
 | 
			
		||||
                    helper.searchIOSNewSharedFiles();
 | 
			
		||||
                }, 200);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, (url) => {
 | 
			
		||||
                if (url && url.indexOf('file://') === 0) {
 | 
			
		||||
                    // We received a file in iOS, it's probably a shared file. Treat it.
 | 
			
		||||
                    lastCheck = Date.now();
 | 
			
		||||
                    helper.searchIOSNewSharedFiles(url);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -392,7 +392,8 @@ export class CoreAppProvider {
 | 
			
		||||
     * @return Whether the app is running in an Android mobile or tablet device.
 | 
			
		||||
     */
 | 
			
		||||
    isAndroid(): boolean {
 | 
			
		||||
        return this.isMobile() && this.device.platform.toLowerCase() == 'android';
 | 
			
		||||
        return this.isMobile() &&
 | 
			
		||||
            ((this.device.platform && this.device.platform.toLowerCase() == 'android') || this.platform.is('android'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -412,7 +413,8 @@ export class CoreAppProvider {
 | 
			
		||||
     * @return Whether the app is running in an iOS mobile or tablet device.
 | 
			
		||||
     */
 | 
			
		||||
    isIOS(): boolean {
 | 
			
		||||
        return this.isMobile() && this.device.platform.toLowerCase() == 'ios';
 | 
			
		||||
        return this.isMobile() &&
 | 
			
		||||
            ((this.device.platform && this.device.platform.toLowerCase() == 'ios') || this.platform.is('ios'));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -81,28 +81,31 @@ export class CoreFileProvider {
 | 
			
		||||
 | 
			
		||||
        this.logger = logger.getInstance('CoreFileProvider');
 | 
			
		||||
 | 
			
		||||
        if (appProvider.isAndroid() && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) {
 | 
			
		||||
            // Cordova File plugin creates some getters and setter for FileReader, but Ionic's polyfills override them in Android.
 | 
			
		||||
            // Create the getters and setters again. This code comes from FileReader.js in cordova-plugin-file.
 | 
			
		||||
            this.defineGetterSetter(FileReader.prototype, 'readyState', function(): any {
 | 
			
		||||
                return this._localURL ? this._readyState : this._realReader.readyState;
 | 
			
		||||
            });
 | 
			
		||||
        platform.ready().then(() => {
 | 
			
		||||
            if (appProvider.isAndroid() && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) {
 | 
			
		||||
                // Cordova File plugin creates some getters and setter for FileReader, but
 | 
			
		||||
                // Ionic's polyfills override them in Android.
 | 
			
		||||
                // Create the getters and setters again. This code comes from FileReader.js in cordova-plugin-file.
 | 
			
		||||
                this.defineGetterSetter(FileReader.prototype, 'readyState', function(): any {
 | 
			
		||||
                    return this._localURL ? this._readyState : this._realReader.readyState;
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            this.defineGetterSetter(FileReader.prototype, 'error', function(): any {
 | 
			
		||||
                return this._localURL ? this._error : this._realReader.error;
 | 
			
		||||
            });
 | 
			
		||||
                this.defineGetterSetter(FileReader.prototype, 'error', function(): any {
 | 
			
		||||
                    return this._localURL ? this._error : this._realReader.error;
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            this.defineGetterSetter(FileReader.prototype, 'result', function(): any {
 | 
			
		||||
                return this._localURL ? this._result : this._realReader.result;
 | 
			
		||||
            });
 | 
			
		||||
                this.defineGetterSetter(FileReader.prototype, 'result', function(): any {
 | 
			
		||||
                    return this._localURL ? this._result : this._realReader.result;
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
            this.defineEvent('onloadstart');
 | 
			
		||||
            this.defineEvent('onprogress');
 | 
			
		||||
            this.defineEvent('onload');
 | 
			
		||||
            this.defineEvent('onerror');
 | 
			
		||||
            this.defineEvent('onloadend');
 | 
			
		||||
            this.defineEvent('onabort');
 | 
			
		||||
        }
 | 
			
		||||
                this.defineEvent('onloadstart');
 | 
			
		||||
                this.defineEvent('onprogress');
 | 
			
		||||
                this.defineEvent('onload');
 | 
			
		||||
                this.defineEvent('onerror');
 | 
			
		||||
                this.defineEvent('onloadend');
 | 
			
		||||
                this.defineEvent('onabort');
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@ import { Injectable, NgZone } from '@angular/core';
 | 
			
		||||
import { Config, Platform, NavController } from 'ionic-angular';
 | 
			
		||||
import { TranslateService } from '@ngx-translate/core';
 | 
			
		||||
import { Network } from '@ionic-native/network';
 | 
			
		||||
import { CoreApp } from '../app';
 | 
			
		||||
import { CoreApp, CoreAppProvider } from '../app';
 | 
			
		||||
import { CoreFileProvider } from '../file';
 | 
			
		||||
import { CoreLoggerProvider } from '../logger';
 | 
			
		||||
import { CoreSitesProvider } from '../sites';
 | 
			
		||||
@ -47,6 +47,7 @@ export class CoreIframeUtilsProvider {
 | 
			
		||||
            private utils: CoreUtilsProvider,
 | 
			
		||||
            private domUtils: CoreDomUtilsProvider,
 | 
			
		||||
            platform: Platform,
 | 
			
		||||
            appProvider: CoreAppProvider,
 | 
			
		||||
            private translate: TranslateService,
 | 
			
		||||
            private network: Network, private zone: NgZone,
 | 
			
		||||
            private config: Config,
 | 
			
		||||
@ -56,8 +57,8 @@ export class CoreIframeUtilsProvider {
 | 
			
		||||
 | 
			
		||||
        const win = <WKUserScriptWindow> window;
 | 
			
		||||
 | 
			
		||||
        if (CoreApp.instance.isIOS() && win.WKUserScript) {
 | 
			
		||||
            platform.ready().then(() => {
 | 
			
		||||
        platform.ready().then(() => {
 | 
			
		||||
            if (appProvider.isIOS() && win.WKUserScript) {
 | 
			
		||||
                // Inject code to the iframes because we cannot access the online ones.
 | 
			
		||||
                const wwwPath = fileProvider.getWWWAbsolutePath();
 | 
			
		||||
                const linksPath = textUtils.concatenatePaths(wwwPath, 'assets/js/iframe-treat-links.js');
 | 
			
		||||
@ -72,8 +73,8 @@ export class CoreIframeUtilsProvider {
 | 
			
		||||
 | 
			
		||||
                // Handle post messages received by iframes.
 | 
			
		||||
                window.addEventListener('message', this.handleIframeMessage.bind(this));
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user