-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhockeyapp.android.ts
53 lines (41 loc) · 1.56 KB
/
hockeyapp.android.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
import * as application from 'application';
import { Android, getInstance } from "./hockeyapp.common";
declare var net: any;
class HockeyAppAndroidPlugin implements Android {
private initDone = false;
constructor() { }
init(): void {
if (this.initDone) {
console.log("HockeyAppAndroidPlugin already initialized");
return;
}
if (!application.android) {
return;
}
try {
if (!net.hockeyapp.android.metrics.MetricsManager.getInstance()) {
net.hockeyapp.android.metrics.MetricsManager.register(application.android.nativeApp);
}
application.android.on(application.AndroidApplication.activityResumedEvent, activityEventData => {
net.hockeyapp.android.CrashManager.register(activityEventData.activity);
});
this.initDone = true;
} catch (e) {
console.error('Error during init of HockeyApp', e);
}
}
trackEvent(eventName: string): void {
if (!net.hockeyapp.android.metrics.MetricsManager.getInstance()) {
console.warn("Metrics manager is not initialized, event won't be tracked");
return;
}
if (!eventName || !/^[a-zA-Z0-9_. -]+$/.test(eventName)) {
console.warn("Invalid event name, it may not appear in HockeyApp");
}
net.hockeyapp.android.metrics.MetricsManager.trackEvent(eventName);
}
}
/**
* Create new singleton instance
*/
export const HockeyApp: Android = getInstance(HockeyAppAndroidPlugin);