mirror of https://github.com/BTCPrivate/copay.git
add platform provider
This commit is contained in:
parent
de5e2a43dc
commit
58de171bb7
|
@ -21,12 +21,13 @@
|
|||
"@angular/http": "4.1.3",
|
||||
"@angular/platform-browser": "4.1.3",
|
||||
"@angular/platform-browser-dynamic": "4.1.3",
|
||||
"@angular/tsc-wrapped": "^4.3.2",
|
||||
"@ionic-native/core": "3.12.1",
|
||||
"@ionic-native/splash-screen": "3.12.1",
|
||||
"@ionic-native/status-bar": "3.12.1",
|
||||
"@ionic/storage": "2.0.1",
|
||||
"@nsalaun/ng-logger": "^2.0.1",
|
||||
"@types/lodash": "^4.14.71",
|
||||
"autoprefixer": "^7.1.2",
|
||||
"ionic-angular": "3.5.3",
|
||||
"ionicons": "3.0.0",
|
||||
"lodash": "^4.17.4",
|
||||
|
@ -42,7 +43,9 @@
|
|||
"@ionic/app-scripts": "2.0.2",
|
||||
"@ionic/cli-plugin-cordova": "1.5.0",
|
||||
"@ionic/cli-plugin-ionic-angular": "1.4.0",
|
||||
"@types/chrome": "0.0.47",
|
||||
"@types/jasmine": "^2.5.53",
|
||||
"@types/lodash": "^4.14.71",
|
||||
"@types/node": "^8.0.17",
|
||||
"codecov": "^2.2.0",
|
||||
"ionic": "3.6.0",
|
||||
|
|
|
@ -22,6 +22,7 @@ import { SplashScreen } from '@ionic-native/splash-screen';
|
|||
import { WalletProvider } from '../providers/wallet-provider/wallet-provider';
|
||||
import { StorageProvider } from '../providers/storage-provider/storage-provider';
|
||||
import { AppProvider } from '../providers/app-provider/app-provider';
|
||||
import { PlatformProvider } from '../providers/platform/platform';
|
||||
|
||||
// Set different log level depending on environment.
|
||||
const LOG_LEVEL = Level.LOG;
|
||||
|
@ -63,7 +64,8 @@ if (isDevMode()){
|
|||
{provide: ErrorHandler, useClass: IonicErrorHandler},
|
||||
WalletProvider,
|
||||
StorageProvider,
|
||||
AppProvider
|
||||
AppProvider,
|
||||
PlatformProvider
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Platform } from 'ionic-angular';
|
||||
import { Logger } from '@nsalaun/ng-logger';
|
||||
|
||||
@Injectable()
|
||||
export class PlatformProvider {
|
||||
isAndroid: boolean;
|
||||
isIOS: boolean;
|
||||
isWP: boolean;
|
||||
isSafari: boolean;
|
||||
isCordova: boolean;
|
||||
isNW: boolean;
|
||||
ua: string;
|
||||
isMobile: boolean;
|
||||
isChromeApp: boolean;
|
||||
isDevel: boolean;
|
||||
supportsLedger: boolean;
|
||||
supportsTrezor: boolean;
|
||||
versionIntelTEE: string;
|
||||
supportsIntelTEE: boolean;
|
||||
|
||||
constructor(private platform: Platform, private log: Logger) {
|
||||
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+\)$/, '');
|
||||
|
||||
this.isAndroid = platform.is('android');
|
||||
this.isIOS = platform.is('ios');
|
||||
this.isWP = platform.is('windows') && platform.is('mobile');
|
||||
this.ua = ua;
|
||||
this.isCordova = platform.is('cordova');
|
||||
this.isNW = this.isNodeWebkit();
|
||||
this.isMobile = platform.is('mobile');
|
||||
this.isChromeApp = this.getBrowserName() == 'chrome' && chrome && chrome.runtime && chrome.runtime.id && !this.isNW;
|
||||
this.isDevel = !this.isMobile && !this.isChromeApp && !this.isNW;
|
||||
this.supportsLedger = this.isChromeApp;
|
||||
this.supportsTrezor = this.isChromeApp || this.isDevel;
|
||||
this.versionIntelTEE = this.getVersionIntelTee();
|
||||
this.supportsIntelTEE = this.versionIntelTEE.length > 0;
|
||||
}
|
||||
|
||||
getBrowserName(): string {
|
||||
let userAgent = window.navigator.userAgent;
|
||||
let browsers = { chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i };
|
||||
|
||||
for (let key in browsers) {
|
||||
if (browsers[key].test(userAgent)) {
|
||||
return key;
|
||||
}
|
||||
};
|
||||
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
isNodeWebkit(): boolean {
|
||||
let isNode = (typeof process !== "undefined" && typeof require !== "undefined");
|
||||
if (isNode) {
|
||||
try {
|
||||
return (typeof require('nw.gui') !== "undefined");
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getVersionIntelTee(): string {
|
||||
let v = '';
|
||||
let isWindows = navigator.platform.indexOf('Win') > -1;
|
||||
|
||||
if (!this.isNodeWebkit() || !isWindows) {
|
||||
return v;
|
||||
}
|
||||
|
||||
try {
|
||||
var IntelWallet = require('intelWalletCon');
|
||||
if (IntelWallet.getVersion) {
|
||||
v = IntelWallet.getVersion();
|
||||
} else {
|
||||
v = 'Alpha';
|
||||
}
|
||||
if (v.length > 0) {
|
||||
this.log.info('Intel TEE library ' + v);
|
||||
}
|
||||
} catch (e) { }
|
||||
return v;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
import { LocalStorage } from './local-storage';
|
||||
|
||||
describe('Local Storage', () => {
|
||||
it('should do nothing', () => {
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
it('should get', () => {
|
||||
var storage = new LocalStorage();
|
||||
expect(storage.get('myKey')).toEqual('myKey');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
import { PlatformProvider } from '../platform/platform';
|
||||
import { Logger } from '@nsalaun/ng-logger';
|
||||
|
||||
export class LocalStorage {
|
||||
constructor(private platform: PlatformProvider, private log: Logger) {
|
||||
}
|
||||
}
|
|
@ -4,8 +4,4 @@ describe('Storage Service', () => {
|
|||
it('should do nothing', () => {
|
||||
expect(true).toBeTruthy();
|
||||
});
|
||||
it('should get', () => {
|
||||
var storage = new StorageProvider();
|
||||
expect(storage.get('myKey')).toEqual('myKey');
|
||||
});
|
||||
});
|
|
@ -1,13 +1,10 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Platform } from 'ionic-angular';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class StorageProvider {
|
||||
|
||||
constructor() {
|
||||
console.log('Hello StorageService Provider');
|
||||
}
|
||||
|
||||
public get(key:string):string {
|
||||
return key;
|
||||
storage:
|
||||
constructor(public platform: Platform) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,5 +22,9 @@
|
|||
"compileOnSave": false,
|
||||
"atom": {
|
||||
"rewriteTsconfig": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"types": [
|
||||
"chrome",
|
||||
"lodash"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue