mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 05:58:26 +08:00
fix(angula): platform logic belongs to core
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user