Wallet/src/js/services/platformInfo.js
2017-04-11 10:02:14 -04:00

44 lines
1.2 KiB
JavaScript

'use strict';
angular.module('copayApp.services').factory('platformInfo', function($window) {
var ua = navigator ? navigator.userAgent : null;
if (!ua) {
console.log('Could not determine navigator. Using fixed string');
ua = 'dummy user-agent';
}
// Fixes IOS WebKit UA
ua = ua.replace(/\(\d+\)$/, '');
var isNodeWebkit = function() {
var isNode = (typeof process !== "undefined" && typeof require !== "undefined");
if (isNode) {
try {
return (typeof require('nw.gui') !== "undefined");
} catch (e) {
return false;
}
}
};
// Detect mobile devices
var ret = {
isAndroid: ionic.Platform.isAndroid(),
isIOS: ionic.Platform.isIOS(),
isWP: ionic.Platform.isWindowsPhone() || ionic.Platform.platform() == 'edge',
isSafari: Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0,
ua: ua,
isCordova: !!$window.cordova,
isNW: isNodeWebkit(),
};
ret.isMobile = ret.isAndroid || ret.isIOS || ret.isWP;
ret.isChromeApp = $window.chrome && chrome.runtime && chrome.runtime.id && !ret.isNW;
ret.isDevel = !ret.isMobile && !ret.isChromeApp && !ret.isNW;
ret.isIntelTEE = true;
return ret;
});