From ba0501b07171adb607a7e0b5ef61c50bc1f00d6c Mon Sep 17 00:00:00 2001 From: Joshua Estrin Skrzypek Date: Mon, 8 Jun 2015 18:01:04 +0300 Subject: [PATCH] feat(app): Decouple from ionic.Platform Closes #12 --- README.md | 2 +- ionic-core.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0638f59..1291c15 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -ionic-service-common +ionic-service-core ==================== Common required service tools and addons diff --git a/ionic-core.js b/ionic-core.js index 13e4b2f..cf16233 100644 --- a/ionic-core.js +++ b/ionic-core.js @@ -301,7 +301,7 @@ function($q, $timeout, $http, persistentStorage, $ionicApp) { var storageKeyName = 'ionic_analytics_user_' + $ionicApp.getApp().app_id, user = persistentStorage.retrieveObject(storageKeyName) || {}, - deviceCordova = ionic.Platform.device(), + deviceCordova = window.device || {}, device = { screen_width: window.innerWidth * (window.devicePixelRatio || 1), screen_height: window.innerHeight * (window.devicePixelRatio || 1) @@ -312,9 +312,10 @@ function($q, $timeout, $http, persistentStorage, $ionicApp) { if (deviceCordova.version) device.version = deviceCordova.version; if (deviceCordova.uuid) device.uuid = deviceCordova.uuid; + // Flag if we've changed anything on our user var dirty = false; - dirty = storeOrDirty('is_on_device', ionic.Platform.isWebView()); + dirty = storeOrDirty('is_on_device', isWebView()); dirty = storeOrDirty('device', device); if (!user._id) { user._id = generateGuid(); @@ -325,6 +326,11 @@ function($q, $timeout, $http, persistentStorage, $ionicApp) { persistentStorage.storeObject(storageKeyName, user); } + function isWebView() { + // using logic from ionic.Platform.isWebView() + return !(!window.cordova && !window.PhoneGap && !window.phonegap && !window.forge); + } + function generateGuid() { // Some crazy bit-twiddling to generate a random guid return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {