@aigens/aigens-sdk-core 0.0.11 → 0.0.14

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.
@@ -42,47 +42,94 @@ import java.util.Map;
42
42
 
43
43
  public class WebContainerActivity extends BridgeActivity {
44
44
 
45
+ static Bundle perviousInstanceState;
46
+ static Intent perviousIntent;
45
47
  private boolean DEBUG = CorePlugin.DEBUG;
46
48
  private String url;
47
49
  private boolean navbar = false;
48
50
  private Map member;
49
51
  private Map deeplink;
50
52
  private boolean ENVIRONMENT_PRODUCTION = true;
51
- private List<String> externalProtocols = new ArrayList<String>(){{
53
+ private String[] shouldRedirectList = new String[]{
54
+ "/scan?",
55
+ "/qr?",
56
+ "//scan",
57
+ "/api/v1/pay",
58
+ "/api/v1/wechat",
59
+ "/api/v1/qfpaywechat"
60
+ };
61
+ private List<String> externalProtocols = new ArrayList<String>() {{
52
62
  add("octopus://");
53
63
  add("alipay://");
54
64
  add("alipays://");
55
65
  add("alipayhk://");
66
+ add("weixin://");
56
67
  add("tel:");
57
68
  add("mailto:");
58
69
  add("payme://");
59
- add("weixin://");
60
70
  add("https://play.google.com");
71
+ add("hsbcpaymepay://");
61
72
  }};
62
73
 
63
- private void debug(Object... msgs){
74
+ private void debug(Object... msgs) {
64
75
 
65
76
 
66
- if(DEBUG){
67
- for(Object m: msgs){
77
+ if (DEBUG) {
78
+ for (Object m : msgs) {
68
79
  System.out.println(m);
69
80
  }
70
81
 
71
82
  }
72
83
  }
73
84
 
85
+ private String getRedirectUrl() {
86
+ Intent intent = getIntent();
87
+ Uri uri = intent.getData();
88
+ if (uri != null) {
89
+ String totalUrl = uri.toString();
90
+ String redirectUrl = null;
91
+ String universalLink = null;
92
+ if (perviousIntent != null) {
93
+ Map member = (Map) perviousIntent.getSerializableExtra("member");
94
+ universalLink = (String) member.get("universalLink");
95
+ }
96
+ if (universalLink != null && totalUrl.startsWith(universalLink) && totalUrl.indexOf("redirect=") >= 0) {
97
+ redirectUrl = totalUrl.split("redirect=")[1];
98
+ }
99
+ Log.i("getRedirectUrl", totalUrl);
100
+ return redirectUrl;
101
+ } else {
102
+ Log.i("getRedirectUrl", "null");
103
+ return null;
104
+ }
74
105
 
106
+ }
75
107
 
76
108
  @Override
77
109
  protected void onCreate(Bundle savedInstanceState) {
78
110
 
79
- super.onCreate(savedInstanceState);
111
+ Bundle currentInstanceState = savedInstanceState;
80
112
 
81
- setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
113
+ super.onCreate(currentInstanceState);
82
114
 
115
+ setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
83
116
 
84
117
 
118
+ String redirectUrl = getRedirectUrl();
85
119
  Intent intent = getIntent();
120
+
121
+ if (redirectUrl != null && !redirectUrl.equals("") && WebContainerActivity.perviousIntent != null) {
122
+ perviousIntent.putExtra("url", redirectUrl);
123
+ intent = perviousIntent;
124
+ currentInstanceState = WebContainerActivity.perviousInstanceState;
125
+ WebContainerActivity.perviousIntent = null;
126
+ WebContainerActivity.perviousInstanceState = null;
127
+ } else {
128
+ WebContainerActivity.perviousIntent = intent;
129
+ WebContainerActivity.perviousInstanceState = currentInstanceState;
130
+ }
131
+
132
+
86
133
  this.url = intent.getStringExtra("url");
87
134
 
88
135
  //if navbar = true, show nav bar with "Done" button
@@ -100,23 +147,23 @@ public class WebContainerActivity extends BridgeActivity {
100
147
  }
101
148
  }
102
149
 
103
- if(this.member != null) {
150
+ if (this.member != null) {
104
151
  CorePlugin.setMember(this.member);
105
152
  }
106
153
  if (this.deeplink != null) {
107
154
  CorePlugin.setDeeplink(this.deeplink);
108
155
  }
109
156
 
110
- System.out.println("OPEN URL:"+ url);
157
+ System.out.println("OPEN URL:" + url);
111
158
 
112
- if(url == null){
159
+ if (url == null) {
113
160
  System.err.println("CONFIG ERROR MISSING NATIVE URL");
114
161
  }
115
162
 
116
- if(member != null){
163
+ if (member != null) {
117
164
  debug("member", member);
118
165
  }
119
- if(member != null){
166
+ if (member != null) {
120
167
  debug("deeplink", deeplink);
121
168
  }
122
169
 
@@ -127,7 +174,7 @@ public class WebContainerActivity extends BridgeActivity {
127
174
  JSONObject server = config.optJSONObject("server");
128
175
 
129
176
  try {
130
- if(url != null){
177
+ if (url != null) {
131
178
  server.putOpt("url", url);
132
179
  }
133
180
 
@@ -144,19 +191,19 @@ public class WebContainerActivity extends BridgeActivity {
144
191
 
145
192
  List<Class<? extends Plugin>> auto = loadPlugins();
146
193
 
147
- for(Class c: auto){
194
+ for (Class c : auto) {
148
195
 
149
196
  String clsName = c.getName();
150
197
 
151
- if(clsName.endsWith("SplashScreenPlugin")){
198
+ if (clsName.endsWith("SplashScreenPlugin")) {
152
199
  //don't add the splash screen plugin so it doesn't show the splash screen again
153
- }else{
200
+ } else {
154
201
  plugins.add(c);
155
202
  }
156
203
 
157
204
  }
158
205
 
159
- addExtraPlugins(new String[] {
206
+ addExtraPlugins(new String[]{
160
207
  "com.aigens.googlepay.GooglePayPlugin",
161
208
  "com.aigens.octopus.OctopusPlugin",
162
209
  "com.aigens.wechatpay.WechatPayPlugin",
@@ -168,7 +215,7 @@ public class WebContainerActivity extends BridgeActivity {
168
215
 
169
216
  debug("App plugins:" + plugins);
170
217
 
171
- super.init(savedInstanceState, plugins, cc);
218
+ super.init(currentInstanceState, plugins, cc);
172
219
 
173
220
  //still have time to override webview client to avoid any intercept
174
221
 
@@ -184,7 +231,7 @@ public class WebContainerActivity extends BridgeActivity {
184
231
  // this.bridge.getWebView().clearFormData();
185
232
  // this.bridge.getWebView().getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
186
233
 
187
- initView();
234
+ initView(intent);
188
235
  initLayout(false, true, false);
189
236
 
190
237
  disableServiceWorker(this.url, this.bridge);
@@ -214,7 +261,7 @@ public class WebContainerActivity extends BridgeActivity {
214
261
  }
215
262
  }
216
263
 
217
- private void initView(){
264
+ private void initView(Intent intent) {
218
265
 
219
266
  Button backButton = (Button) findViewById(R.id.back);
220
267
  backButton.setOnClickListener(new View.OnClickListener() {
@@ -236,11 +283,11 @@ public class WebContainerActivity extends BridgeActivity {
236
283
  }
237
284
  });
238
285
 
239
- setTheme();
286
+ setTheme(intent);
240
287
 
241
288
  }
242
289
 
243
- private void reload(){
290
+ private void reload() {
244
291
 
245
292
  String url = this.url;
246
293
 
@@ -254,8 +301,7 @@ public class WebContainerActivity extends BridgeActivity {
254
301
 
255
302
  }
256
303
 
257
- private void setTheme() {
258
- Intent intent = getIntent();
304
+ private void setTheme(Intent intent) {
259
305
  String themeColor = intent.getStringExtra("themeColor");
260
306
  if (!TextUtils.isEmpty(themeColor)) {
261
307
  View info = findViewById(R.id.info);
@@ -266,9 +312,10 @@ public class WebContainerActivity extends BridgeActivity {
266
312
  getWindow().setStatusBarColor(Color.parseColor(themeColor));//set statussbar color
267
313
  }
268
314
  }
269
- private void initLayout(boolean showWeb, boolean showInfo, boolean showError){
270
315
 
271
- if(showError){
316
+ private void initLayout(boolean showWeb, boolean showInfo, boolean showError) {
317
+
318
+ if (showError) {
272
319
  showWeb = false;
273
320
  showInfo = false;
274
321
  }
@@ -284,7 +331,7 @@ public class WebContainerActivity extends BridgeActivity {
284
331
 
285
332
  }
286
333
 
287
- private List<Class<? extends Plugin>> loadPlugins(){
334
+ private List<Class<? extends Plugin>> loadPlugins() {
288
335
 
289
336
  List<Class<? extends Plugin>> plugins = null;
290
337
 
@@ -301,9 +348,9 @@ public class WebContainerActivity extends BridgeActivity {
301
348
 
302
349
  private static boolean SW_DISABLED = false;
303
350
 
304
- private static void disableServiceWorker(String originUrl, Bridge bridge){
351
+ private static void disableServiceWorker(String originUrl, Bridge bridge) {
305
352
 
306
- if(SW_DISABLED) return;
353
+ if (SW_DISABLED) return;
307
354
 
308
355
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
309
356
  ServiceWorkerController.getInstance().setServiceWorkerClient(new ServiceWorkerClient() {
@@ -311,11 +358,12 @@ public class WebContainerActivity extends BridgeActivity {
311
358
  public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
312
359
 
313
360
  // Fixed: Sometimes the plugin cannot be loaded
314
- String currentUrl = request.getUrl().toString();
315
- if (currentUrl.equals(originUrl)) {
316
- return bridge.getLocalServer().shouldInterceptRequest(request);
317
- }
318
- return null;
361
+ // String currentUrl = request.getUrl().toString();
362
+ // if (currentUrl.equals(originUrl)) {
363
+ // return bridge.getLocalServer().shouldInterceptRequest(request);
364
+ // }
365
+ // return null;
366
+ return bridge.getLocalServer().shouldInterceptRequest(request);
319
367
  }
320
368
  });
321
369
  }
@@ -338,7 +386,7 @@ public class WebContainerActivity extends BridgeActivity {
338
386
  }
339
387
 
340
388
 
341
- private JSONObject readConfig(){
389
+ private JSONObject readConfig() {
342
390
 
343
391
  try {
344
392
 
@@ -351,7 +399,7 @@ public class WebContainerActivity extends BridgeActivity {
351
399
  JSONObject jo = new JSONObject(joStr);
352
400
 
353
401
  return jo;
354
- }catch(Exception e){
402
+ } catch (Exception e) {
355
403
  e.printStackTrace();
356
404
  }
357
405
 
@@ -366,7 +414,7 @@ public class WebContainerActivity extends BridgeActivity {
366
414
  boolean canBack = this.bridge.getWebView().canGoBack();
367
415
 
368
416
  System.out.println("WebContainerActivity onBackPressed can back:" + canBack);
369
- if(!canBack){
417
+ if (!canBack) {
370
418
  finish();
371
419
  }
372
420
  }
@@ -377,6 +425,7 @@ public class WebContainerActivity extends BridgeActivity {
377
425
  public Activity activity;
378
426
  private String TAG = "BypassWebViewClient";
379
427
  List<String> externalProtocols;
428
+
380
429
  public BypassWebViewClient(Bridge bridge) {
381
430
  super(bridge);
382
431
  }
@@ -391,6 +440,7 @@ public class WebContainerActivity extends BridgeActivity {
391
440
  }
392
441
  return false;
393
442
  }
443
+
394
444
  public boolean shouldOverrideUrl(WebView view, String url) {
395
445
  if (url.startsWith(WebView.SCHEME_TEL)) {
396
446
  try {
@@ -454,17 +504,25 @@ public class WebContainerActivity extends BridgeActivity {
454
504
  String url = request.getUrl().toString();
455
505
  //debug("shouldInterceptRequest", url);
456
506
 
507
+ Log.wtf("shouldInterceptRequestUrl:", url);
457
508
 
458
509
 
459
510
  //support redirect from /scan
460
- if(url.indexOf("/scan?") > 0 || url.indexOf("/qr?") > 0 || url.indexOf("//scan") > 0){
461
- return null;
462
- }
511
+ // for (String r: shouldRedirectList) {
512
+ // if (url.indexOf(r) > 0) {
513
+ // return null;
514
+ // }
515
+ // }
516
+
517
+ // call super.shouldInterceptRequest(view, request); at: disableServiceWorker method
518
+ return null;
463
519
 
464
- return super.shouldInterceptRequest(view, request);
520
+ // if(url.indexOf("/scan?") > 0 || url.indexOf("/qr?") > 0 || url.indexOf("//scan") > 0){
521
+ // return null;
522
+ // }
523
+
524
+ // return super.shouldInterceptRequest(view, request);
465
525
 
466
- //super.shouldInterceptRequest(view, request);
467
- //return null;
468
526
  }
469
527
 
470
528
 
@@ -499,14 +557,14 @@ public class WebContainerActivity extends BridgeActivity {
499
557
  }
500
558
 
501
559
  @Override
502
- public void onPageFinished (WebView view, String url){
560
+ public void onPageFinished(WebView view, String url) {
503
561
 
504
562
  debug("onPageFinished", url);
505
563
  //bridge.getWebView().setVisibility(View.VISIBLE);
506
564
  }
507
565
 
508
566
  @Override
509
- public void onReceivedError (WebView view, int errorCode, String description, String failingUrl){
567
+ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
510
568
  debug("onReceivedErrorOld", errorCode, description, failingUrl);
511
569
 
512
570
  initLayout(false, true, true);
@@ -523,5 +581,4 @@ public class WebContainerActivity extends BridgeActivity {
523
581
  }
524
582
 
525
583
 
526
-
527
584
  }
@@ -14,8 +14,10 @@ import Capacitor
14
14
  // {themeColor: "#xxxxxx"}
15
15
  public var options: Dictionary<String, Any>?
16
16
 
17
+ private var redirectLink = ""
18
+ private var universalLink = ""
17
19
  var externalProtocols: [String] = [
18
- "octopus://", "alipay://", "alipays://", "alipayhk://", "https://itunes.apple.com", "tel:", "mailto:", "itms-apps://itunes.apple.com", "https://apps.apple.com", "payme://", "weixin://"
20
+ "octopus://", "alipay://", "alipays://", "alipayhk://", "https://itunes.apple.com", "tel:", "mailto:", "itms-apps://itunes.apple.com", "https://apps.apple.com", "payme://", "weixin://", "hsbcpaymepay://"
19
21
  ]
20
22
  let containerView = WebContainer.webContainer()
21
23
  var webContainerView: WebContainer {
@@ -97,6 +99,7 @@ import Capacitor
97
99
  let url = URL(string: urlString!)
98
100
 
99
101
  let member = self.options?["member"] as? Dictionary<String, Any>
102
+ self.universalLink = member?["universalLink"] as? String ?? ""
100
103
 
101
104
  CorePlugin.member = member
102
105
  let deeplink = self.options?["deeplink"] as? Dictionary<String, Any>
@@ -165,6 +168,22 @@ extension WebContainerViewController: WKNavigationDelegate {
165
168
  return
166
169
  }
167
170
 
171
+ print("navURL--:\(navURL)")
172
+
173
+ if !universalLink.isEmpty && navURL.absoluteString.starts(with: universalLink) {
174
+
175
+ if navURL.absoluteString.range(of: "redirect=") != nil, let redirect = navURL.absoluteString.components(separatedBy:"redirect=").last, let redirectUrl = URL(string: redirect) {
176
+ self.redirectLink = redirect
177
+ print("navURL-- redirect:\(redirect)")
178
+ webContainerView.showLoading(true)
179
+ webContainerView.showError(false)
180
+ let rUrl = URLRequest(url: redirectUrl)
181
+ webView.load(rUrl)
182
+ }
183
+ decisionHandler(.cancel)
184
+ return;
185
+ }
186
+
168
187
  var isCanOpen = false
169
188
  if externalProtocols.count > 0 {
170
189
  externalProtocols.forEach { (url) in
@@ -263,7 +282,20 @@ extension WebContainerViewController: WKNavigationDelegate {
263
282
  }
264
283
  CAPLog.print("⚡️ WebView failed provisional navigation")
265
284
  CAPLog.print("⚡️ Error: " + error.localizedDescription)
266
- webContainerView.showError(true, error.localizedDescription)
285
+
286
+ if let errorUrl = webView.url?.absoluteString {
287
+ print("navURL-- errorUrl: \(errorUrl)")
288
+ if (!self.redirectLink.isEmpty && errorUrl.starts(with: self.redirectLink)) {
289
+ self.redirectLink = ""
290
+ webContainerView.showError(false)
291
+ webContainerView.showLoading(true)
292
+ }else {
293
+ webContainerView.showError(true, error.localizedDescription)
294
+ }
295
+ }else {
296
+ webContainerView.showError(true, error.localizedDescription)
297
+ }
298
+
267
299
  }
268
300
 
269
301
  public func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigens/aigens-sdk-core",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "description": "Aigens Order.Place Core Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",