leap-capacitor 1.0.1 → 1.2.0
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/README.md +28 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/is/leap/capacitor/LeapPlugin.java +51 -15
- package/dist/docs.json +34 -0
- package/dist/esm/definitions.d.ts +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/LeapPlugin.m +2 -0
- package/ios/Plugin/LeapPlugin.swift +74 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ npx cap sync
|
|
|
15
15
|
|
|
16
16
|
* [`start(...)`](#start)
|
|
17
17
|
* [`startWithProperties(...)`](#startwithproperties)
|
|
18
|
+
* [`startWithSelfHostedURL(...)`](#startwithselfhostedurl)
|
|
19
|
+
* [`startWithSelfHostedURLAndProperties(...)`](#startwithselfhostedurlandproperties)
|
|
18
20
|
* [`flushProperties(...)`](#flushproperties)
|
|
19
21
|
* [`setUniqueUserId(...)`](#setuniqueuserid)
|
|
20
22
|
* [`startProject(...)`](#startproject)
|
|
@@ -57,6 +59,32 @@ startWithProperties(options: { apiKey: string; properties: UserProperty; }) => P
|
|
|
57
59
|
--------------------
|
|
58
60
|
|
|
59
61
|
|
|
62
|
+
### startWithSelfHostedURL(...)
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
startWithSelfHostedURL(options: { baseURL: string; }) => Promise<void>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Param | Type |
|
|
69
|
+
| ------------- | --------------------------------- |
|
|
70
|
+
| **`options`** | <code>{ baseURL: string; }</code> |
|
|
71
|
+
|
|
72
|
+
--------------------
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### startWithSelfHostedURLAndProperties(...)
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
startWithSelfHostedURLAndProperties(options: { baseURL: string; properties: UserProperty; }) => Promise<void>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| Param | Type |
|
|
82
|
+
| ------------- | --------------------------------------------------------------------------------------- |
|
|
83
|
+
| **`options`** | <code>{ baseURL: string; properties: <a href="#userproperty">UserProperty</a>; }</code> |
|
|
84
|
+
|
|
85
|
+
--------------------
|
|
86
|
+
|
|
87
|
+
|
|
60
88
|
### flushProperties(...)
|
|
61
89
|
|
|
62
90
|
```typescript
|
package/android/build.gradle
CHANGED
|
@@ -11,7 +11,7 @@ buildscript {
|
|
|
11
11
|
jcenter()
|
|
12
12
|
}
|
|
13
13
|
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:4.2.
|
|
14
|
+
classpath 'com.android.tools.build:gradle:4.2.2'
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -51,7 +51,7 @@ repositories {
|
|
|
51
51
|
dependencies {
|
|
52
52
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
53
|
implementation project(':capacitor-android')
|
|
54
|
-
implementation 'is.leap.android:sdk:1.
|
|
54
|
+
implementation 'is.leap.android:sdk:1.7.0'
|
|
55
55
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
56
|
testImplementation "junit:junit:$junitVersion"
|
|
57
57
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
@@ -43,6 +43,7 @@ import is.leap.android.core.LeapElementActionCallbacks;
|
|
|
43
43
|
public class LeapPlugin extends Plugin {
|
|
44
44
|
|
|
45
45
|
public static final String API_KEY = "apiKey";
|
|
46
|
+
public static final String SELF_HOSTING_BASE_URL = "baseURL";
|
|
46
47
|
public static final String PROPERTIES = "properties";
|
|
47
48
|
public static final String DATE_TYPE_PREFIX = "Date:";
|
|
48
49
|
public static final String PROJECT_IDS = "projectIds";
|
|
@@ -58,6 +59,7 @@ public class LeapPlugin extends Plugin {
|
|
|
58
59
|
private static final String FORMAT_SDF = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
|
59
60
|
private static final String TIMEZONE_GMT = "GMT";
|
|
60
61
|
public static final String LOCALE_CODE = "localeCode";
|
|
62
|
+
public static final String WFX_CLIENT_UNIQUE_ID = "wfx_user_id";
|
|
61
63
|
|
|
62
64
|
public LeapPlugin() {
|
|
63
65
|
setLeapEventEmitter();
|
|
@@ -71,6 +73,34 @@ public class LeapPlugin extends Plugin {
|
|
|
71
73
|
call.resolve();
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
@PluginMethod
|
|
77
|
+
public void startWithSelfHostedURL(PluginCall call) {
|
|
78
|
+
String baseURL = call.getString(SELF_HOSTING_BASE_URL);
|
|
79
|
+
Leap.withSelfHostedBuilder()
|
|
80
|
+
.setBaseUrl(baseURL)
|
|
81
|
+
.start();
|
|
82
|
+
call.resolve();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@PluginMethod
|
|
86
|
+
public void startWithSelfHostedURLAndProperties(PluginCall call) {
|
|
87
|
+
String baseURL = call.getString(SELF_HOSTING_BASE_URL);
|
|
88
|
+
JSObject propsObj = call.getObject(PROPERTIES);
|
|
89
|
+
Leap.Builder builder = Leap.withSelfHostedBuilder()
|
|
90
|
+
.setBaseUrl(baseURL);
|
|
91
|
+
|
|
92
|
+
if(propsObj == null) {
|
|
93
|
+
builder.start();
|
|
94
|
+
call.resolve();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
startWithProperties(propsObj, builder);
|
|
99
|
+
call.resolve();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
74
104
|
@PluginMethod
|
|
75
105
|
public void startWithProperties(PluginCall call) {
|
|
76
106
|
String apiKey = call.getString(API_KEY);
|
|
@@ -81,10 +111,20 @@ public class LeapPlugin extends Plugin {
|
|
|
81
111
|
return;
|
|
82
112
|
}
|
|
83
113
|
Leap.Builder leapBuilder = Leap.withBuilder(apiKey);
|
|
114
|
+
startWithProperties(propsObj, leapBuilder);
|
|
115
|
+
call.resolve();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private void startWithProperties(JSObject propsObj, Leap.Builder leapBuilder) {
|
|
84
119
|
Iterator<String> iterator = propsObj.keys();
|
|
85
120
|
|
|
86
121
|
while (iterator.hasNext()) {
|
|
87
122
|
String key = iterator.next();
|
|
123
|
+
if(WFX_CLIENT_UNIQUE_ID.equals(key)) {
|
|
124
|
+
String uniqueId = propsObj.getString(key);
|
|
125
|
+
leapBuilder.addUniqueId(uniqueId);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
88
128
|
Object propValue = null;
|
|
89
129
|
try {
|
|
90
130
|
propValue = propsObj.get(key);
|
|
@@ -106,7 +146,6 @@ public class LeapPlugin extends Plugin {
|
|
|
106
146
|
|
|
107
147
|
}
|
|
108
148
|
leapBuilder.start();
|
|
109
|
-
call.resolve();
|
|
110
149
|
}
|
|
111
150
|
|
|
112
151
|
@PluginMethod
|
|
@@ -212,22 +251,19 @@ public class LeapPlugin extends Plugin {
|
|
|
212
251
|
}
|
|
213
252
|
|
|
214
253
|
private void setLeapEventEmitter() {
|
|
215
|
-
LeapEventCallbacks leapEventListener =
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
jsObject = new JSObject(ret.toString());
|
|
224
|
-
} catch (JSONException e) {
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
if(jsObject == null) return;
|
|
228
|
-
notifyListeners(LEAP_CALLBACKS, jsObject);
|
|
254
|
+
LeapEventCallbacks leapEventListener = eventValue -> {
|
|
255
|
+
if (eventValue == null)
|
|
256
|
+
return;
|
|
257
|
+
JSONObject ret = new JSONObject(eventValue);
|
|
258
|
+
JSObject jsObject = null;
|
|
259
|
+
try {
|
|
260
|
+
jsObject = new JSObject(ret.toString());
|
|
261
|
+
} catch (JSONException ignored) {
|
|
229
262
|
|
|
230
263
|
}
|
|
264
|
+
if(jsObject == null) return;
|
|
265
|
+
notifyListeners(LEAP_CALLBACKS, jsObject);
|
|
266
|
+
|
|
231
267
|
};
|
|
232
268
|
Leap.setLeapEventCallbacks(leapEventListener);
|
|
233
269
|
}
|
package/dist/docs.json
CHANGED
|
@@ -39,6 +39,40 @@
|
|
|
39
39
|
],
|
|
40
40
|
"slug": "startwithproperties"
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
"name": "startWithSelfHostedURL",
|
|
44
|
+
"signature": "(options: { baseURL: string; }) => Promise<void>",
|
|
45
|
+
"parameters": [
|
|
46
|
+
{
|
|
47
|
+
"name": "options",
|
|
48
|
+
"docs": "",
|
|
49
|
+
"type": "{ baseURL: string; }"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"returns": "Promise<void>",
|
|
53
|
+
"tags": [],
|
|
54
|
+
"docs": "",
|
|
55
|
+
"complexTypes": [],
|
|
56
|
+
"slug": "startwithselfhostedurl"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "startWithSelfHostedURLAndProperties",
|
|
60
|
+
"signature": "(options: { baseURL: string; properties: UserProperty; }) => Promise<void>",
|
|
61
|
+
"parameters": [
|
|
62
|
+
{
|
|
63
|
+
"name": "options",
|
|
64
|
+
"docs": "",
|
|
65
|
+
"type": "{ baseURL: string; properties: UserProperty; }"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"returns": "Promise<void>",
|
|
69
|
+
"tags": [],
|
|
70
|
+
"docs": "",
|
|
71
|
+
"complexTypes": [
|
|
72
|
+
"UserProperty"
|
|
73
|
+
],
|
|
74
|
+
"slug": "startwithselfhostedurlandproperties"
|
|
75
|
+
},
|
|
42
76
|
{
|
|
43
77
|
"name": "flushProperties",
|
|
44
78
|
"signature": "(options: { properties: UserProperty; }) => Promise<void>",
|
|
@@ -16,6 +16,13 @@ export interface LeapPluginInterface {
|
|
|
16
16
|
apiKey: string;
|
|
17
17
|
properties: UserProperty;
|
|
18
18
|
}): Promise<void>;
|
|
19
|
+
startWithSelfHostedURL(options: {
|
|
20
|
+
baseURL: string;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
startWithSelfHostedURLAndProperties(options: {
|
|
23
|
+
baseURL: string;
|
|
24
|
+
properties: UserProperty;
|
|
25
|
+
}): Promise<void>;
|
|
19
26
|
flushProperties(options: {
|
|
20
27
|
properties: UserProperty;
|
|
21
28
|
}): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface UserProperty {\n [key: string]: string | number\n}\n\nexport interface LeapCallbacks {\n [key: string]: string\n}\n\nexport interface LeapElementActionCallbacks {\n [key: string]: any\n}\n\nexport interface LeapPluginInterface {\n start(options: { apiKey: string }): Promise<void>;\n startWithProperties(options: { apiKey: string, properties: UserProperty }): Promise<void>;\n flushProperties(options: { properties: UserProperty }): Promise<void>;\n setUniqueUserId(options: { uniqueUserId: string }): Promise<void>;\n startProject(options: { projectId: string, resetProject?: boolean }): Promise<void>;\n embedProject(options: { projectId: string }): Promise<void>;\n offlineSync(options: { projectIds: Array<string> }): Promise<void>;\n disable(): Promise<void>;\n setAppLocale(options: {localeCode: string}): Promise<void>;\n\n addListener(\n eventName: 'leapCallbacks',\n listenerFunc: (event: LeapCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n addListener(\n eventName: 'leapElementActionCallbacks',\n listenerFunc: (event: LeapElementActionCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface UserProperty {\n [key: string]: string | number\n}\n\nexport interface LeapCallbacks {\n [key: string]: string\n}\n\nexport interface LeapElementActionCallbacks {\n [key: string]: any\n}\n\nexport interface LeapPluginInterface {\n start(options: { apiKey: string }): Promise<void>;\n startWithProperties(options: { apiKey: string, properties: UserProperty }): Promise<void>;\n startWithSelfHostedURL(options:{baseURL: string}):Promise<void>;\n startWithSelfHostedURLAndProperties(options:{baseURL:string, properties: UserProperty}):Promise<void>;\n flushProperties(options: { properties: UserProperty }): Promise<void>;\n setUniqueUserId(options: { uniqueUserId: string }): Promise<void>;\n startProject(options: { projectId: string, resetProject?: boolean }): Promise<void>;\n embedProject(options: { projectId: string }): Promise<void>;\n offlineSync(options: { projectIds: Array<string> }): Promise<void>;\n disable(): Promise<void>;\n setAppLocale(options: {localeCode: string}): Promise<void>;\n\n addListener(\n eventName: 'leapCallbacks',\n listenerFunc: (event: LeapCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n addListener(\n eventName: 'leapElementActionCallbacks',\n listenerFunc: (event: LeapElementActionCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n\n}\n"]}
|
package/ios/Plugin/LeapPlugin.m
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
CAP_PLUGIN(LeapPlugin, "LeapPlugin",
|
|
7
7
|
CAP_PLUGIN_METHOD(start, CAPPluginReturnPromise);
|
|
8
8
|
CAP_PLUGIN_METHOD(startWithProperties, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(startWithSelfHostedURL, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(startWithSelfHostedURLAndProperties, CAPPluginReturnPromise);
|
|
9
11
|
CAP_PLUGIN_METHOD(flushProperties, CAPPluginReturnPromise);
|
|
10
12
|
CAP_PLUGIN_METHOD(startProject, CAPPluginReturnPromise);
|
|
11
13
|
CAP_PLUGIN_METHOD(embedProject, CAPPluginReturnPromise);
|
|
@@ -2,6 +2,20 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
import LeapSDK
|
|
4
4
|
|
|
5
|
+
let API_KEY = "apiKey"
|
|
6
|
+
let PROPERTIES = "properties"
|
|
7
|
+
let DATE_PREFIX = "Date:"
|
|
8
|
+
let BASE_URL = "baseURL"
|
|
9
|
+
let UNIQUE_USER_ID = "uniqueUserId"
|
|
10
|
+
let LOCALE_CODE = "localeCode"
|
|
11
|
+
let PROJECT_ID = "projectId"
|
|
12
|
+
let RESET_PROJECT = "resetProject"
|
|
13
|
+
let PROJECT_IDS = "projectIds"
|
|
14
|
+
let DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
|
15
|
+
let DATE_LOCALE = "en_US_POSIX"
|
|
16
|
+
let LEAP_CALLBACKS = "leapCallbacks"
|
|
17
|
+
let WFX_UNIQUE_ID = "wfx_user_id"
|
|
18
|
+
|
|
5
19
|
/**
|
|
6
20
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
21
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
@@ -11,7 +25,7 @@ import LeapSDK
|
|
|
11
25
|
public class LeapPlugin: CAPPlugin {
|
|
12
26
|
|
|
13
27
|
@objc public func start(_ call: CAPPluginCall) {
|
|
14
|
-
let apiKey = call.getString(
|
|
28
|
+
let apiKey = call.getString(API_KEY) ?? ""
|
|
15
29
|
DispatchQueue.main.async {
|
|
16
30
|
Leap.shared.start(apiKey)
|
|
17
31
|
Leap.shared.callback = self
|
|
@@ -20,62 +34,59 @@ public class LeapPlugin: CAPPlugin {
|
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
@objc public func startWithProperties(_ call: CAPPluginCall) {
|
|
23
|
-
let apiKey = call.getString(
|
|
24
|
-
let properties:[String:AnyHashable] = call.getObject(
|
|
25
|
-
DispatchQueue.main.async {
|
|
37
|
+
let apiKey = call.getString(API_KEY) ?? ""
|
|
38
|
+
let properties:[String:AnyHashable] = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
39
|
+
DispatchQueue.main.async {[weak self] in
|
|
26
40
|
let leapShared = Leap.shared.withBuilder(apiKey)
|
|
27
|
-
properties
|
|
28
|
-
|
|
29
|
-
if stringValue.hasPrefix("Date:") {
|
|
30
|
-
let dateValue = stringValue.components(separatedBy: "Date:").last ?? ""
|
|
31
|
-
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
32
|
-
leapShared?.addProperty(key, dateValue: date)
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
leapShared?.addProperty(key, stringValue: stringValue)
|
|
36
|
-
}
|
|
37
|
-
} else if let intValue = value as? Int {
|
|
38
|
-
leapShared?.addProperty(key, intValue: intValue)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
+
if let wfxId = properties[WFX_UNIQUE_ID] as? String { Leap.shared.addUniqueUserId(wfxId) }
|
|
42
|
+
self?.addProperties(properties: properties)
|
|
41
43
|
leapShared?.start()
|
|
42
44
|
}
|
|
43
45
|
call.resolve()
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
@objc public func startWithSelfHostedURL(_ call:CAPPluginCall) {
|
|
49
|
+
if let baseUrl = call.getString(BASE_URL) {
|
|
50
|
+
DispatchQueue.main.async {
|
|
51
|
+
Leap.shared.withSelfHostedBuilder()?.setBaseUrl(baseUrl)?.start()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
call.resolve()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@objc public func startWithSelfHostedURLAndProperties(_ call:CAPPluginCall) {
|
|
58
|
+
if let baseUrl = call.getString(BASE_URL) {
|
|
59
|
+
let properties = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
60
|
+
DispatchQueue.main.async {[weak self] in
|
|
61
|
+
Leap.shared.withSelfHostedBuilder()?.setBaseUrl(baseUrl)
|
|
62
|
+
if let wfxId = properties[WFX_UNIQUE_ID] as? String { Leap.shared.addUniqueUserId(wfxId) }
|
|
63
|
+
self?.addProperties(properties: properties)
|
|
64
|
+
Leap.shared.start()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
call.resolve()
|
|
68
|
+
}
|
|
69
|
+
|
|
46
70
|
@objc public func flushProperties(_ call: CAPPluginCall) {
|
|
47
|
-
let properties:[String:AnyHashable] = call.getObject(
|
|
48
|
-
DispatchQueue.main.async {
|
|
71
|
+
let properties:[String:AnyHashable] = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
72
|
+
DispatchQueue.main.async {[weak self] in
|
|
49
73
|
let leapShared = Leap.shared
|
|
50
|
-
properties
|
|
51
|
-
if let stringValue = value as? String {
|
|
52
|
-
if stringValue.hasPrefix("Date:") {
|
|
53
|
-
let dateValue = stringValue.components(separatedBy: "Date:").last ?? ""
|
|
54
|
-
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
55
|
-
leapShared.addProperty(key, dateValue: date)
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
leapShared.addProperty(key, stringValue: stringValue)
|
|
59
|
-
}
|
|
60
|
-
} else if let intValue = value as? Int {
|
|
61
|
-
leapShared.addProperty(key, intValue: intValue)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
74
|
+
self?.addProperties(properties: properties)
|
|
64
75
|
leapShared.flush()
|
|
65
76
|
}
|
|
66
77
|
call.resolve()
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
@objc public func setUniqueUserId(_ call: CAPPluginCall) {
|
|
70
|
-
let uniqueUserId = call.getString(
|
|
81
|
+
let uniqueUserId = call.getString(UNIQUE_USER_ID) ?? ""
|
|
71
82
|
DispatchQueue.main.async {
|
|
72
83
|
Leap.shared.setUniqueUserId(uniqueUserId)
|
|
73
84
|
}
|
|
74
85
|
call.resolve()
|
|
75
86
|
}
|
|
76
|
-
|
|
87
|
+
|
|
77
88
|
@objc public func setAppLocale(_ call: CAPPluginCall) {
|
|
78
|
-
let localeCode = call.getString(
|
|
89
|
+
let localeCode = call.getString(LOCALE_CODE) ?? ""
|
|
79
90
|
DispatchQueue.main.async {
|
|
80
91
|
Leap.shared.setAppLocale(localeCode)
|
|
81
92
|
}
|
|
@@ -83,8 +94,8 @@ public class LeapPlugin: CAPPlugin {
|
|
|
83
94
|
}
|
|
84
95
|
|
|
85
96
|
@objc public func startProject(_ call: CAPPluginCall) {
|
|
86
|
-
let projectId = call.getString(
|
|
87
|
-
let resetProject = call.getBool(
|
|
97
|
+
let projectId = call.getString(PROJECT_ID) ?? ""
|
|
98
|
+
let resetProject = call.getBool(RESET_PROJECT) ?? false
|
|
88
99
|
DispatchQueue.main.async {
|
|
89
100
|
Leap.shared.startProject(projectId, resetProject: resetProject)
|
|
90
101
|
}
|
|
@@ -92,7 +103,7 @@ public class LeapPlugin: CAPPlugin {
|
|
|
92
103
|
}
|
|
93
104
|
|
|
94
105
|
@objc public func embedProject(_ call: CAPPluginCall) {
|
|
95
|
-
let projectId = call.getString(
|
|
106
|
+
let projectId = call.getString(PROJECT_ID) ?? ""
|
|
96
107
|
DispatchQueue.main.async {
|
|
97
108
|
Leap.shared.embedProject(projectId)
|
|
98
109
|
}
|
|
@@ -100,7 +111,7 @@ public class LeapPlugin: CAPPlugin {
|
|
|
100
111
|
}
|
|
101
112
|
|
|
102
113
|
@objc public func offlineSync(_ call: CAPPluginCall) {
|
|
103
|
-
let projectIds = call.getArray(
|
|
114
|
+
let projectIds = call.getArray(PROJECT_IDS)?.capacitor.replacingNullValues() as? [String] ?? []
|
|
104
115
|
DispatchQueue.main.async {
|
|
105
116
|
Leap.shared.offlineSync(projectIds)
|
|
106
117
|
}
|
|
@@ -114,10 +125,29 @@ public class LeapPlugin: CAPPlugin {
|
|
|
114
125
|
call.resolve()
|
|
115
126
|
}
|
|
116
127
|
|
|
128
|
+
func addProperties(properties:[String:AnyHashable]) {
|
|
129
|
+
properties.forEach { key, value in
|
|
130
|
+
if key != WFX_UNIQUE_ID {
|
|
131
|
+
if let stringValue = value as? String {
|
|
132
|
+
if stringValue.hasPrefix(DATE_PREFIX) {
|
|
133
|
+
let dateValue = stringValue.components(separatedBy: DATE_PREFIX).last ?? ""
|
|
134
|
+
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
135
|
+
Leap.shared.addProperty(key, dateValue: date)
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
Leap.shared.addProperty(key, stringValue: stringValue)
|
|
139
|
+
}
|
|
140
|
+
} else if let intValue = value as? Int {
|
|
141
|
+
Leap.shared.addProperty(key, intValue: intValue)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
117
147
|
func getDateFromISOString(dateString:String) -> Date? {
|
|
118
148
|
let formatter = DateFormatter()
|
|
119
|
-
formatter.dateFormat =
|
|
120
|
-
let posix:Locale = Locale(identifier:
|
|
149
|
+
formatter.dateFormat = DATE_FORMAT
|
|
150
|
+
let posix:Locale = Locale(identifier: DATE_LOCALE)
|
|
121
151
|
formatter.locale = posix
|
|
122
152
|
let date = formatter.date(from: dateString)
|
|
123
153
|
return date
|
|
@@ -128,7 +158,7 @@ extension LeapPlugin: LeapCallback {
|
|
|
128
158
|
|
|
129
159
|
public func eventNotification(eventInfo: Dictionary<String, Any>) {
|
|
130
160
|
DispatchQueue.main.async { [weak self] in
|
|
131
|
-
self?.notifyListeners(
|
|
161
|
+
self?.notifyListeners(LEAP_CALLBACKS, data: eventInfo)
|
|
132
162
|
}
|
|
133
163
|
}
|
|
134
164
|
}
|