From af5db2fb023ea0763b9a4e26ce2040ee62b4d4e4 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Mon, 14 May 2018 13:20:03 +0200 Subject: [PATCH] fix(angula): platform logic belongs to core --- angular/src/providers/platform.ts | 52 +++---------------------------- core/src/utils/platform.ts | 45 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/angular/src/providers/platform.ts b/angular/src/providers/platform.ts index e840fa0d7e..7e5574b2bc 100644 --- a/angular/src/providers/platform.ts +++ b/angular/src/providers/platform.ts @@ -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; /** @@ -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); } /** diff --git a/core/src/utils/platform.ts b/core/src/utils/platform.ts index 44cf206c61..123da26ff9 100644 --- a/core/src/utils/platform.ts +++ b/core/src/utils/platform.ts @@ -70,3 +70,48 @@ export function matchMedia(win: Window, query: string, fallback = false): boolea ? win.matchMedia(query).matches : fallback; } + +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 + } +]; + +export function detectPlatforms(win: Window, platforms: PlatformConfig[] = PLATFORM_CONFIGS) { + // bracket notation to ensure they're not property renamed + return platforms.filter(p => p.isMatch(win)); +}