@aigens/aigens-sdk-core 0.5.3 → 0.5.5

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
  }
@@ -14,6 +14,8 @@ import android.content.pm.PackageManager;
14
14
  import android.net.Uri;
15
15
  import android.os.Build;
16
16
  import android.os.Handler;
17
+ import android.util.ArrayMap;
18
+ import android.util.Log;
17
19
  import android.view.View;
18
20
  import android.view.ViewGroup;
19
21
  import android.webkit.WebSettings;
@@ -23,11 +25,13 @@ import androidx.activity.result.ActivityResult;
23
25
  import androidx.core.app.NotificationManagerCompat;
24
26
 
25
27
  import com.aigens.sdk.WebContainerActivity;
28
+ import com.getcapacitor.Bridge;
26
29
  import com.getcapacitor.JSArray;
27
30
  import com.getcapacitor.JSObject;
28
31
  import com.getcapacitor.PermissionState;
29
32
  import com.getcapacitor.Plugin;
30
33
  import com.getcapacitor.PluginCall;
34
+ import com.getcapacitor.PluginHandle;
31
35
  import com.getcapacitor.PluginMethod;
32
36
  import com.getcapacitor.annotation.ActivityCallback;
33
37
  import com.getcapacitor.annotation.CapacitorPlugin;
@@ -37,6 +41,7 @@ import com.getcapacitor.annotation.PermissionCallback;
37
41
  import org.json.JSONException;
38
42
 
39
43
  import java.io.Serializable;
44
+ import java.lang.reflect.Field;
40
45
  import java.util.HashMap;
41
46
  import java.util.Iterator;
42
47
  import java.util.List;
@@ -88,6 +93,25 @@ public class CorePlugin extends Plugin {
88
93
  CorePlugin.ENVIRONMENT_PRODUCTION = ENVIRONMENT_PRODUCTION;
89
94
  }
90
95
 
96
+ public static Bridge staticBridge = null;
97
+
98
+ public static CorePlugin getCoreInstance() {
99
+ if (staticBridge != null && staticBridge.getWebView() != null) {
100
+ PluginHandle handle = staticBridge.getPlugin("Core");
101
+ if (handle == null) {
102
+ return null;
103
+ }
104
+ return (CorePlugin) handle.getInstance();
105
+ }
106
+ return null;
107
+ }
108
+
109
+ @Override
110
+ public void load() {
111
+ super.load();
112
+ staticBridge = this.bridge;
113
+ }
114
+
91
115
  @Override
92
116
  protected void handleOnStart() {
93
117
 
@@ -139,6 +163,31 @@ public class CorePlugin extends Plugin {
139
163
  // barcodeLauncher.launch(new ScanOptions());
140
164
  //}
141
165
 
166
+ public void forceDismiss() {
167
+ JSObject options = new JSObject();
168
+ if (options != null) {
169
+ Intent data = new Intent();
170
+ data.putExtra("closedData", options.toString());
171
+ getActivity().setResult(Activity.RESULT_OK, data);
172
+
173
+ try {
174
+ if (dismissCall != null) {
175
+ JSObject result = new JSObject();
176
+ result.put("closedData", options);
177
+ dismissCall.resolve(result);
178
+ dismissCall = null;
179
+ }
180
+ } catch (Exception e) {
181
+ e.printStackTrace();
182
+ }
183
+ }
184
+
185
+ if (getActivity() != null) {
186
+ getActivity().finish();
187
+ }
188
+
189
+ }
190
+
142
191
  @PluginMethod()
143
192
  public void finish(PluginCall call) {
144
193
 
@@ -153,6 +202,7 @@ public class CorePlugin extends Plugin {
153
202
  JSObject result = new JSObject();
154
203
  result.put("closedData", options);
155
204
  dismissCall.resolve(result);
205
+ dismissCall = null;
156
206
  }
157
207
  } catch (Exception e) {
158
208
  e.printStackTrace();
@@ -168,7 +218,7 @@ public class CorePlugin extends Plugin {
168
218
  @PluginMethod()
169
219
  public void dismiss(PluginCall call) {
170
220
 
171
- JSObject options = call.getObject("closedData");
221
+ JSObject options = call.getObject("closedData", new JSObject());
172
222
  if (options != null) {
173
223
  Intent data = new Intent();
174
224
  data.putExtra("closedData", options.toString());
@@ -179,6 +229,7 @@ public class CorePlugin extends Plugin {
179
229
  JSObject result = new JSObject();
180
230
  result.put("closedData", options);
181
231
  dismissCall.resolve(result);
232
+ dismissCall = null;
182
233
  }
183
234
  } catch (Exception e) {
184
235
  e.printStackTrace();
@@ -208,6 +259,8 @@ public class CorePlugin extends Plugin {
208
259
 
209
260
  String url = call.getString("url");
210
261
 
262
+ // url = "http://192.168.1.105:11111/order/store/967302003724288/mode/takeaway?brandId=599961624702976";
263
+
211
264
  if (url == null) return;
212
265
 
213
266
  JSObject options = call.getObject("options", null);
@@ -271,6 +324,16 @@ public class CorePlugin extends Plugin {
271
324
  e.printStackTrace();
272
325
  }
273
326
 
327
+ JSArray exitUniversalLinks = call.getArray("exitUniversalLinks");
328
+ try {
329
+ if (exitUniversalLinks != null) {
330
+ List<String> es = exitUniversalLinks.toList();
331
+ intent.putExtra("exitUniversalLinks", (Serializable) es);
332
+ }
333
+ } catch (JSONException e) {
334
+ e.printStackTrace();
335
+ }
336
+
274
337
  intent.putExtra("url", url);
275
338
  intent.putExtra("clearCache", clearCache);
276
339
  intent.putExtra("member", (Serializable) memMap);
@@ -449,9 +512,7 @@ public class CorePlugin extends Plugin {
449
512
  call.resolve();
450
513
 
451
514
  }
452
-
453
- @PluginMethod
454
- public void readClipboard(PluginCall call) {
515
+ public JSObject _readClipboard() {
455
516
  JSObject object = new JSObject();
456
517
  try {
457
518
  ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
@@ -492,6 +553,12 @@ public class CorePlugin extends Plugin {
492
553
  object.put("type", "text/plain");
493
554
  e.printStackTrace();
494
555
  }
556
+ return object;
557
+ }
558
+
559
+ @PluginMethod
560
+ public void readClipboard(PluginCall call) {
561
+ JSObject object = _readClipboard();
495
562
  call.resolve(object);
496
563
  }
497
564
 
@@ -564,8 +631,24 @@ public class CorePlugin extends Plugin {
564
631
  ActivityManager.RecentTaskInfo taskInfo = tasks.get(0).getTaskInfo();
565
632
  if (taskInfo.topActivity.getClassName().equals(WebContainerActivity.class.getName())) {
566
633
  try {
567
- Class<?> activityClass = Class.forName(taskInfo.topActivity.getClassName());
568
- currentActivity = (Activity) activityClass.newInstance();
634
+ Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
635
+ Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
636
+ Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
637
+ activitiesField.setAccessible(true);
638
+
639
+ ArrayMap<?, ?> activities = (ArrayMap<?, ?>) activitiesField.get(activityThread);
640
+ for (Object record : activities.values()) {
641
+ Class<?> recordClass = record.getClass();
642
+ Field activityField = recordClass.getDeclaredField("activity");
643
+ activityField.setAccessible(true);
644
+ Activity activity = (Activity) activityField.get(record);
645
+ // 检查类名和是否存活
646
+ if (activity.getClass().getName().equals(taskInfo.topActivity.getClassName())
647
+ && !activity.isFinishing()) {
648
+ currentActivity = activity;
649
+ break;
650
+ }
651
+ }
569
652
  } catch (Exception e) {
570
653
  e.printStackTrace();
571
654
  }
@@ -575,16 +658,27 @@ public class CorePlugin extends Plugin {
575
658
  } else {
576
659
  List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
577
660
  if (tasks != null && !tasks.isEmpty()) {
578
- ActivityManager.RunningTaskInfo taskInfo = tasks.get(0);
579
- if (taskInfo.topActivity.getClassName().equals(WebContainerActivity.class.getName())) {
580
- try {
581
- Class<?> activityClass = Class.forName(taskInfo.topActivity.getClassName());
582
- currentActivity = (Activity) activityClass.newInstance();
583
- } catch (Exception e) {
584
- e.printStackTrace();
661
+ ComponentName componentName = tasks.get(0).topActivity;
662
+ try {
663
+ Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
664
+ Object activityThread = activityThreadClass.getMethod("currentActivityThread").invoke(null);
665
+ Field activitiesField = activityThreadClass.getDeclaredField("mActivities");
666
+ activitiesField.setAccessible(true);
667
+
668
+ HashMap<?, ?> activities = (HashMap<?, ?>) activitiesField.get(activityThread);
669
+ for (Object record : activities.values()) {
670
+ Class<?> recordClass = record.getClass();
671
+ Field activityField = recordClass.getDeclaredField("activity");
672
+ activityField.setAccessible(true);
673
+ Activity activity = (Activity) activityField.get(record);
674
+ if (activity.getClass().getName().equals(componentName.getClassName())
675
+ && !activity.isFinishing()) {
676
+ currentActivity = activity;
677
+ break;
678
+ }
585
679
  }
586
-
587
-
680
+ } catch (Exception e) {
681
+ e.printStackTrace();
588
682
  }
589
683
  }
590
684
  }
@@ -595,7 +689,7 @@ public class CorePlugin extends Plugin {
595
689
  }
596
690
 
597
691
  if (currentActivity instanceof WebContainerActivity) {
598
- ((WebContainerActivity) currentActivity).openSecondBrowser(url, null, new WebContainerActivity.SecondBrowserInterface() {
692
+ ((WebContainerActivity) currentActivity).openSecondBrowser(url, serviceName, new WebContainerActivity.SecondBrowserInterface() {
599
693
  @Override
600
694
  public void secondBrowserInterfaceYuuLoginCallback(View targetView, String status, String yuuToken, String cardNo, String warning, boolean cancel) {
601
695
  JSObject ret = new JSObject();
@@ -204,6 +204,16 @@ public class CorePlugin: CAPPlugin {
204
204
 
205
205
  }
206
206
 
207
+ public func forceDismiss() {
208
+ let r = ["closedData": [:]]
209
+ WebContainerViewController.closeCB?(r)
210
+ CorePlugin.dismissCall?.resolve(r)
211
+ CorePlugin.dismissCall = nil
212
+ DispatchQueue.main.async {
213
+ self.bridge?.viewController?.dismiss(animated: true);
214
+ }
215
+ }
216
+
207
217
  @objc func dismiss(_ call: CAPPluginCall) {
208
218
 
209
219
  aigensprint("CorePlugin dismiss")
@@ -224,6 +234,7 @@ public class CorePlugin: CAPPlugin {
224
234
  "success": true
225
235
  //"value": implementation.echo(value)
226
236
  ])
237
+ CorePlugin.dismissCall = nil
227
238
 
228
239
 
229
240
  }
@@ -260,6 +271,7 @@ public class CorePlugin: CAPPlugin {
260
271
  "success": true
261
272
  //"value": implementation.echo(value)
262
273
  ])
274
+ CorePlugin.dismissCall = nil
263
275
  }
264
276
 
265
277
  private static var dismissCall: CAPPluginCall?
@@ -320,6 +332,7 @@ public class CorePlugin: CAPPlugin {
320
332
  let externalProtocols = call.getArray("externalProtocols")
321
333
  let addPaddingProtocols = call.getArray("addPaddingProtocols")
322
334
  let excludedUniversalLinks = call.getArray("excludedUniversalLinks")
335
+ let exitUniversalLinks = call.getArray("exitUniversalLinks")
323
336
 
324
337
  let clearCache = call.getBool("clearCache") ?? false
325
338
  aigensDebug = call.getBool("debug") ?? false
@@ -349,6 +362,9 @@ public class CorePlugin: CAPPlugin {
349
362
  if (excludedUniversalLinks != nil) {
350
363
  options["excludedUniversalLinks"] = excludedUniversalLinks as AnyObject
351
364
  }
365
+ if (exitUniversalLinks != nil) {
366
+ options["exitUniversalLinks"] = exitUniversalLinks as AnyObject
367
+ }
352
368
 
353
369
  bridgeVC.options = options;
354
370
 
@@ -510,9 +526,16 @@ public class CorePlugin: CAPPlugin {
510
526
  return str;
511
527
  }
512
528
 
513
- @objc func readClipboard(_ call: CAPPluginCall) {
529
+ public func _readClipboard() -> [String: Any]?{
514
530
  if UIPasteboard.general.hasImages, let image = UIPasteboard.general.image, let str = getStringFromQr(image) {
515
- call.resolve(["value": str, "type": "text/plain"])
531
+ return ["value": str, "type": "text/plain"]
532
+ }
533
+ return nil
534
+ }
535
+
536
+ @objc func readClipboard(_ call: CAPPluginCall) {
537
+ if let obj = _readClipboard() {
538
+ call.resolve(obj)
516
539
  return
517
540
  }
518
541
  call.resolve(["value": "", "type": ""])
@@ -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.3",
3
+ "version": "0.5.5",
4
4
  "description": "Aigens Order.Place Core Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",