@capacitor-firebase/performance 0.3.1 → 0.5.1-dev.01021f0.1659726888
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorFirebasePerformance.podspec +19 -19
- package/LICENSE +201 -201
- package/README.md +88 -88
- package/android/build.gradle +59 -60
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/{dev/robingenz → io/capawesome}/capacitorjs/plugins/firebase/performance/FirebasePerformance.java +45 -45
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/performance/FirebasePerformancePlugin.java +112 -0
- package/dist/docs.json +16 -16
- package/dist/esm/definitions.d.ts +102 -102
- package/dist/esm/definitions.js +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +6 -6
- package/dist/esm/web.d.ts +10 -10
- package/dist/esm/web.js +40 -40
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +39 -39
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +40 -40
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/FirebasePerformance.swift +46 -46
- package/ios/Plugin/FirebasePerformancePlugin.h +10 -10
- package/ios/Plugin/FirebasePerformancePlugin.m +12 -12
- package/ios/Plugin/FirebasePerformancePlugin.swift +83 -83
- package/ios/Plugin/Info.plist +24 -24
- package/package.json +95 -84
- package/android/src/main/java/dev/robingenz/capacitorjs/plugins/firebase/performance/FirebasePerformancePlugin.java +0 -92
package/README.md
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
# @capacitor-firebase/performance
|
|
2
|
-
|
|
3
|
-
⚡️ Capacitor plugin for Firebase Performance Monitoring.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @capacitor-firebase/performance firebase
|
|
9
|
-
npx cap sync
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Add Firebase to your project if you haven't already ([Android](https://firebase.google.com/docs/android/setup) / [iOS](https://firebase.google.com/docs/ios/setup) / [Web](https://firebase.google.com/docs/web/setup)).
|
|
13
|
-
|
|
14
|
-
### Android
|
|
15
|
-
|
|
16
|
-
See [Add the Performance Monitoring plugin to your app](https://firebase.google.com/docs/perf-mon/get-started-android#add-perfmon-plugin) and follow the instructions to set up your app correctly.
|
|
17
|
-
|
|
18
|
-
#### Variables
|
|
19
|
-
|
|
20
|
-
This plugin will use the following project variables (defined in your app’s `variables.gradle` file):
|
|
21
|
-
|
|
22
|
-
- `$firebasePerfVersion` version of `com.google.firebase:firebase-perf` (default: `20.0.6`)
|
|
23
|
-
|
|
24
|
-
## Configuration
|
|
25
|
-
|
|
26
|
-
No configuration required for this plugin.
|
|
27
|
-
|
|
28
|
-
## Demo
|
|
29
|
-
|
|
30
|
-
A working example can be found here: [robingenz/capacitor-firebase-plugin-demo](https://github.com/robingenz/capacitor-firebase-plugin-demo)
|
|
31
|
-
|
|
32
|
-
## Usage
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
import { FirebasePerformance } from '@capacitor-firebase/performance';
|
|
36
|
-
|
|
37
|
-
const startTrace = async () => {
|
|
38
|
-
await FirebasePerformance.startTrace({ traceName: 'test_trace' });
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const stopTrace = async () => {
|
|
42
|
-
await FirebasePerformance.stopTrace({ traceName: 'test_trace' });
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const incrementMetric = async () => {
|
|
46
|
-
await FirebasePerformance.incrementMetric({
|
|
47
|
-
traceName: 'test_trace',
|
|
48
|
-
metricName: 'item_cache_hit',
|
|
49
|
-
incrementBy: 1,
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const setPerformanceCollectionEnabled = async () => {
|
|
54
|
-
await FirebasePerformance.setPerformanceCollectionEnabled({ enabled: true });
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const isPerformanceCollectionEnabled = async () => {
|
|
58
|
-
const result = await FirebasePerformance.isPerformanceCollectionEnabled();
|
|
59
|
-
return result.enabled;
|
|
60
|
-
};
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## API
|
|
64
|
-
|
|
1
|
+
# @capacitor-firebase/performance
|
|
2
|
+
|
|
3
|
+
⚡️ Capacitor plugin for Firebase Performance Monitoring.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @capacitor-firebase/performance firebase
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Add Firebase to your project if you haven't already ([Android](https://firebase.google.com/docs/android/setup) / [iOS](https://firebase.google.com/docs/ios/setup) / [Web](https://firebase.google.com/docs/web/setup)).
|
|
13
|
+
|
|
14
|
+
### Android
|
|
15
|
+
|
|
16
|
+
See [Add the Performance Monitoring plugin to your app](https://firebase.google.com/docs/perf-mon/get-started-android#add-perfmon-plugin) and follow the instructions to set up your app correctly.
|
|
17
|
+
|
|
18
|
+
#### Variables
|
|
19
|
+
|
|
20
|
+
This plugin will use the following project variables (defined in your app’s `variables.gradle` file):
|
|
21
|
+
|
|
22
|
+
- `$firebasePerfVersion` version of `com.google.firebase:firebase-perf` (default: `20.0.6`)
|
|
23
|
+
|
|
24
|
+
## Configuration
|
|
25
|
+
|
|
26
|
+
No configuration required for this plugin.
|
|
27
|
+
|
|
28
|
+
## Demo
|
|
29
|
+
|
|
30
|
+
A working example can be found here: [robingenz/capacitor-firebase-plugin-demo](https://github.com/robingenz/capacitor-firebase-plugin-demo)
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { FirebasePerformance } from '@capacitor-firebase/performance';
|
|
36
|
+
|
|
37
|
+
const startTrace = async () => {
|
|
38
|
+
await FirebasePerformance.startTrace({ traceName: 'test_trace' });
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const stopTrace = async () => {
|
|
42
|
+
await FirebasePerformance.stopTrace({ traceName: 'test_trace' });
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const incrementMetric = async () => {
|
|
46
|
+
await FirebasePerformance.incrementMetric({
|
|
47
|
+
traceName: 'test_trace',
|
|
48
|
+
metricName: 'item_cache_hit',
|
|
49
|
+
incrementBy: 1,
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const setPerformanceCollectionEnabled = async () => {
|
|
54
|
+
await FirebasePerformance.setPerformanceCollectionEnabled({ enabled: true });
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const isPerformanceCollectionEnabled = async () => {
|
|
58
|
+
const result = await FirebasePerformance.isPerformanceCollectionEnabled();
|
|
59
|
+
return result.enabled;
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
65
|
<docgen-index>
|
|
66
66
|
|
|
67
67
|
* [`startTrace(...)`](#starttrace)
|
|
68
68
|
* [`stopTrace(...)`](#stoptrace)
|
|
69
69
|
* [`incrementMetric(...)`](#incrementmetric)
|
|
70
|
-
* [`
|
|
71
|
-
* [`
|
|
70
|
+
* [`setEnabled(...)`](#setenabled)
|
|
71
|
+
* [`isEnabled()`](#isenabled)
|
|
72
72
|
* [Interfaces](#interfaces)
|
|
73
73
|
|
|
74
|
-
</docgen-index>
|
|
75
|
-
|
|
74
|
+
</docgen-index>
|
|
75
|
+
|
|
76
76
|
<docgen-api>
|
|
77
77
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
78
78
|
|
|
@@ -127,33 +127,33 @@ Atomically increments the metric with the given name for the selected trace by t
|
|
|
127
127
|
--------------------
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
###
|
|
130
|
+
### setEnabled(...)
|
|
131
131
|
|
|
132
132
|
```typescript
|
|
133
|
-
|
|
133
|
+
setEnabled(options: SetEnabledOptions) => Promise<void>
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
-
Enables or disables performance monitoring.
|
|
136
|
+
Enables or disables performance monitoring.
|
|
137
137
|
Will be applied with the next start of the app.
|
|
138
138
|
|
|
139
|
-
| Param | Type
|
|
140
|
-
| ------------- |
|
|
141
|
-
| **`options`** | <code><a href="#
|
|
139
|
+
| Param | Type |
|
|
140
|
+
| ------------- | --------------------------------------------------------------- |
|
|
141
|
+
| **`options`** | <code><a href="#setenabledoptions">SetEnabledOptions</a></code> |
|
|
142
142
|
|
|
143
143
|
**Since:** 0.1.0
|
|
144
144
|
|
|
145
145
|
--------------------
|
|
146
146
|
|
|
147
147
|
|
|
148
|
-
###
|
|
148
|
+
### isEnabled()
|
|
149
149
|
|
|
150
150
|
```typescript
|
|
151
|
-
|
|
151
|
+
isEnabled() => Promise<IsEnabledResult>
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
Determines whether performance monitoring is enabled or disabled.
|
|
155
155
|
|
|
156
|
-
**Returns:** <code>Promise<<a href="#
|
|
156
|
+
**Returns:** <code>Promise<<a href="#isenabledresult">IsEnabledResult</a>></code>
|
|
157
157
|
|
|
158
158
|
**Since:** 0.1.0
|
|
159
159
|
|
|
@@ -186,25 +186,25 @@ Determines whether performance monitoring is enabled or disabled.
|
|
|
186
186
|
| **`incrementBy`** | <code>number</code> | Amount by which the metric has to be incremented. | <code>1</code> | 0.1.0 |
|
|
187
187
|
|
|
188
188
|
|
|
189
|
-
####
|
|
189
|
+
#### SetEnabledOptions
|
|
190
190
|
|
|
191
191
|
| Prop | Type | Description | Since |
|
|
192
192
|
| ------------- | -------------------- | ----------------------------------------- | ----- |
|
|
193
193
|
| **`enabled`** | <code>boolean</code> | Should performance monitoring be enabled. | 0.1.0 |
|
|
194
194
|
|
|
195
195
|
|
|
196
|
-
####
|
|
196
|
+
#### IsEnabledResult
|
|
197
197
|
|
|
198
198
|
| Prop | Type | Description | Since |
|
|
199
199
|
| ------------- | -------------------- | --------------------------------------------------------------- | ----- |
|
|
200
200
|
| **`enabled`** | <code>boolean</code> | `true` if performance monitoring is enabled, otherwise `false`. | 0.1.0 |
|
|
201
201
|
|
|
202
|
-
</docgen-api>
|
|
203
|
-
|
|
204
|
-
## Changelog
|
|
205
|
-
|
|
206
|
-
See [CHANGELOG.md](/packages/performance/CHANGELOG.md).
|
|
207
|
-
|
|
208
|
-
## License
|
|
209
|
-
|
|
210
|
-
See [LICENSE](/packages/performance/LICENSE).
|
|
202
|
+
</docgen-api>
|
|
203
|
+
|
|
204
|
+
## Changelog
|
|
205
|
+
|
|
206
|
+
See [CHANGELOG.md](/packages/performance/CHANGELOG.md).
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
See [LICENSE](/packages/performance/LICENSE).
|
package/android/build.gradle
CHANGED
|
@@ -1,60 +1,59 @@
|
|
|
1
|
-
ext {
|
|
2
|
-
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
6
|
-
firebasePerfVersion = project.hasProperty('firebasePerfVersion') ? rootProject.ext.firebasePerfVersion : '20.0.6'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
buildscript {
|
|
10
|
-
repositories {
|
|
11
|
-
google()
|
|
12
|
-
mavenCentral()
|
|
13
|
-
}
|
|
14
|
-
dependencies {
|
|
15
|
-
classpath 'com.android.tools.build:gradle:
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
apply plugin: 'com.android.library'
|
|
20
|
-
|
|
21
|
-
android {
|
|
22
|
-
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion :
|
|
23
|
-
defaultConfig {
|
|
24
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion :
|
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
26
|
-
versionCode 1
|
|
27
|
-
versionName "1.0"
|
|
28
|
-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
-
}
|
|
30
|
-
buildTypes {
|
|
31
|
-
release {
|
|
32
|
-
minifyEnabled false
|
|
33
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
lintOptions {
|
|
37
|
-
abortOnError false
|
|
38
|
-
}
|
|
39
|
-
compileOptions {
|
|
40
|
-
sourceCompatibility JavaVersion.
|
|
41
|
-
targetCompatibility JavaVersion.
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
repositories {
|
|
46
|
-
google()
|
|
47
|
-
mavenCentral()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
implementation
|
|
54
|
-
implementation
|
|
55
|
-
implementation "
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
androidTestImplementation "androidx.test.
|
|
59
|
-
|
|
60
|
-
}
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
|
|
6
|
+
firebasePerfVersion = project.hasProperty('firebasePerfVersion') ? rootProject.ext.firebasePerfVersion : '20.0.6'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
buildscript {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
dependencies {
|
|
15
|
+
classpath 'com.android.tools.build:gradle:7.2.1'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apply plugin: 'com.android.library'
|
|
20
|
+
|
|
21
|
+
android {
|
|
22
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
implementation "com.google.firebase:firebase-perf:$firebasePerfVersion"
|
|
56
|
+
testImplementation "junit:junit:$junitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
58
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
59
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
-
package="
|
|
3
|
-
</manifest>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
package="io.capawesome.capacitorjs.plugins.firebase.performance">
|
|
3
|
+
</manifest>
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
package
|
|
2
|
-
|
|
3
|
-
import com.google.firebase.perf.metrics.Trace;
|
|
4
|
-
import java.util.HashMap;
|
|
5
|
-
|
|
6
|
-
public class FirebasePerformance {
|
|
7
|
-
|
|
8
|
-
private HashMap<String, Trace> traces = new HashMap<String, Trace>();
|
|
9
|
-
|
|
10
|
-
public void startTrace(String traceName) {
|
|
11
|
-
Trace trace = this.getFirebasePerformanceInstance().newTrace(traceName);
|
|
12
|
-
trace.start();
|
|
13
|
-
this.traces.put(traceName, trace);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public void stopTrace(String traceName) {
|
|
17
|
-
Trace trace = this.traces.get(traceName);
|
|
18
|
-
trace.stop();
|
|
19
|
-
this.traces.remove(traceName);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public void incrementMetric(String traceName, String metricName, Integer incrementBy) {
|
|
23
|
-
Trace trace = this.traces.get(traceName);
|
|
24
|
-
trace.incrementMetric(metricName, incrementBy);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public Trace getTraceByName(String traceName) {
|
|
28
|
-
if (this.traces.containsKey(traceName)) {
|
|
29
|
-
return this.traces.get(traceName);
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public void
|
|
35
|
-
this.getFirebasePerformanceInstance().setPerformanceCollectionEnabled(enabled);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
public Boolean
|
|
39
|
-
return this.getFirebasePerformanceInstance().isPerformanceCollectionEnabled();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private com.google.firebase.perf.FirebasePerformance getFirebasePerformanceInstance() {
|
|
43
|
-
return com.google.firebase.perf.FirebasePerformance.getInstance();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.firebase.performance;
|
|
2
|
+
|
|
3
|
+
import com.google.firebase.perf.metrics.Trace;
|
|
4
|
+
import java.util.HashMap;
|
|
5
|
+
|
|
6
|
+
public class FirebasePerformance {
|
|
7
|
+
|
|
8
|
+
private HashMap<String, Trace> traces = new HashMap<String, Trace>();
|
|
9
|
+
|
|
10
|
+
public void startTrace(String traceName) {
|
|
11
|
+
Trace trace = this.getFirebasePerformanceInstance().newTrace(traceName);
|
|
12
|
+
trace.start();
|
|
13
|
+
this.traces.put(traceName, trace);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public void stopTrace(String traceName) {
|
|
17
|
+
Trace trace = this.traces.get(traceName);
|
|
18
|
+
trace.stop();
|
|
19
|
+
this.traces.remove(traceName);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public void incrementMetric(String traceName, String metricName, Integer incrementBy) {
|
|
23
|
+
Trace trace = this.traces.get(traceName);
|
|
24
|
+
trace.incrementMetric(metricName, incrementBy);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public Trace getTraceByName(String traceName) {
|
|
28
|
+
if (this.traces.containsKey(traceName)) {
|
|
29
|
+
return this.traces.get(traceName);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public void setEnabled(Boolean enabled) {
|
|
35
|
+
this.getFirebasePerformanceInstance().setPerformanceCollectionEnabled(enabled);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public Boolean isEnabled() {
|
|
39
|
+
return this.getFirebasePerformanceInstance().isPerformanceCollectionEnabled();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private com.google.firebase.perf.FirebasePerformance getFirebasePerformanceInstance() {
|
|
43
|
+
return com.google.firebase.perf.FirebasePerformance.getInstance();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.firebase.performance;
|
|
2
|
+
|
|
3
|
+
import com.getcapacitor.JSObject;
|
|
4
|
+
import com.getcapacitor.Plugin;
|
|
5
|
+
import com.getcapacitor.PluginCall;
|
|
6
|
+
import com.getcapacitor.PluginMethod;
|
|
7
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
import com.google.firebase.perf.metrics.Trace;
|
|
9
|
+
|
|
10
|
+
@CapacitorPlugin(name = "FirebasePerformance")
|
|
11
|
+
public class FirebasePerformancePlugin extends Plugin {
|
|
12
|
+
|
|
13
|
+
public static final String ERROR_TRACE_NAME_MISSING = "traceName must be provided.";
|
|
14
|
+
public static final String ERROR_METRIC_NAME_MISSING = "metricName must be provided.";
|
|
15
|
+
public static final String ERROR_TRACE_NAME_ALREADY_ASSIGNED = "traceName already assigned.";
|
|
16
|
+
public static final String ERROR_ENABLED_MISSING = "enabled must be provided.";
|
|
17
|
+
public static final String ERROR_TRACE_NOT_FOUND = "No trace was found with the provided traceName.";
|
|
18
|
+
private FirebasePerformance implementation = new FirebasePerformance();
|
|
19
|
+
|
|
20
|
+
@PluginMethod
|
|
21
|
+
public void startTrace(PluginCall call) {
|
|
22
|
+
try {
|
|
23
|
+
String traceName = call.getString("traceName");
|
|
24
|
+
if (traceName == null) {
|
|
25
|
+
call.reject(ERROR_TRACE_NAME_MISSING);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
Trace trace = implementation.getTraceByName(traceName);
|
|
29
|
+
if (trace != null) {
|
|
30
|
+
call.reject(ERROR_TRACE_NAME_ALREADY_ASSIGNED);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
implementation.startTrace(traceName);
|
|
34
|
+
call.resolve();
|
|
35
|
+
} catch (Exception ex) {
|
|
36
|
+
call.reject(ex.getLocalizedMessage());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@PluginMethod
|
|
41
|
+
public void stopTrace(PluginCall call) {
|
|
42
|
+
try {
|
|
43
|
+
String traceName = call.getString("traceName");
|
|
44
|
+
if (traceName == null) {
|
|
45
|
+
call.reject(ERROR_TRACE_NAME_MISSING);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
Trace trace = implementation.getTraceByName(traceName);
|
|
49
|
+
if (trace == null) {
|
|
50
|
+
call.reject(ERROR_TRACE_NOT_FOUND);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
implementation.stopTrace(traceName);
|
|
54
|
+
call.resolve();
|
|
55
|
+
} catch (Exception ex) {
|
|
56
|
+
call.reject(ex.getLocalizedMessage());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@PluginMethod
|
|
61
|
+
public void incrementMetric(PluginCall call) {
|
|
62
|
+
try {
|
|
63
|
+
String traceName = call.getString("traceName");
|
|
64
|
+
String metricName = call.getString("metricName");
|
|
65
|
+
Integer incrementBy = call.getInt("incrementBy", 1);
|
|
66
|
+
if (traceName == null) {
|
|
67
|
+
call.reject(ERROR_TRACE_NAME_MISSING);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (metricName == null) {
|
|
71
|
+
call.reject(ERROR_METRIC_NAME_MISSING);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
Trace trace = implementation.getTraceByName(traceName);
|
|
75
|
+
if (trace == null) {
|
|
76
|
+
call.reject(ERROR_TRACE_NOT_FOUND);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
implementation.incrementMetric(traceName, metricName, incrementBy);
|
|
80
|
+
call.resolve();
|
|
81
|
+
} catch (Exception ex) {
|
|
82
|
+
call.reject(ex.getLocalizedMessage());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@PluginMethod
|
|
87
|
+
public void setEnabled(PluginCall call) {
|
|
88
|
+
try {
|
|
89
|
+
Boolean enabled = call.getBoolean("enabled");
|
|
90
|
+
if (enabled == null) {
|
|
91
|
+
call.reject(ERROR_ENABLED_MISSING);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
implementation.setEnabled(enabled);
|
|
95
|
+
call.resolve();
|
|
96
|
+
} catch (Exception ex) {
|
|
97
|
+
call.reject(ex.getLocalizedMessage());
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@PluginMethod
|
|
102
|
+
public void isEnabled(PluginCall call) {
|
|
103
|
+
try {
|
|
104
|
+
Boolean enabled = implementation.isEnabled();
|
|
105
|
+
JSObject result = new JSObject();
|
|
106
|
+
result.put("enabled", enabled);
|
|
107
|
+
call.resolve(result);
|
|
108
|
+
} catch (Exception ex) {
|
|
109
|
+
call.reject(ex.getLocalizedMessage());
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -75,13 +75,13 @@
|
|
|
75
75
|
"slug": "incrementmetric"
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
|
-
"name": "
|
|
79
|
-
"signature": "(options:
|
|
78
|
+
"name": "setEnabled",
|
|
79
|
+
"signature": "(options: SetEnabledOptions) => Promise<void>",
|
|
80
80
|
"parameters": [
|
|
81
81
|
{
|
|
82
82
|
"name": "options",
|
|
83
83
|
"docs": "",
|
|
84
|
-
"type": "
|
|
84
|
+
"type": "SetEnabledOptions"
|
|
85
85
|
}
|
|
86
86
|
],
|
|
87
87
|
"returns": "Promise<void>",
|
|
@@ -91,17 +91,17 @@
|
|
|
91
91
|
"text": "0.1.0"
|
|
92
92
|
}
|
|
93
93
|
],
|
|
94
|
-
"docs": "Enables or disables performance monitoring.\nWill be applied with the next start of the app.",
|
|
94
|
+
"docs": "Enables or disables performance monitoring.\r\nWill be applied with the next start of the app.",
|
|
95
95
|
"complexTypes": [
|
|
96
|
-
"
|
|
96
|
+
"SetEnabledOptions"
|
|
97
97
|
],
|
|
98
|
-
"slug": "
|
|
98
|
+
"slug": "setenabled"
|
|
99
99
|
},
|
|
100
100
|
{
|
|
101
|
-
"name": "
|
|
102
|
-
"signature": "() => Promise<
|
|
101
|
+
"name": "isEnabled",
|
|
102
|
+
"signature": "() => Promise<IsEnabledResult>",
|
|
103
103
|
"parameters": [],
|
|
104
|
-
"returns": "Promise<
|
|
104
|
+
"returns": "Promise<IsEnabledResult>",
|
|
105
105
|
"tags": [
|
|
106
106
|
{
|
|
107
107
|
"name": "since",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
],
|
|
111
111
|
"docs": "Determines whether performance monitoring is enabled or disabled.",
|
|
112
112
|
"complexTypes": [
|
|
113
|
-
"
|
|
113
|
+
"IsEnabledResult"
|
|
114
114
|
],
|
|
115
|
-
"slug": "
|
|
115
|
+
"slug": "isenabled"
|
|
116
116
|
}
|
|
117
117
|
],
|
|
118
118
|
"properties": []
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"name": "since"
|
|
139
139
|
}
|
|
140
140
|
],
|
|
141
|
-
"docs": "Custom trace name.\n\nNames for custom code traces must meet the following requirements:\nno leading or trailing whitespace, no leading underscore (_) character,\nand max length is 100 characters.",
|
|
141
|
+
"docs": "Custom trace name.\r\n\r\nNames for custom code traces must meet the following requirements:\r\nno leading or trailing whitespace, no leading underscore (_) character,\r\nand max length is 100 characters.",
|
|
142
142
|
"complexTypes": [],
|
|
143
143
|
"type": "string"
|
|
144
144
|
}
|
|
@@ -225,8 +225,8 @@
|
|
|
225
225
|
]
|
|
226
226
|
},
|
|
227
227
|
{
|
|
228
|
-
"name": "
|
|
229
|
-
"slug": "
|
|
228
|
+
"name": "SetEnabledOptions",
|
|
229
|
+
"slug": "setenabledoptions",
|
|
230
230
|
"docs": "",
|
|
231
231
|
"tags": [
|
|
232
232
|
{
|
|
@@ -251,8 +251,8 @@
|
|
|
251
251
|
]
|
|
252
252
|
},
|
|
253
253
|
{
|
|
254
|
-
"name": "
|
|
255
|
-
"slug": "
|
|
254
|
+
"name": "IsEnabledResult",
|
|
255
|
+
"slug": "isenabledresult",
|
|
256
256
|
"docs": "",
|
|
257
257
|
"tags": [],
|
|
258
258
|
"methods": [],
|