From dbae55bff29b475992791a5e07aeac773dcc8e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Tue, 15 Sep 2020 14:36:06 +0200 Subject: [PATCH] MOBILE-3532 ionic: Half Revert Fix check device during loading This reverts commit 8844abd857cbbc4ea182bcd83ef21e34d71aa292. --- src/core/sharedfiles/sharedfiles.module.ts | 50 +++++++++++----------- src/providers/app.ts | 10 ++--- src/providers/file.ts | 41 ++++++++---------- src/providers/utils/iframe.ts | 8 ++-- 4 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/core/sharedfiles/sharedfiles.module.ts b/src/core/sharedfiles/sharedfiles.module.ts index 185a9a5bf..c31accbad 100644 --- a/src/core/sharedfiles/sharedfiles.module.ts +++ b/src/core/sharedfiles/sharedfiles.module.ts @@ -49,33 +49,31 @@ export class CoreSharedFilesModule { // Register the handler. delegate.registerHandler(handler); - platform.ready().then(() => { - if (appsProvider.isIOS()) { - let lastCheck = 0; + 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; - } - - 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); + // 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); + } + }); + } } } diff --git a/src/providers/app.ts b/src/providers/app.ts index 02c1279ae..206528dc7 100644 --- a/src/providers/app.ts +++ b/src/providers/app.ts @@ -17,7 +17,6 @@ import { Platform, App, NavController, MenuController } from 'ionic-angular'; import { Keyboard } from '@ionic-native/keyboard'; import { Network } from '@ionic-native/network'; import { StatusBar } from '@ionic-native/status-bar'; -import { Device } from '@ionic-native/device'; import { CoreDbProvider } from './db'; import { CoreLoggerProvider } from './logger'; @@ -179,7 +178,6 @@ export class CoreAppProvider { zone: NgZone, private menuCtrl: MenuController, private statusBar: StatusBar, - private device: Device, appRef: ApplicationRef) { this.logger = logger.getInstance('CoreAppProvider'); @@ -392,8 +390,7 @@ export class CoreAppProvider { * @return Whether the app is running in an Android mobile or tablet device. */ isAndroid(): boolean { - return this.isMobile() && - ((this.device.platform && this.device.platform.toLowerCase() == 'android') || this.platform.is('android')); + return this.isMobile() && this.platform.is('android'); } /** @@ -413,8 +410,7 @@ export class CoreAppProvider { * @return Whether the app is running in an iOS mobile or tablet device. */ isIOS(): boolean { - return this.isMobile() && - ((this.device.platform && this.device.platform.toLowerCase() == 'ios') || this.platform.is('ios')); + return this.isMobile() && !this.platform.is('android'); } /** @@ -572,7 +568,7 @@ export class CoreAppProvider { */ openKeyboard(): void { // Open keyboard is not supported in desktop and in iOS. - if (this.isMobile() && !this.isIOS()) { + if (this.isAndroid()) { this.keyboard.show(); } } diff --git a/src/providers/file.ts b/src/providers/file.ts index d0a86cc78..98df61923 100644 --- a/src/providers/file.ts +++ b/src/providers/file.ts @@ -81,31 +81,28 @@ export class CoreFileProvider { this.logger = logger.getInstance('CoreFileProvider'); - 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; - }); + 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'); + } } /** diff --git a/src/providers/utils/iframe.ts b/src/providers/utils/iframe.ts index efcbda6b7..fc9d3afb9 100644 --- a/src/providers/utils/iframe.ts +++ b/src/providers/utils/iframe.ts @@ -57,8 +57,8 @@ export class CoreIframeUtilsProvider { const win = window; - platform.ready().then(() => { - if (appProvider.isIOS() && win.WKUserScript) { + if (appProvider.isIOS() && win.WKUserScript) { + platform.ready().then(() => { // 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'); @@ -73,8 +73,8 @@ export class CoreIframeUtilsProvider { // Handle post messages received by iframes. window.addEventListener('message', this.handleIframeMessage.bind(this)); - } - }); + }); + } } /**