|
1 | 1 |
|
2 | 2 | import { EventEmitter, Injectable } from '@angular/core';
|
3 | 3 | import { proxyEvent } from '../util/util';
|
4 |
| -import { isAndroid, isCordova, isElectron, isIOS, isIpad, isIphone, isPhablet, isTablet } from '@ionic/core'; |
5 |
| - |
6 |
| -export interface PlatformConfig { |
7 |
| - name: string; |
8 |
| - isMatch: (win: Window) => boolean; |
9 |
| -} |
10 |
| - |
11 |
| -export const PLATFORM_CONFIGS: PlatformConfig[] = [ |
12 |
| - { |
13 |
| - name: 'ipad', |
14 |
| - isMatch: isIpad |
15 |
| - }, |
16 |
| - { |
17 |
| - name: 'iphone', |
18 |
| - isMatch: isIphone |
19 |
| - }, |
20 |
| - { |
21 |
| - name: 'ios', |
22 |
| - isMatch: isIOS |
23 |
| - }, |
24 |
| - { |
25 |
| - name: 'android', |
26 |
| - isMatch: isAndroid |
27 |
| - }, |
28 |
| - { |
29 |
| - name: 'phablet', |
30 |
| - isMatch: isPhablet |
31 |
| - }, |
32 |
| - { |
33 |
| - name: 'tablet', |
34 |
| - isMatch: isTablet |
35 |
| - }, |
36 |
| - { |
37 |
| - name: 'cordova', |
38 |
| - isMatch: isCordova |
39 |
| - }, |
40 |
| - { |
41 |
| - name: 'electron', |
42 |
| - isMatch: isElectron |
43 |
| - } |
44 |
| - |
45 |
| -]; |
| 4 | +import { PlatformConfig, detectPlatforms } from '@ionic/core'; |
46 | 5 |
|
47 | 6 | @Injectable()
|
48 | 7 | export class Platform {
|
49 | 8 |
|
50 |
| - private _platforms: PlatformConfig[] = PLATFORM_CONFIGS; |
| 9 | + private _platforms = detectPlatforms(window); |
51 | 10 | private _readyPromise: Promise<string>;
|
52 | 11 |
|
53 | 12 | /**
|
@@ -88,11 +47,9 @@ export class Platform {
|
88 | 47 | this._readyPromise = new Promise(res => { readyResolve = res; } );
|
89 | 48 | if ((window as any)['cordova']) {
|
90 | 49 | window.addEventListener('deviceready', () => {
|
91 |
| - this._platforms = this.detectPlatforms(window, this._platforms); |
92 | 50 | readyResolve('cordova');
|
93 | 51 | }, {once: true});
|
94 | 52 | } else {
|
95 |
| - this._platforms = this.detectPlatforms(window, this._platforms); |
96 | 53 | readyResolve('dom');
|
97 | 54 | }
|
98 | 55 | }
|
@@ -151,9 +108,8 @@ export class Platform {
|
151 | 108 | * Detects the platforms using window and the platforms config provided.
|
152 | 109 | * Populates the platforms array so they can be used later on for platform detection.
|
153 | 110 | */
|
154 |
| - detectPlatforms(win: Window, platforms: PlatformConfig[]) { |
155 |
| - // bracket notation to ensure they're not property renamed |
156 |
| - return platforms.filter(p => p.isMatch(win)); |
| 111 | + detectPlatforms(platforms: PlatformConfig[]) { |
| 112 | + return detectPlatforms(window, platforms); |
157 | 113 | }
|
158 | 114 |
|
159 | 115 | /**
|
|
0 commit comments