Skip to content

Commit dbae55b

Browse files
committed
MOBILE-3532 ionic: Half Revert Fix check device during loading
This reverts commit 8844abd.
1 parent bee1e42 commit dbae55b

File tree

4 files changed

+49
-58
lines changed

4 files changed

+49
-58
lines changed

src/core/sharedfiles/sharedfiles.module.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,31 @@ export class CoreSharedFilesModule {
4949
// Register the handler.
5050
delegate.registerHandler(handler);
5151

52-
platform.ready().then(() => {
53-
if (appsProvider.isIOS()) {
54-
let lastCheck = 0;
52+
if (appsProvider.isIOS()) {
53+
let lastCheck = 0;
5554

56-
// Check if there are new files at app start and when the app is resumed.
57-
helper.searchIOSNewSharedFiles();
58-
platform.resume.subscribe(() => {
59-
// Wait a bit to make sure that APP_LAUNCHED_URL is treated before this callback.
60-
setTimeout(() => {
61-
if (Date.now() - lastCheck < 1000) {
62-
// Last check less than 1s ago, don't do anything.
63-
return;
64-
}
55+
// Check if there are new files at app start and when the app is resumed.
56+
helper.searchIOSNewSharedFiles();
57+
platform.resume.subscribe(() => {
58+
// Wait a bit to make sure that APP_LAUNCHED_URL is treated before this callback.
59+
setTimeout(() => {
60+
if (Date.now() - lastCheck < 1000) {
61+
// Last check less than 1s ago, don't do anything.
62+
return;
63+
}
6564

66-
lastCheck = Date.now();
67-
helper.searchIOSNewSharedFiles();
68-
}, 200);
69-
});
65+
lastCheck = Date.now();
66+
helper.searchIOSNewSharedFiles();
67+
}, 200);
68+
});
7069

71-
eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, (url) => {
72-
if (url && url.indexOf('file://') === 0) {
73-
// We received a file in iOS, it's probably a shared file. Treat it.
74-
lastCheck = Date.now();
75-
helper.searchIOSNewSharedFiles(url);
76-
}
77-
});
78-
}
79-
});
70+
eventsProvider.on(CoreEventsProvider.APP_LAUNCHED_URL, (url) => {
71+
if (url && url.indexOf('file://') === 0) {
72+
// We received a file in iOS, it's probably a shared file. Treat it.
73+
lastCheck = Date.now();
74+
helper.searchIOSNewSharedFiles(url);
75+
}
76+
});
77+
}
8078
}
8179
}

src/providers/app.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { Platform, App, NavController, MenuController } from 'ionic-angular';
1717
import { Keyboard } from '@ionic-native/keyboard';
1818
import { Network } from '@ionic-native/network';
1919
import { StatusBar } from '@ionic-native/status-bar';
20-
import { Device } from '@ionic-native/device';
2120

2221
import { CoreDbProvider } from './db';
2322
import { CoreLoggerProvider } from './logger';
@@ -179,7 +178,6 @@ export class CoreAppProvider {
179178
zone: NgZone,
180179
private menuCtrl: MenuController,
181180
private statusBar: StatusBar,
182-
private device: Device,
183181
appRef: ApplicationRef) {
184182

185183
this.logger = logger.getInstance('CoreAppProvider');
@@ -392,8 +390,7 @@ export class CoreAppProvider {
392390
* @return Whether the app is running in an Android mobile or tablet device.
393391
*/
394392
isAndroid(): boolean {
395-
return this.isMobile() &&
396-
((this.device.platform && this.device.platform.toLowerCase() == 'android') || this.platform.is('android'));
393+
return this.isMobile() && this.platform.is('android');
397394
}
398395

399396
/**
@@ -413,8 +410,7 @@ export class CoreAppProvider {
413410
* @return Whether the app is running in an iOS mobile or tablet device.
414411
*/
415412
isIOS(): boolean {
416-
return this.isMobile() &&
417-
((this.device.platform && this.device.platform.toLowerCase() == 'ios') || this.platform.is('ios'));
413+
return this.isMobile() && !this.platform.is('android');
418414
}
419415

420416
/**
@@ -572,7 +568,7 @@ export class CoreAppProvider {
572568
*/
573569
openKeyboard(): void {
574570
// Open keyboard is not supported in desktop and in iOS.
575-
if (this.isMobile() && !this.isIOS()) {
571+
if (this.isAndroid()) {
576572
this.keyboard.show();
577573
}
578574
}

src/providers/file.ts

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,31 +81,28 @@ export class CoreFileProvider {
8181

8282
this.logger = logger.getInstance('CoreFileProvider');
8383

84-
platform.ready().then(() => {
85-
if (appProvider.isAndroid() && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) {
86-
// Cordova File plugin creates some getters and setter for FileReader, but
87-
// Ionic's polyfills override them in Android.
88-
// Create the getters and setters again. This code comes from FileReader.js in cordova-plugin-file.
89-
this.defineGetterSetter(FileReader.prototype, 'readyState', function(): any {
90-
return this._localURL ? this._readyState : this._realReader.readyState;
91-
});
84+
if (appProvider.isAndroid() && !Object.getOwnPropertyDescriptor(FileReader.prototype, 'onloadend')) {
85+
// Cordova File plugin creates some getters and setter for FileReader, but Ionic's polyfills override them in Android.
86+
// Create the getters and setters again. This code comes from FileReader.js in cordova-plugin-file.
87+
this.defineGetterSetter(FileReader.prototype, 'readyState', function(): any {
88+
return this._localURL ? this._readyState : this._realReader.readyState;
89+
});
9290

93-
this.defineGetterSetter(FileReader.prototype, 'error', function(): any {
94-
return this._localURL ? this._error : this._realReader.error;
95-
});
91+
this.defineGetterSetter(FileReader.prototype, 'error', function(): any {
92+
return this._localURL ? this._error : this._realReader.error;
93+
});
9694

97-
this.defineGetterSetter(FileReader.prototype, 'result', function(): any {
98-
return this._localURL ? this._result : this._realReader.result;
99-
});
95+
this.defineGetterSetter(FileReader.prototype, 'result', function(): any {
96+
return this._localURL ? this._result : this._realReader.result;
97+
});
10098

101-
this.defineEvent('onloadstart');
102-
this.defineEvent('onprogress');
103-
this.defineEvent('onload');
104-
this.defineEvent('onerror');
105-
this.defineEvent('onloadend');
106-
this.defineEvent('onabort');
107-
}
108-
});
99+
this.defineEvent('onloadstart');
100+
this.defineEvent('onprogress');
101+
this.defineEvent('onload');
102+
this.defineEvent('onerror');
103+
this.defineEvent('onloadend');
104+
this.defineEvent('onabort');
105+
}
109106
}
110107

111108
/**

src/providers/utils/iframe.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export class CoreIframeUtilsProvider {
5757

5858
const win = <WKUserScriptWindow> window;
5959

60-
platform.ready().then(() => {
61-
if (appProvider.isIOS() && win.WKUserScript) {
60+
if (appProvider.isIOS() && win.WKUserScript) {
61+
platform.ready().then(() => {
6262
// Inject code to the iframes because we cannot access the online ones.
6363
const wwwPath = fileProvider.getWWWAbsolutePath();
6464
const linksPath = textUtils.concatenatePaths(wwwPath, 'assets/js/iframe-treat-links.js');
@@ -73,8 +73,8 @@ export class CoreIframeUtilsProvider {
7373

7474
// Handle post messages received by iframes.
7575
window.addEventListener('message', this.handleIframeMessage.bind(this));
76-
}
77-
});
76+
});
77+
}
7878
}
7979

8080
/**

0 commit comments

Comments
 (0)