@aigens/aigens-sdk-core 0.5.4 → 5.0.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.
@@ -1,6 +1,8 @@
1
1
  package com.aigens.sdk;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.content.ClipData;
5
+ import android.content.ClipboardManager;
4
6
  import android.content.Intent;
5
7
  import android.content.pm.ApplicationInfo;
6
8
  import android.content.res.AssetManager;
@@ -34,6 +36,7 @@ import com.getcapacitor.BridgeActivity;
34
36
  import com.getcapacitor.BridgeWebViewClient;
35
37
  import com.getcapacitor.CapConfig;
36
38
  import com.getcapacitor.JSExport;
39
+ import com.getcapacitor.JSObject;
37
40
  import com.getcapacitor.Logger;
38
41
  import com.getcapacitor.NativePlugin;
39
42
  import com.getcapacitor.Plugin;
@@ -97,6 +100,10 @@ public class WebContainerActivity extends BridgeActivity {
97
100
  add("aigenshkfps/true");
98
101
  }};
99
102
 
103
+ static List<String> exitUniversalLinks = new ArrayList<String>() {{
104
+ // add("phhkdownloadapp=true&requireMember");
105
+ }};
106
+
100
107
  private void debug(Object... msgs) {
101
108
 
102
109
 
@@ -117,6 +124,23 @@ public class WebContainerActivity extends BridgeActivity {
117
124
  return false;
118
125
  }
119
126
 
127
+ private boolean isExitUniversalLink() {
128
+ CorePlugin corePlugin = CorePlugin.getCoreInstance();
129
+ if (corePlugin == null || WebContainerActivity.exitUniversalLinks.size() == 0) return false;
130
+ JSObject object = corePlugin._readClipboard();
131
+ String url = object.getString("value");
132
+ // Log.i("Jason","onNewIntent 2"+url);
133
+ for (String p : WebContainerActivity.exitUniversalLinks) {
134
+ if (url != null && url != "" && url.contains(p)) {
135
+ corePlugin.forceDismiss();
136
+ return true;
137
+ }
138
+ }
139
+ return false;
140
+ }
141
+
142
+
143
+
120
144
  private String getRedirectUrl(Intent intent) {
121
145
  try {
122
146
  // Intent intent = getIntent();
@@ -139,6 +163,7 @@ public class WebContainerActivity extends BridgeActivity {
139
163
  if (isExcludedUniversalLink(totalUrl)) {
140
164
  return null;
141
165
  }
166
+
142
167
  // Log.i("Jason totalUrl", totalUrl+universalLink);
143
168
  if (totalUrl != null && totalUrl.indexOf("redirect=") >= 0) {
144
169
  redirectUrl = totalUrl.split("redirect=")[1];
@@ -167,6 +192,33 @@ public class WebContainerActivity extends BridgeActivity {
167
192
 
168
193
  }
169
194
 
195
+ @Override
196
+ public void onResume() {
197
+ super.onResume();
198
+
199
+ // Log.i("Jason","onNewIntent 1");
200
+ new Handler().postDelayed(() -> {
201
+ if (getWindow().getDecorView().hasFocus()) {
202
+ // Log.i("Jason","onNewIntent 2.1");
203
+ isExitUniversalLink();
204
+ } else {
205
+ // 强制请求焦点
206
+ getWindow().getDecorView().requestFocus();
207
+ getWindow().getDecorView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
208
+ @Override
209
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
210
+ int oldLeft, int oldTop, int oldRight, int oldBottom) {
211
+ if (v.hasFocus()) {
212
+ // Log.i("Jason","onNewIntent 2.3");
213
+ isExitUniversalLink();
214
+ v.removeOnLayoutChangeListener(this);
215
+ }
216
+ }
217
+ });
218
+ }
219
+ }, 300);
220
+ // Log.i("Jason","onNewIntent 2");
221
+ }
170
222
 
171
223
  @Override
172
224
  protected void onNewIntent(Intent intent) {
@@ -201,9 +253,10 @@ public class WebContainerActivity extends BridgeActivity {
201
253
 
202
254
  super.onCreate(currentInstanceState);
203
255
 
256
+ setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
257
+
204
258
  addChannel();
205
259
 
206
- setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
207
260
 
208
261
  Intent intent = getIntent();
209
262
 
@@ -249,6 +302,13 @@ public class WebContainerActivity extends BridgeActivity {
249
302
  }
250
303
  }
251
304
 
305
+ List<String> exitUniversalLinks = (List<String>) intent.getSerializableExtra("exitUniversalLinks");
306
+ if (exitUniversalLinks != null) {
307
+ for (String s : exitUniversalLinks) {
308
+ WebContainerActivity.exitUniversalLinks.add(s);
309
+ }
310
+ }
311
+
252
312
  if (this.member != null) {
253
313
  CorePlugin.setMember(this.member);
254
314
  }
@@ -505,12 +565,25 @@ public class WebContainerActivity extends BridgeActivity {
505
565
  }
506
566
 
507
567
  View info = findViewById(R.id.info);
508
- info.setVisibility(showInfo ? View.VISIBLE : View.INVISIBLE);
568
+ if (info == null) {
569
+ setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
570
+ info = findViewById(R.id.info);
571
+ }
572
+
573
+ if (info != null) {
574
+ info.setVisibility(showInfo ? View.VISIBLE : View.INVISIBLE);
575
+ }
576
+
509
577
 
510
578
  View error = findViewById(R.id.error);
511
- error.setVisibility(showError ? View.VISIBLE : View.INVISIBLE);
579
+ if (error != null) {
580
+ error.setVisibility(showError ? View.VISIBLE : View.INVISIBLE);
581
+ }
582
+
583
+ if (bridge.getWebView() != null) {
584
+ bridge.getWebView().setVisibility(showWeb ? View.VISIBLE : View.INVISIBLE);
585
+ }
512
586
 
513
- bridge.getWebView().setVisibility(showWeb ? View.VISIBLE : View.INVISIBLE);
514
587
 
515
588
 
516
589
  }
@@ -13,8 +13,10 @@ import android.content.pm.PackageInfo;
13
13
  import android.content.pm.PackageManager;
14
14
  import android.net.Uri;
15
15
  import android.os.Build;
16
+ import android.os.Bundle;
16
17
  import android.os.Handler;
17
18
  import android.util.ArrayMap;
19
+ import android.util.Log;
18
20
  import android.view.View;
19
21
  import android.view.ViewGroup;
20
22
  import android.webkit.WebSettings;
@@ -24,21 +26,26 @@ import androidx.activity.result.ActivityResult;
24
26
  import androidx.core.app.NotificationManagerCompat;
25
27
 
26
28
  import com.aigens.sdk.WebContainerActivity;
29
+ import com.getcapacitor.Bridge;
27
30
  import com.getcapacitor.JSArray;
28
31
  import com.getcapacitor.JSObject;
29
32
  import com.getcapacitor.PermissionState;
30
33
  import com.getcapacitor.Plugin;
31
34
  import com.getcapacitor.PluginCall;
35
+ import com.getcapacitor.PluginHandle;
32
36
  import com.getcapacitor.PluginMethod;
33
37
  import com.getcapacitor.annotation.ActivityCallback;
34
38
  import com.getcapacitor.annotation.CapacitorPlugin;
35
39
  import com.getcapacitor.annotation.Permission;
36
40
  import com.getcapacitor.annotation.PermissionCallback;
37
41
 
42
+ import org.json.JSONArray;
38
43
  import org.json.JSONException;
44
+ import org.json.JSONObject;
39
45
 
40
46
  import java.io.Serializable;
41
47
  import java.lang.reflect.Field;
48
+ import java.lang.reflect.Method;
42
49
  import java.util.HashMap;
43
50
  import java.util.Iterator;
44
51
  import java.util.List;
@@ -49,16 +56,23 @@ import java.util.TimeZone;
49
56
  @CapacitorPlugin(
50
57
  name = "Core",
51
58
  permissions = {
52
- @Permission(strings = { Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR }, alias = CorePlugin.CALENDAR_PERMISSION),
59
+ @Permission(strings = {Manifest.permission.READ_CALENDAR, Manifest.permission.WRITE_CALENDAR}, alias = CorePlugin.CALENDAR_PERMISSION),
53
60
  }
54
61
  )
55
62
  public class CorePlugin extends Plugin {
56
63
 
57
64
  static final String CALENDAR_PERMISSION = "calendarPermission";
65
+
58
66
  public interface CoreListener {
59
67
  public boolean isInterceptedUrl(String url, WebView view, Activity activity);
60
68
  }
69
+
70
+ public interface AnalyticsListener {
71
+ public void logEvent(String name, Bundle parameters);
72
+ }
73
+
61
74
  static public CoreListener coreListener;
75
+ static public AnalyticsListener analyticsListener;
62
76
  public static final int REQUEST_CODE_OPEN_URL = 100001;
63
77
 
64
78
  public static boolean DEBUG = false;
@@ -66,6 +80,7 @@ public class CorePlugin extends Plugin {
66
80
  private static Map member;
67
81
  private static Map deeplink;
68
82
  private static boolean ENVIRONMENT_PRODUCTION = true;
83
+
69
84
  private void debug(Object msg) {
70
85
 
71
86
  if (DEBUG) {
@@ -90,6 +105,25 @@ public class CorePlugin extends Plugin {
90
105
  CorePlugin.ENVIRONMENT_PRODUCTION = ENVIRONMENT_PRODUCTION;
91
106
  }
92
107
 
108
+ public static Bridge staticBridge = null;
109
+
110
+ public static CorePlugin getCoreInstance() {
111
+ if (staticBridge != null && staticBridge.getWebView() != null) {
112
+ PluginHandle handle = staticBridge.getPlugin("Core");
113
+ if (handle == null) {
114
+ return null;
115
+ }
116
+ return (CorePlugin) handle.getInstance();
117
+ }
118
+ return null;
119
+ }
120
+
121
+ @Override
122
+ public void load() {
123
+ super.load();
124
+ staticBridge = this.bridge;
125
+ }
126
+
93
127
  @Override
94
128
  protected void handleOnStart() {
95
129
 
@@ -141,6 +175,31 @@ public class CorePlugin extends Plugin {
141
175
  // barcodeLauncher.launch(new ScanOptions());
142
176
  //}
143
177
 
178
+ public void forceDismiss() {
179
+ JSObject options = new JSObject();
180
+ if (options != null) {
181
+ Intent data = new Intent();
182
+ data.putExtra("closedData", options.toString());
183
+ getActivity().setResult(Activity.RESULT_OK, data);
184
+
185
+ try {
186
+ if (dismissCall != null) {
187
+ JSObject result = new JSObject();
188
+ result.put("closedData", options);
189
+ dismissCall.resolve(result);
190
+ dismissCall = null;
191
+ }
192
+ } catch (Exception e) {
193
+ e.printStackTrace();
194
+ }
195
+ }
196
+
197
+ if (getActivity() != null) {
198
+ getActivity().finish();
199
+ }
200
+
201
+ }
202
+
144
203
  @PluginMethod()
145
204
  public void finish(PluginCall call) {
146
205
 
@@ -155,6 +214,7 @@ public class CorePlugin extends Plugin {
155
214
  JSObject result = new JSObject();
156
215
  result.put("closedData", options);
157
216
  dismissCall.resolve(result);
217
+ dismissCall = null;
158
218
  }
159
219
  } catch (Exception e) {
160
220
  e.printStackTrace();
@@ -170,7 +230,7 @@ public class CorePlugin extends Plugin {
170
230
  @PluginMethod()
171
231
  public void dismiss(PluginCall call) {
172
232
 
173
- JSObject options = call.getObject("closedData");
233
+ JSObject options = call.getObject("closedData", new JSObject());
174
234
  if (options != null) {
175
235
  Intent data = new Intent();
176
236
  data.putExtra("closedData", options.toString());
@@ -181,6 +241,7 @@ public class CorePlugin extends Plugin {
181
241
  JSObject result = new JSObject();
182
242
  result.put("closedData", options);
183
243
  dismissCall.resolve(result);
244
+ dismissCall = null;
184
245
  }
185
246
  } catch (Exception e) {
186
247
  e.printStackTrace();
@@ -194,6 +255,128 @@ public class CorePlugin extends Plugin {
194
255
 
195
256
  }
196
257
 
258
+ private static Method logEventMethod;
259
+ private static Object analyticsInstance;
260
+
261
+ public static void initFirebaseAnalytics(Context context) {
262
+ try {
263
+ if (logEventMethod != null && analyticsInstance != null) return;
264
+ Class<?> clazz = Class.forName("com.google.firebase.analytics.FirebaseAnalytics");
265
+ Method getInstance = clazz.getMethod("getInstance", Context.class);
266
+ logEventMethod = clazz.getMethod("logEvent", String.class, Bundle.class);
267
+ analyticsInstance = getInstance.invoke(null, context);
268
+ } catch (Exception e) {
269
+ Log.e("CorePlugin", "initFirebaseAnalytics Error", e);
270
+ }
271
+ }
272
+
273
+ public static void trackEvent(Context context, String eventName, Bundle params) {
274
+ CorePlugin.initFirebaseAnalytics(context);
275
+ if (logEventMethod == null || analyticsInstance == null) {
276
+ Log.i("CorePlugin", "FirebaseAnalytics trackEvent failure");
277
+ return;
278
+ }
279
+ try {
280
+ logEventMethod.invoke(analyticsInstance, eventName, params);
281
+ Log.i("CorePlugin", "trackEvent successful");
282
+ } catch (Exception e) {
283
+ Log.e("CorePlugin", "FirebaseAnalytics trackEvent Error", e);
284
+ }
285
+ }
286
+
287
+ private void callTracking(String name, Bundle bundle) {
288
+ if (CorePlugin.analyticsListener != null) {
289
+ CorePlugin.analyticsListener.logEvent(name, bundle);
290
+ return;
291
+ }
292
+
293
+ CorePlugin.trackEvent(getContext(), name, bundle);
294
+ }
295
+
296
+ private static Bundle convertJsonToBundle(JSONObject json) {
297
+ Bundle bundle = new Bundle();
298
+ if (json == null || json.length() == 0) return bundle;
299
+
300
+ Iterator<String> iterator = json.keys();
301
+ while (iterator.hasNext()) {
302
+ String key = (String) iterator.next();
303
+ try {
304
+ Object value = json.get(key);
305
+ if (value == null);
306
+ else if (value instanceof String) bundle.putString(key, (String) value);
307
+ else if (value instanceof Boolean) bundle.putBoolean(key, (Boolean) value);
308
+ else if (value instanceof Integer) bundle.putInt(key, (Integer) value);
309
+ else if (value instanceof Long) bundle.putLong(key, (Long) value);
310
+ else if (value instanceof Float) bundle.putFloat(key, (Float) value);
311
+ else if (value instanceof Double) bundle.putDouble(key, (Double) value);
312
+ else if (value instanceof JSONObject) bundle.putBundle(key, CorePlugin.convertJsonToBundle((JSONObject) value));
313
+ else if (value instanceof JSONArray) {
314
+ JSONArray array = (JSONArray) value;
315
+ Object first = array.length() == 0 ? null : (Object) array.get(0);
316
+ if (first == null);
317
+ else if (first instanceof JSONObject) {
318
+ Bundle[] items = new Bundle[array.length()];
319
+ for (int i = 0; i < array.length(); i++) items[i] = CorePlugin.convertJsonToBundle(array.getJSONObject(i));
320
+ bundle.putParcelableArray(key, items);
321
+ } else if (first instanceof String) {
322
+ String[] items = new String[array.length()];
323
+ for (int i = 0; i < array.length(); i++) items[i] = array.getString(i);
324
+ bundle.putStringArray(key, items);
325
+ } else if (first instanceof Integer || first instanceof Float || first instanceof Double) {
326
+ float[] items = new float[array.length()];
327
+ for (int i = 0; i < array.length(); i++) {
328
+ items[i] = ((Number) array.get(i)).floatValue();
329
+ }
330
+ bundle.putFloatArray(key, items);
331
+ }
332
+ }
333
+ } catch (ClassCastException | JSONException e) {
334
+ e.printStackTrace();
335
+ }
336
+ }
337
+
338
+ return bundle;
339
+ }
340
+
341
+ @PluginMethod
342
+ public void setScreenName(PluginCall call) {
343
+
344
+ try {
345
+ String screenName = call.getString("name", null);
346
+
347
+ if (screenName == null) {
348
+ call.resolve();
349
+ return;
350
+ }
351
+ bridge.getActivity().runOnUiThread(new Runnable() {
352
+ @Override
353
+ public void run() {
354
+ Bundle bundle = new Bundle();
355
+ bundle.putString("screen_name", screenName);
356
+ callTracking("screen_view", bundle);
357
+ }
358
+ });
359
+ call.resolve();
360
+ } catch (Exception ex) {
361
+ call.reject(ex.getLocalizedMessage());
362
+ }
363
+ }
364
+
365
+ @PluginMethod
366
+ public void logEvent(PluginCall call) {
367
+ String name = call.getString("name", null);
368
+
369
+ if (name == null) {
370
+ call.resolve();
371
+ return;
372
+ }
373
+
374
+ JSONObject params = call.getData().getJSObject("params");
375
+ Bundle bundle = params != null ? CorePlugin.convertJsonToBundle(params) : null;
376
+ callTracking(name, bundle);
377
+ call.resolve();
378
+ }
379
+
197
380
  private static PluginCall dismissCall;
198
381
  @PluginMethod
199
382
  public void getFinishData(PluginCall call) {
@@ -210,6 +393,8 @@ public class CorePlugin extends Plugin {
210
393
 
211
394
  String url = call.getString("url");
212
395
 
396
+ // url = "http://192.168.1.105:11111/order/store/967302003724288/mode/takeaway?brandId=599961624702976";
397
+
213
398
  if (url == null) return;
214
399
 
215
400
  JSObject options = call.getObject("options", null);
@@ -273,6 +458,16 @@ public class CorePlugin extends Plugin {
273
458
  e.printStackTrace();
274
459
  }
275
460
 
461
+ JSArray exitUniversalLinks = call.getArray("exitUniversalLinks");
462
+ try {
463
+ if (exitUniversalLinks != null) {
464
+ List<String> es = exitUniversalLinks.toList();
465
+ intent.putExtra("exitUniversalLinks", (Serializable) es);
466
+ }
467
+ } catch (JSONException e) {
468
+ e.printStackTrace();
469
+ }
470
+
276
471
  intent.putExtra("url", url);
277
472
  intent.putExtra("clearCache", clearCache);
278
473
  intent.putExtra("member", (Serializable) memMap);
@@ -344,7 +539,7 @@ public class CorePlugin extends Plugin {
344
539
  try {
345
540
  if (areNotificationsEnabled) {
346
541
  object.put("display", "granted");
347
- }else {
542
+ } else {
348
543
  object.put("display", "denied");
349
544
  }
350
545
  } catch (Exception e) {
@@ -380,7 +575,7 @@ public class CorePlugin extends Plugin {
380
575
  endTime + TimeZone.getDefault().getOffset(endTime));
381
576
  }
382
577
  calIntent.putExtra("eventTimezone", "TIMEZONE_UTC");
383
- }else {
578
+ } else {
384
579
  if (beginTime != null) {
385
580
  calIntent.putExtra("beginTime", beginTime);
386
581
  }
@@ -411,6 +606,7 @@ public class CorePlugin extends Plugin {
411
606
  call.resolve(ret);
412
607
  // Do something with the result data
413
608
  }
609
+
414
610
  @PluginMethod()
415
611
  public void addCalendar(PluginCall call) {
416
612
  if (getPermissionState(CorePlugin.CALENDAR_PERMISSION) != PermissionState.GRANTED) {
@@ -443,7 +639,7 @@ public class CorePlugin extends Plugin {
443
639
  int rounded = (int) Math.round(value * 100);
444
640
  settings.setTextZoom(rounded);
445
641
  });
446
- }catch (Exception e) {
642
+ } catch (Exception e) {
447
643
  e.printStackTrace();
448
644
  }
449
645
 
@@ -452,8 +648,7 @@ public class CorePlugin extends Plugin {
452
648
 
453
649
  }
454
650
 
455
- @PluginMethod
456
- public void readClipboard(PluginCall call) {
651
+ public JSObject _readClipboard() {
457
652
  JSObject object = new JSObject();
458
653
  try {
459
654
  ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
@@ -494,6 +689,12 @@ public class CorePlugin extends Plugin {
494
689
  object.put("type", "text/plain");
495
690
  e.printStackTrace();
496
691
  }
692
+ return object;
693
+ }
694
+
695
+ @PluginMethod
696
+ public void readClipboard(PluginCall call) {
697
+ JSObject object = _readClipboard();
497
698
  call.resolve(object);
498
699
  }
499
700
 
@@ -20,6 +20,10 @@ CAP_PLUGIN(CorePlugin, "Core",
20
20
  CAP_PLUGIN_METHOD(readClipboard, CAPPluginReturnPromise);
21
21
  CAP_PLUGIN_METHOD(addCalendar, CAPPluginReturnPromise);
22
22
  CAP_PLUGIN_METHOD(makeHKFPSPayment, CAPPluginReturnPromise);
23
+ CAP_PLUGIN_METHOD(setScreenName, CAPPluginReturnPromise);
24
+ CAP_PLUGIN_METHOD(logEvent, CAPPluginReturnPromise);
25
+
26
+
23
27
 
24
28
 
25
29
  )
@@ -12,6 +12,10 @@ import EventKitUI
12
12
  func isInterceptedUrl(url: URL, webview: WKWebView) -> Bool
13
13
  }
14
14
 
15
+ @objc public protocol AnalyticsDelegate: AnyObject {
16
+ func logEvent(_ name: String, parameters: Dictionary<String, Any>?)
17
+ }
18
+
15
19
  var aigensDebug = false;
16
20
  /**
17
21
  * Please read the Capacitor iOS Plugin Development Guide
@@ -21,6 +25,7 @@ var aigensDebug = false;
21
25
  public class CorePlugin: CAPPlugin {
22
26
 
23
27
  static public var coreDelegate: CoreDelegate?
28
+ static public var analyticsDelegate: AnalyticsDelegate?
24
29
 
25
30
  public static let shared = CorePlugin()
26
31
  private let implementation = Core()
@@ -204,6 +209,16 @@ public class CorePlugin: CAPPlugin {
204
209
 
205
210
  }
206
211
 
212
+ public func forceDismiss() {
213
+ let r = ["closedData": [:]]
214
+ WebContainerViewController.closeCB?(r)
215
+ CorePlugin.dismissCall?.resolve(r)
216
+ CorePlugin.dismissCall = nil
217
+ DispatchQueue.main.async {
218
+ self.bridge?.viewController?.dismiss(animated: true);
219
+ }
220
+ }
221
+
207
222
  @objc func dismiss(_ call: CAPPluginCall) {
208
223
 
209
224
  aigensprint("CorePlugin dismiss")
@@ -224,7 +239,82 @@ public class CorePlugin: CAPPlugin {
224
239
  "success": true
225
240
  //"value": implementation.echo(value)
226
241
  ])
242
+ CorePlugin.dismissCall = nil
243
+
244
+
245
+ }
246
+
247
+ @objc func setScreenName(_ call: CAPPluginCall) {
248
+ if let screenName = call.getString("name") {
249
+ DispatchQueue.main.async {
250
+ self.trackEvent("screen_view", parameters: ["screen_name": screenName])
251
+ }
252
+ call.resolve()
253
+ } else {
254
+ call.resolve()
255
+ }
256
+
257
+ }
258
+
259
+ private func _logEvent(name: String, params: [String: Any]) -> Bool {
260
+
261
+ guard let analyticsClass = NSClassFromString("FirebaseAnalytics.FIRAnalytics") ?? NSClassFromString("FirebaseAnalytics.Analytics") ?? NSClassFromString("FIRAnalytics") ?? NSClassFromString("Analytics") else {
262
+ return false
263
+ }
264
+
265
+ let selector = NSSelectorFromString("logEventWithName:parameters:")
266
+
267
+ guard analyticsClass.responds(to: selector) else { return false }
268
+
269
+ let arguments: [Any] = [name, params]
270
+
271
+ _ = analyticsClass.perform(selector, with: arguments, afterDelay: 0)
272
+ print("CorePlugin logEvent")
273
+ return true
274
+ }
275
+
276
+ private func trackEvent(_ name: String, parameters: Dictionary<String, Any>?) {
277
+ if let del = CorePlugin.analyticsDelegate {
278
+ del.logEvent(name, parameters: parameters)
279
+ return;
280
+ }
281
+ _ = _logEvent(name: name, params: parameters ?? [:])
282
+ }
283
+
284
+ @objc func logEvent(_ call: CAPPluginCall) {
285
+ guard let name = call.getString("name"), !name.isEmpty else {
286
+ call.reject("Event name is required and can't be empty")
287
+ return
288
+ }
289
+
290
+ /// logEvent() expects `nil` when there are no parameters
291
+ guard var params = call.getObject("params"), !params.isEmpty else {
292
+ trackEvent(name, parameters: nil)
293
+ call.resolve()
294
+ return
295
+ }
296
+
297
+ /// FirebaseAnalytics silently converts any item quantity that is not an
298
+ /// integer to zero, this includes any NSNumber or string value passed
299
+ /// as an option to CAPPluginCall.
300
+ if var items = params["items"] as? NSArray as? [[String:Any]] {
301
+ for (idx, item) in items.enumerated() {
302
+ if let quantity = item["quantity"] {
303
+ guard let intVal = quantity as? Int else {
304
+ call.resolve()
305
+ return
306
+ }
307
+ items[idx]["quantity"] = intVal
308
+ }
309
+ }
310
+ params["items"] = items
311
+ }
227
312
 
313
+ if let extendSession = params["extendSession"] as? NSNumber, extendSession == 1 {
314
+ params["extendSession"] = true
315
+ }
316
+ trackEvent(name, parameters: params)
317
+ call.resolve()
228
318
 
229
319
  }
230
320
 
@@ -260,6 +350,7 @@ public class CorePlugin: CAPPlugin {
260
350
  "success": true
261
351
  //"value": implementation.echo(value)
262
352
  ])
353
+ CorePlugin.dismissCall = nil
263
354
  }
264
355
 
265
356
  private static var dismissCall: CAPPluginCall?
@@ -320,6 +411,7 @@ public class CorePlugin: CAPPlugin {
320
411
  let externalProtocols = call.getArray("externalProtocols")
321
412
  let addPaddingProtocols = call.getArray("addPaddingProtocols")
322
413
  let excludedUniversalLinks = call.getArray("excludedUniversalLinks")
414
+ let exitUniversalLinks = call.getArray("exitUniversalLinks")
323
415
 
324
416
  let clearCache = call.getBool("clearCache") ?? false
325
417
  aigensDebug = call.getBool("debug") ?? false
@@ -349,6 +441,9 @@ public class CorePlugin: CAPPlugin {
349
441
  if (excludedUniversalLinks != nil) {
350
442
  options["excludedUniversalLinks"] = excludedUniversalLinks as AnyObject
351
443
  }
444
+ if (exitUniversalLinks != nil) {
445
+ options["exitUniversalLinks"] = exitUniversalLinks as AnyObject
446
+ }
352
447
 
353
448
  bridgeVC.options = options;
354
449
 
@@ -510,9 +605,16 @@ public class CorePlugin: CAPPlugin {
510
605
  return str;
511
606
  }
512
607
 
513
- @objc func readClipboard(_ call: CAPPluginCall) {
608
+ public func _readClipboard() -> [String: Any]?{
514
609
  if UIPasteboard.general.hasImages, let image = UIPasteboard.general.image, let str = getStringFromQr(image) {
515
- call.resolve(["value": str, "type": "text/plain"])
610
+ return ["value": str, "type": "text/plain"]
611
+ }
612
+ return nil
613
+ }
614
+
615
+ @objc func readClipboard(_ call: CAPPluginCall) {
616
+ if let obj = _readClipboard() {
617
+ call.resolve(obj)
516
618
  return
517
619
  }
518
620
  call.resolve(["value": "", "type": ""])
@@ -569,5 +671,3 @@ extension CorePlugin: EKEventEditViewDelegate {
569
671
  }
570
672
  }
571
673
  #endif
572
-
573
-
@@ -44,6 +44,9 @@ import Capacitor
44
44
  "aigenshkfps=true",
45
45
  "aigenshkfps/true"
46
46
  ]
47
+ var exitUniversalLinks: [String] = [
48
+ // "phhkdownloadapp=true&requireMember"
49
+ ]
47
50
 
48
51
  let containerView = WebContainer.webContainer()
49
52
  var webContainerView: WebContainer {
@@ -135,6 +138,15 @@ import Capacitor
135
138
  NotificationCenter.default.addObserver(self, selector: #selector(self.handleUniversalLink(notification:)), name: Notification.Name.capacitorOpenUniversalLink, object: nil)
136
139
 
137
140
  NotificationCenter.default.addObserver(self, selector: #selector(self.handleUrlOpened(notification:)), name: Notification.Name.capacitorOpenURL, object: nil)
141
+
142
+ NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: OperationQueue.main) { [weak self] (_) in
143
+ if let this = self, let core = CorePlugin.getCoreInstance(), this.exitUniversalLinks.count > 0, let obj = core._readClipboard(), let value = obj["value"] as? String {
144
+ if this.isExitUniversalLinks(value) {
145
+ core.forceDismiss()
146
+ }
147
+ }
148
+
149
+ }
138
150
  }
139
151
 
140
152
  private func isExcludedUniversalLink(_ url: String) -> Bool {
@@ -148,6 +160,17 @@ import Capacitor
148
160
  return result
149
161
  }
150
162
 
163
+ private func isExitUniversalLinks(_ url: String) -> Bool {
164
+ var result = false
165
+
166
+ exitUniversalLinks.forEach { (url_) in
167
+ if url.contains(url_) {
168
+ result = true
169
+ }
170
+ }
171
+ return result
172
+ }
173
+
151
174
  private func isParseUrl(_ url: String) -> Bool {
152
175
 
153
176
  if isExcludedUniversalLink(url) {
@@ -289,6 +312,10 @@ import Capacitor
289
312
  self.excludedUniversalLinks.append(contentsOf: excludedUniversalLinks)
290
313
  }
291
314
 
315
+ if let exitUniversalLinks = options?["exitUniversalLinks"] as? [String] {
316
+ self.exitUniversalLinks.append(contentsOf: exitUniversalLinks)
317
+ }
318
+
292
319
  }
293
320
 
294
321
  private func decodeURIComponent(_ url: URL) -> URL {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigens/aigens-sdk-core",
3
- "version": "0.5.4",
3
+ "version": "5.0.0",
4
4
  "description": "Aigens Order.Place Core Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",