2016-05-31 10:45:59 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2016-05-31 14:55:08 -03:00
|
|
|
angular.module('copayApp.services').factory('platformInfo', function($window) {
|
2016-05-31 10:45:59 -03:00
|
|
|
|
2016-05-31 14:55:08 -03:00
|
|
|
var ua = navigator ? navigator.userAgent : null;
|
|
|
|
|
|
|
|
|
|
if (!ua) {
|
|
|
|
|
console.log('Could not determine navigator. Using a random string');
|
|
|
|
|
ua = Math.floor(Math.random() * 100000);
|
|
|
|
|
}
|
2016-05-31 10:45:59 -03:00
|
|
|
|
|
|
|
|
var isNodeWebkit = function() {
|
|
|
|
|
var isNode = (typeof process !== "undefined" && typeof require !== "undefined");
|
2016-05-31 14:55:08 -03:00
|
|
|
if (isNode) {
|
2016-05-31 10:45:59 -03:00
|
|
|
try {
|
|
|
|
|
return (typeof require('nw.gui') !== "undefined");
|
2016-05-31 14:55:08 -03:00
|
|
|
} catch (e) {
|
2016-05-31 10:45:59 -03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Detect mobile devices
|
|
|
|
|
var ret = {
|
|
|
|
|
isAndroid: function() {
|
|
|
|
|
return !!ua.match(/Android/i);
|
|
|
|
|
},
|
|
|
|
|
isIOS: function() {
|
|
|
|
|
return /iPad|iPhone|iPod/.test(ua) && !$window.MSStream;
|
|
|
|
|
},
|
|
|
|
|
isWP: function() {
|
|
|
|
|
return !!ua.match(/IEMobile/i);
|
|
|
|
|
},
|
2016-05-31 14:55:08 -03:00
|
|
|
isSafari: function() {
|
2016-05-31 10:45:59 -03:00
|
|
|
return Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-05-31 14:55:08 -03:00
|
|
|
ret.ua = ua;
|
2016-05-31 10:45:59 -03:00
|
|
|
ret.isMobile = ret.isAndroid() || ret.isIOS() || ret.isWP();
|
|
|
|
|
ret.isCordova = !!$window.cordova;
|
|
|
|
|
ret.isNW = isNodeWebkit();
|
2016-05-31 14:55:08 -03:00
|
|
|
ret.isChromeApp = $window.chrome && chrome.runtime && chrome.runtime.id && !ret.isNW;
|
|
|
|
|
ret.isDevel = !ret.isMobile && !ret.isChromeApp && !ret.isNW;
|
2016-05-31 10:45:59 -03:00
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
});
|