fix(angula): platform logic belongs to core

This commit is contained in:
Manu Mtz.-Almeida
2018-05-14 13:20:03 +02:00
parent d177087225
commit af5db2fb02
2 changed files with 49 additions and 48 deletions

View File

@ -1,53 +1,12 @@
import { EventEmitter, Injectable } from '@angular/core';
import { proxyEvent } from '../util/util';
import { isAndroid, isCordova, isElectron, isIOS, isIpad, isIphone, isPhablet, isTablet } from '@ionic/core';
export interface PlatformConfig {
name: string;
isMatch: (win: Window) => boolean;
}
export const PLATFORM_CONFIGS: PlatformConfig[] = [
{
name: 'ipad',
isMatch: isIpad
},
{
name: 'iphone',
isMatch: isIphone
},
{
name: 'ios',
isMatch: isIOS
},
{
name: 'android',
isMatch: isAndroid
},
{
name: 'phablet',
isMatch: isPhablet
},
{
name: 'tablet',
isMatch: isTablet
},
{
name: 'cordova',
isMatch: isCordova
},
{
name: 'electron',
isMatch: isElectron
}
];
import { PlatformConfig, detectPlatforms } from '@ionic/core';
@Injectable()
export class Platform {
private _platforms: PlatformConfig[] = PLATFORM_CONFIGS;
private _platforms = detectPlatforms(window);
private _readyPromise: Promise<string>;
/**
@ -88,11 +47,9 @@ export class Platform {
this._readyPromise = new Promise(res => { readyResolve = res; } );
if ((window as any)['cordova']) {
window.addEventListener('deviceready', () => {
this._platforms = this.detectPlatforms(window, this._platforms);
readyResolve('cordova');
}, {once: true});
} else {
this._platforms = this.detectPlatforms(window, this._platforms);
readyResolve('dom');
}
}
@ -151,9 +108,8 @@ export class Platform {
* Detects the platforms using window and the platforms config provided.
* Populates the platforms array so they can be used later on for platform detection.
*/
detectPlatforms(win: Window, platforms: PlatformConfig[]) {
// bracket notation to ensure they're not property renamed
return platforms.filter(p => p.isMatch(win));
detectPlatforms(platforms: PlatformConfig[]) {
return detectPlatforms(window, platforms);
}
/**