forked from bitpay/wallet
/
app.ts
121 lines (109 loc) · 3.15 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { File } from '@ionic-native/file';
// providers
import { ConfigProvider } from '../../providers/config/config';
import { LanguageProvider } from '../../providers/language/language';
import { Logger } from '../../providers/logger/logger';
import { PersistenceProvider } from '../../providers/persistence/persistence';
import { PlatformProvider } from '../platform/platform';
/* TODO: implement interface properly
interface App {
packageName: string;
packageDescription: string;
packageNameId: string;
themeColor: string;
userVisibleName: string;
purposeLine: string;
bundleName: string;
appUri: string;
name: string;
nameNoSpace: string;
nameCase: string;
nameCaseNoSpace: string;
gitHubRepoName: string;
gitHubRepoUrl: string;
gitHubRepoBugs: string;
disclaimerUrl: string;
url: string;
appDescription: string;
winAppName: string;
WindowsStoreIdentityName: string;
WindowsStoreDisplayName: string;
windowsAppId: string;
pushSenderId: string;
description: string;
version: string;
androidVersion: string;
commitHash: string;
_extraCSS: string;
_enabledExtensions;
}*/
@Injectable()
export class AppProvider {
public info: any = {};
public servicesInfo;
public isLockModalOpen: boolean;
private jsonPathApp: string = 'assets/appConfig.json';
private jsonPathServices: string = 'assets/externalServices.json';
private appTheme: BehaviorSubject<string>;
constructor(
public http: HttpClient,
private logger: Logger,
private language: LanguageProvider,
public config: ConfigProvider,
private persistence: PersistenceProvider,
private file: File,
private platformProvider: PlatformProvider
) {
this.logger.debug('AppProvider initialized');
}
public async load() {
await Promise.all([this.getInfo(), this.loadProviders()]);
}
private async getInfo() {
[this.servicesInfo, this.info] = await Promise.all([
this.getServicesInfo(),
this.getAppInfo()
]);
if (this.platformProvider.isCordova) {
this.info = JSON.parse(this.info);
this.servicesInfo = JSON.parse(this.servicesInfo);
}
}
private async loadProviders() {
this.persistence.load();
await this.config.load();
await this.persistence.getAppTheme().then(value => {
this.appTheme = new BehaviorSubject(value);
});
this.language.load();
}
private getAppInfo() {
if (this.platformProvider.isCordova) {
return this.file.readAsText(
this.file.applicationDirectory + 'www/',
this.jsonPathApp
);
} else {
return this.http.get(this.jsonPathApp).toPromise();
}
}
private getServicesInfo() {
if (this.platformProvider.isCordova) {
return this.file.readAsText(
this.file.applicationDirectory + 'www/',
this.jsonPathServices
);
} else {
return this.http.get(this.jsonPathServices).toPromise();
}
}
public setActiveTheme(val) {
this.appTheme.next(val);
}
public getActiveTheme() {
return this.appTheme.asObservable();
}
}