leap-capacitor 1.0.1 → 1.3.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 +38 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/is/leap/capacitor/LeapPlugin.java +53 -16
- package/dist/docs.json +44 -0
- package/dist/esm/definitions.d.ts +8 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/LeapPlugin.m +3 -0
- package/ios/Plugin/LeapPlugin.swift +76 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,12 +15,15 @@ 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)
|
|
21
23
|
* [`embedProject(...)`](#embedproject)
|
|
22
24
|
* [`offlineSync(...)`](#offlinesync)
|
|
23
25
|
* [`disable()`](#disable)
|
|
26
|
+
* [`logout()`](#logout)
|
|
24
27
|
* [`setAppLocale(...)`](#setapplocale)
|
|
25
28
|
* [`addListener('leapCallbacks', ...)`](#addlistenerleapcallbacks)
|
|
26
29
|
* [`addListener('leapElementActionCallbacks', ...)`](#addlistenerleapelementactioncallbacks)
|
|
@@ -57,6 +60,32 @@ startWithProperties(options: { apiKey: string; properties: UserProperty; }) => P
|
|
|
57
60
|
--------------------
|
|
58
61
|
|
|
59
62
|
|
|
63
|
+
### startWithSelfHostedURL(...)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
startWithSelfHostedURL(options: { baseURL: string; }) => Promise<void>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Param | Type |
|
|
70
|
+
| ------------- | --------------------------------- |
|
|
71
|
+
| **`options`** | <code>{ baseURL: string; }</code> |
|
|
72
|
+
|
|
73
|
+
--------------------
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### startWithSelfHostedURLAndProperties(...)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
startWithSelfHostedURLAndProperties(options: { baseURL: string; properties: UserProperty; }) => Promise<void>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Param | Type |
|
|
83
|
+
| ------------- | --------------------------------------------------------------------------------------- |
|
|
84
|
+
| **`options`** | <code>{ baseURL: string; properties: <a href="#userproperty">UserProperty</a>; }</code> |
|
|
85
|
+
|
|
86
|
+
--------------------
|
|
87
|
+
|
|
88
|
+
|
|
60
89
|
### flushProperties(...)
|
|
61
90
|
|
|
62
91
|
```typescript
|
|
@@ -131,6 +160,15 @@ disable() => Promise<void>
|
|
|
131
160
|
--------------------
|
|
132
161
|
|
|
133
162
|
|
|
163
|
+
### logout()
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
logout() => Promise<void>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
--------------------
|
|
170
|
+
|
|
171
|
+
|
|
134
172
|
### setAppLocale(...)
|
|
135
173
|
|
|
136
174
|
```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.8.2'
|
|
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";
|
|
@@ -71,6 +72,34 @@ public class LeapPlugin extends Plugin {
|
|
|
71
72
|
call.resolve();
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
@PluginMethod
|
|
76
|
+
public void startWithSelfHostedURL(PluginCall call) {
|
|
77
|
+
String baseURL = call.getString(SELF_HOSTING_BASE_URL);
|
|
78
|
+
Leap.withSelfHostedBuilder()
|
|
79
|
+
.setBaseUrl(baseURL)
|
|
80
|
+
.start();
|
|
81
|
+
call.resolve();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@PluginMethod
|
|
85
|
+
public void startWithSelfHostedURLAndProperties(PluginCall call) {
|
|
86
|
+
String baseURL = call.getString(SELF_HOSTING_BASE_URL);
|
|
87
|
+
JSObject propsObj = call.getObject(PROPERTIES);
|
|
88
|
+
Leap.Builder builder = Leap.withSelfHostedBuilder()
|
|
89
|
+
.setBaseUrl(baseURL);
|
|
90
|
+
|
|
91
|
+
if(propsObj == null) {
|
|
92
|
+
builder.start();
|
|
93
|
+
call.resolve();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
startWithProperties(propsObj, builder);
|
|
98
|
+
call.resolve();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
74
103
|
@PluginMethod
|
|
75
104
|
public void startWithProperties(PluginCall call) {
|
|
76
105
|
String apiKey = call.getString(API_KEY);
|
|
@@ -81,6 +110,11 @@ public class LeapPlugin extends Plugin {
|
|
|
81
110
|
return;
|
|
82
111
|
}
|
|
83
112
|
Leap.Builder leapBuilder = Leap.withBuilder(apiKey);
|
|
113
|
+
startWithProperties(propsObj, leapBuilder);
|
|
114
|
+
call.resolve();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private void startWithProperties(JSObject propsObj, Leap.Builder leapBuilder) {
|
|
84
118
|
Iterator<String> iterator = propsObj.keys();
|
|
85
119
|
|
|
86
120
|
while (iterator.hasNext()) {
|
|
@@ -106,7 +140,6 @@ public class LeapPlugin extends Plugin {
|
|
|
106
140
|
|
|
107
141
|
}
|
|
108
142
|
leapBuilder.start();
|
|
109
|
-
call.resolve();
|
|
110
143
|
}
|
|
111
144
|
|
|
112
145
|
@PluginMethod
|
|
@@ -148,6 +181,12 @@ public class LeapPlugin extends Plugin {
|
|
|
148
181
|
call.resolve();
|
|
149
182
|
}
|
|
150
183
|
|
|
184
|
+
@PluginMethod
|
|
185
|
+
public static void logout(PluginCall call) {
|
|
186
|
+
Leap.logout();
|
|
187
|
+
call.resolve();
|
|
188
|
+
}
|
|
189
|
+
|
|
151
190
|
@PluginMethod
|
|
152
191
|
public static void startProject(PluginCall call) {
|
|
153
192
|
String projectID = call.getString(PROJECT_ID);
|
|
@@ -190,8 +229,9 @@ public class LeapPlugin extends Plugin {
|
|
|
190
229
|
}
|
|
191
230
|
|
|
192
231
|
@PluginMethod
|
|
193
|
-
public void disable() {
|
|
232
|
+
public void disable(PluginCall call) {
|
|
194
233
|
Leap.disable();
|
|
234
|
+
call.resolve();
|
|
195
235
|
}
|
|
196
236
|
|
|
197
237
|
@PluginMethod
|
|
@@ -212,22 +252,19 @@ public class LeapPlugin extends Plugin {
|
|
|
212
252
|
}
|
|
213
253
|
|
|
214
254
|
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);
|
|
255
|
+
LeapEventCallbacks leapEventListener = eventValue -> {
|
|
256
|
+
if (eventValue == null)
|
|
257
|
+
return;
|
|
258
|
+
JSONObject ret = new JSONObject(eventValue);
|
|
259
|
+
JSObject jsObject = null;
|
|
260
|
+
try {
|
|
261
|
+
jsObject = new JSObject(ret.toString());
|
|
262
|
+
} catch (JSONException ignored) {
|
|
229
263
|
|
|
230
264
|
}
|
|
265
|
+
if(jsObject == null) return;
|
|
266
|
+
notifyListeners(LEAP_CALLBACKS, jsObject);
|
|
267
|
+
|
|
231
268
|
};
|
|
232
269
|
Leap.setLeapEventCallbacks(leapEventListener);
|
|
233
270
|
}
|
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>",
|
|
@@ -133,6 +167,16 @@
|
|
|
133
167
|
"complexTypes": [],
|
|
134
168
|
"slug": "disable"
|
|
135
169
|
},
|
|
170
|
+
{
|
|
171
|
+
"name": "logout",
|
|
172
|
+
"signature": "() => Promise<void>",
|
|
173
|
+
"parameters": [],
|
|
174
|
+
"returns": "Promise<void>",
|
|
175
|
+
"tags": [],
|
|
176
|
+
"docs": "",
|
|
177
|
+
"complexTypes": [],
|
|
178
|
+
"slug": "logout"
|
|
179
|
+
},
|
|
136
180
|
{
|
|
137
181
|
"name": "setAppLocale",
|
|
138
182
|
"signature": "(options: { localeCode: string; }) => 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>;
|
|
@@ -33,6 +40,7 @@ export interface LeapPluginInterface {
|
|
|
33
40
|
projectIds: Array<string>;
|
|
34
41
|
}): Promise<void>;
|
|
35
42
|
disable(): Promise<void>;
|
|
43
|
+
logout(): Promise<void>;
|
|
36
44
|
setAppLocale(options: {
|
|
37
45
|
localeCode: string;
|
|
38
46
|
}): 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 logout(): 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);
|
|
@@ -13,4 +15,5 @@ CAP_PLUGIN(LeapPlugin, "LeapPlugin",
|
|
|
13
15
|
CAP_PLUGIN_METHOD(setAppLocale, CAPPluginReturnPromise);
|
|
14
16
|
CAP_PLUGIN_METHOD(offlineSync, CAPPluginReturnPromise);
|
|
15
17
|
CAP_PLUGIN_METHOD(disable, CAPPluginReturnPromise);
|
|
18
|
+
CAP_PLUGIN_METHOD(logout, CAPPluginReturnPromise);
|
|
16
19
|
)
|
|
@@ -2,6 +2,19 @@ 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
|
+
|
|
5
18
|
/**
|
|
6
19
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
20
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
@@ -11,7 +24,7 @@ import LeapSDK
|
|
|
11
24
|
public class LeapPlugin: CAPPlugin {
|
|
12
25
|
|
|
13
26
|
@objc public func start(_ call: CAPPluginCall) {
|
|
14
|
-
let apiKey = call.getString(
|
|
27
|
+
let apiKey = call.getString(API_KEY) ?? ""
|
|
15
28
|
DispatchQueue.main.async {
|
|
16
29
|
Leap.shared.start(apiKey)
|
|
17
30
|
Leap.shared.callback = self
|
|
@@ -20,62 +33,57 @@ public class LeapPlugin: CAPPlugin {
|
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
@objc public func startWithProperties(_ call: CAPPluginCall) {
|
|
23
|
-
let apiKey = call.getString(
|
|
24
|
-
let properties:[String:AnyHashable] = call.getObject(
|
|
25
|
-
DispatchQueue.main.async {
|
|
36
|
+
let apiKey = call.getString(API_KEY) ?? ""
|
|
37
|
+
let properties:[String:AnyHashable] = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
38
|
+
DispatchQueue.main.async {[weak self] in
|
|
26
39
|
let leapShared = Leap.shared.withBuilder(apiKey)
|
|
27
|
-
properties
|
|
28
|
-
if let stringValue = value as? String {
|
|
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
|
-
}
|
|
40
|
+
self?.addProperties(properties: properties)
|
|
41
41
|
leapShared?.start()
|
|
42
42
|
}
|
|
43
43
|
call.resolve()
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
@objc public func startWithSelfHostedURL(_ call:CAPPluginCall) {
|
|
47
|
+
if let baseUrl = call.getString(BASE_URL) {
|
|
48
|
+
DispatchQueue.main.async {
|
|
49
|
+
Leap.shared.withSelfHostedBuilder()?.setBaseUrl(baseUrl)?.start()
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
call.resolve()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@objc public func startWithSelfHostedURLAndProperties(_ call:CAPPluginCall) {
|
|
56
|
+
if let baseUrl = call.getString(BASE_URL) {
|
|
57
|
+
let properties = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
58
|
+
DispatchQueue.main.async {[weak self] in
|
|
59
|
+
Leap.shared.withSelfHostedBuilder()?.setBaseUrl(baseUrl)
|
|
60
|
+
self?.addProperties(properties: properties)
|
|
61
|
+
Leap.shared.start()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
call.resolve()
|
|
65
|
+
}
|
|
66
|
+
|
|
46
67
|
@objc public func flushProperties(_ call: CAPPluginCall) {
|
|
47
|
-
let properties:[String:AnyHashable] = call.getObject(
|
|
48
|
-
DispatchQueue.main.async {
|
|
68
|
+
let properties:[String:AnyHashable] = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
69
|
+
DispatchQueue.main.async {[weak self] in
|
|
49
70
|
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
|
-
}
|
|
71
|
+
self?.addProperties(properties: properties)
|
|
64
72
|
leapShared.flush()
|
|
65
73
|
}
|
|
66
74
|
call.resolve()
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
@objc public func setUniqueUserId(_ call: CAPPluginCall) {
|
|
70
|
-
let uniqueUserId = call.getString(
|
|
78
|
+
let uniqueUserId = call.getString(UNIQUE_USER_ID) ?? ""
|
|
71
79
|
DispatchQueue.main.async {
|
|
72
80
|
Leap.shared.setUniqueUserId(uniqueUserId)
|
|
73
81
|
}
|
|
74
82
|
call.resolve()
|
|
75
83
|
}
|
|
76
|
-
|
|
84
|
+
|
|
77
85
|
@objc public func setAppLocale(_ call: CAPPluginCall) {
|
|
78
|
-
let localeCode = call.getString(
|
|
86
|
+
let localeCode = call.getString(LOCALE_CODE) ?? ""
|
|
79
87
|
DispatchQueue.main.async {
|
|
80
88
|
Leap.shared.setAppLocale(localeCode)
|
|
81
89
|
}
|
|
@@ -83,8 +91,8 @@ public class LeapPlugin: CAPPlugin {
|
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
@objc public func startProject(_ call: CAPPluginCall) {
|
|
86
|
-
let projectId = call.getString(
|
|
87
|
-
let resetProject = call.getBool(
|
|
94
|
+
let projectId = call.getString(PROJECT_ID) ?? ""
|
|
95
|
+
let resetProject = call.getBool(RESET_PROJECT) ?? false
|
|
88
96
|
DispatchQueue.main.async {
|
|
89
97
|
Leap.shared.startProject(projectId, resetProject: resetProject)
|
|
90
98
|
}
|
|
@@ -92,7 +100,7 @@ public class LeapPlugin: CAPPlugin {
|
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
@objc public func embedProject(_ call: CAPPluginCall) {
|
|
95
|
-
let projectId = call.getString(
|
|
103
|
+
let projectId = call.getString(PROJECT_ID) ?? ""
|
|
96
104
|
DispatchQueue.main.async {
|
|
97
105
|
Leap.shared.embedProject(projectId)
|
|
98
106
|
}
|
|
@@ -100,7 +108,7 @@ public class LeapPlugin: CAPPlugin {
|
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
@objc public func offlineSync(_ call: CAPPluginCall) {
|
|
103
|
-
let projectIds = call.getArray(
|
|
111
|
+
let projectIds = call.getArray(PROJECT_IDS)?.capacitor.replacingNullValues() as? [String] ?? []
|
|
104
112
|
DispatchQueue.main.async {
|
|
105
113
|
Leap.shared.offlineSync(projectIds)
|
|
106
114
|
}
|
|
@@ -114,10 +122,34 @@ public class LeapPlugin: CAPPlugin {
|
|
|
114
122
|
call.resolve()
|
|
115
123
|
}
|
|
116
124
|
|
|
125
|
+
@objc public func logout(_ call: CAPPluginCall) {
|
|
126
|
+
DispatchQueue.main.async {
|
|
127
|
+
Leap.shared.logout()
|
|
128
|
+
}
|
|
129
|
+
call.resolve()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func addProperties(properties:[String:AnyHashable]) {
|
|
133
|
+
properties.forEach { key, value in
|
|
134
|
+
if let stringValue = value as? String {
|
|
135
|
+
if stringValue.hasPrefix(DATE_PREFIX) {
|
|
136
|
+
let dateValue = stringValue.components(separatedBy: DATE_PREFIX).last ?? ""
|
|
137
|
+
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
138
|
+
Leap.shared.addProperty(key, dateValue: date)
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
Leap.shared.addProperty(key, stringValue: stringValue)
|
|
142
|
+
}
|
|
143
|
+
} else if let intValue = value as? Int {
|
|
144
|
+
Leap.shared.addProperty(key, intValue: intValue)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
117
149
|
func getDateFromISOString(dateString:String) -> Date? {
|
|
118
150
|
let formatter = DateFormatter()
|
|
119
|
-
formatter.dateFormat =
|
|
120
|
-
let posix:Locale = Locale(identifier:
|
|
151
|
+
formatter.dateFormat = DATE_FORMAT
|
|
152
|
+
let posix:Locale = Locale(identifier: DATE_LOCALE)
|
|
121
153
|
formatter.locale = posix
|
|
122
154
|
let date = formatter.date(from: dateString)
|
|
123
155
|
return date
|
|
@@ -128,7 +160,7 @@ extension LeapPlugin: LeapCallback {
|
|
|
128
160
|
|
|
129
161
|
public func eventNotification(eventInfo: Dictionary<String, Any>) {
|
|
130
162
|
DispatchQueue.main.async { [weak self] in
|
|
131
|
-
self?.notifyListeners(
|
|
163
|
+
self?.notifyListeners(LEAP_CALLBACKS, data: eventInfo)
|
|
132
164
|
}
|
|
133
165
|
}
|
|
134
166
|
}
|