Skip to content

Commit a93667c

Browse files
authored
Merge pull request #2523 from crazyserver/MOBILE-3532
Mobile 3532
2 parents bee1e42 + c69d108 commit a93667c

File tree

5 files changed

+105
-64
lines changed

5 files changed

+105
-64
lines changed

src/app/app.component.ts

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
import { Component, OnInit, NgZone } from '@angular/core';
16-
import { Platform, IonicApp } from 'ionic-angular';
16+
import { Config, Platform, IonicApp } from 'ionic-angular';
1717
import { Network } from '@ionic-native/network';
1818
import { CoreApp, CoreAppProvider } from '@providers/app';
1919
import { CoreEventsProvider } from '@providers/events';
@@ -28,6 +28,7 @@ import { Keyboard } from '@ionic-native/keyboard';
2828
import { ScreenOrientation } from '@ionic-native/screen-orientation';
2929
import { CoreLoginSitesPage } from '@core/login/pages/sites/sites';
3030
import { CoreWindow } from '@singletons/window';
31+
import { Device } from '@ionic-native/device';
3132

3233
@Component({
3334
templateUrl: 'app.html'
@@ -40,13 +41,62 @@ export class MoodleMobileApp implements OnInit {
4041
protected lastUrls = {};
4142
protected lastInAppUrl: string;
4243

43-
constructor(private platform: Platform, logger: CoreLoggerProvider, keyboard: Keyboard, private app: IonicApp,
44-
private eventsProvider: CoreEventsProvider, private loginHelper: CoreLoginHelperProvider, private zone: NgZone,
45-
private appProvider: CoreAppProvider, private langProvider: CoreLangProvider, private sitesProvider: CoreSitesProvider,
46-
private screenOrientation: ScreenOrientation, private urlSchemesProvider: CoreCustomURLSchemesProvider,
47-
private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider, private network: Network) {
44+
constructor(
45+
private platform: Platform,
46+
logger: CoreLoggerProvider,
47+
keyboard: Keyboard,
48+
config: Config,
49+
device: Device,
50+
private app: IonicApp,
51+
private eventsProvider: CoreEventsProvider,
52+
private loginHelper: CoreLoginHelperProvider,
53+
private zone: NgZone,
54+
private appProvider: CoreAppProvider,
55+
private langProvider: CoreLangProvider,
56+
private sitesProvider: CoreSitesProvider,
57+
private screenOrientation: ScreenOrientation,
58+
private urlSchemesProvider: CoreCustomURLSchemesProvider,
59+
private utils: CoreUtilsProvider,
60+
private urlUtils: CoreUrlUtilsProvider,
61+
private network: Network
62+
) {
4863
this.logger = logger.getInstance('AppComponent');
4964

65+
if (this.appProvider.isIOS() && !platform.is('ios')) {
66+
// Solve problem with wrong detected iPadOS.
67+
const platforms = platform.platforms();
68+
const index = platforms.indexOf('core');
69+
if (index > -1) {
70+
platforms.splice(index, 1);
71+
}
72+
platforms.push('mobile');
73+
platforms.push('ios');
74+
platforms.push('ipad');
75+
platforms.push('tablet');
76+
77+
app.setElementClass('app-root-ios', true);
78+
platform.ready().then(() => {
79+
if (device.version) {
80+
const [major, minor]: string[] = device.version.split('.', 2);
81+
app.setElementClass('platform-ios' + major, true);
82+
app.setElementClass('platform-ios' + major + '_' + minor, true);
83+
}
84+
});
85+
86+
app._elementRef.nativeElement.classList.remove('app-root-md');
87+
88+
const iosConfig = config.getModeConfig('ios');
89+
90+
config.set('mode', 'ios');
91+
92+
Object.keys(iosConfig).forEach((key) => {
93+
// Already overriden: pageTransition, do not change.
94+
if (key != 'pageTransition') {
95+
config.set('ios', key, iosConfig[key]);
96+
}
97+
});
98+
}
99+
50100
platform.ready().then(() => {
51101
// Okay, so the platform is ready and our plugins are available.
52102
// Here you can do any higher level native things you might need.

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)