@aigens/aigens-sdk-core 0.0.12 → 0.0.15

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,13 +42,15 @@ 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 String[] shouldRedirectList = new String[] {
53
+ private String[] shouldRedirectList = new String[]{
52
54
  "/scan?",
53
55
  "/qr?",
54
56
  "//scan",
@@ -56,7 +58,7 @@ public class WebContainerActivity extends BridgeActivity {
56
58
  "/api/v1/wechat",
57
59
  "/api/v1/qfpaywechat"
58
60
  };
59
- private List<String> externalProtocols = new ArrayList<String>(){{
61
+ private List<String> externalProtocols = new ArrayList<String>() {{
60
62
  add("octopus://");
61
63
  add("alipay://");
62
64
  add("alipays://");
@@ -69,29 +71,65 @@ public class WebContainerActivity extends BridgeActivity {
69
71
  add("hsbcpaymepay://");
70
72
  }};
71
73
 
72
- private void debug(Object... msgs){
74
+ private void debug(Object... msgs) {
73
75
 
74
76
 
75
- if(DEBUG){
76
- for(Object m: msgs){
77
+ if (DEBUG) {
78
+ for (Object m : msgs) {
77
79
  System.out.println(m);
78
80
  }
79
81
 
80
82
  }
81
83
  }
82
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
+ }
83
105
 
106
+ }
84
107
 
85
108
  @Override
86
109
  protected void onCreate(Bundle savedInstanceState) {
87
110
 
88
- super.onCreate(savedInstanceState);
111
+ Bundle currentInstanceState = savedInstanceState;
89
112
 
90
- setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
113
+ super.onCreate(currentInstanceState);
91
114
 
115
+ setContentView(com.aigens.sdk.R.layout.sdk_layout_main);
92
116
 
93
117
 
118
+ String redirectUrl = getRedirectUrl();
94
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
+
95
133
  this.url = intent.getStringExtra("url");
96
134
 
97
135
  //if navbar = true, show nav bar with "Done" button
@@ -109,23 +147,23 @@ public class WebContainerActivity extends BridgeActivity {
109
147
  }
110
148
  }
111
149
 
112
- if(this.member != null) {
150
+ if (this.member != null) {
113
151
  CorePlugin.setMember(this.member);
114
152
  }
115
153
  if (this.deeplink != null) {
116
154
  CorePlugin.setDeeplink(this.deeplink);
117
155
  }
118
156
 
119
- System.out.println("OPEN URL:"+ url);
157
+ System.out.println("OPEN URL:" + url);
120
158
 
121
- if(url == null){
159
+ if (url == null) {
122
160
  System.err.println("CONFIG ERROR MISSING NATIVE URL");
123
161
  }
124
162
 
125
- if(member != null){
163
+ if (member != null) {
126
164
  debug("member", member);
127
165
  }
128
- if(member != null){
166
+ if (member != null) {
129
167
  debug("deeplink", deeplink);
130
168
  }
131
169
 
@@ -136,7 +174,7 @@ public class WebContainerActivity extends BridgeActivity {
136
174
  JSONObject server = config.optJSONObject("server");
137
175
 
138
176
  try {
139
- if(url != null){
177
+ if (url != null) {
140
178
  server.putOpt("url", url);
141
179
  }
142
180
 
@@ -153,19 +191,19 @@ public class WebContainerActivity extends BridgeActivity {
153
191
 
154
192
  List<Class<? extends Plugin>> auto = loadPlugins();
155
193
 
156
- for(Class c: auto){
194
+ for (Class c : auto) {
157
195
 
158
196
  String clsName = c.getName();
159
197
 
160
- if(clsName.endsWith("SplashScreenPlugin")){
198
+ if (clsName.endsWith("SplashScreenPlugin")) {
161
199
  //don't add the splash screen plugin so it doesn't show the splash screen again
162
- }else{
200
+ } else {
163
201
  plugins.add(c);
164
202
  }
165
203
 
166
204
  }
167
205
 
168
- addExtraPlugins(new String[] {
206
+ addExtraPlugins(new String[]{
169
207
  "com.aigens.googlepay.GooglePayPlugin",
170
208
  "com.aigens.octopus.OctopusPlugin",
171
209
  "com.aigens.wechatpay.WechatPayPlugin",
@@ -177,7 +215,7 @@ public class WebContainerActivity extends BridgeActivity {
177
215
 
178
216
  debug("App plugins:" + plugins);
179
217
 
180
- super.init(savedInstanceState, plugins, cc);
218
+ super.init(currentInstanceState, plugins, cc);
181
219
 
182
220
  //still have time to override webview client to avoid any intercept
183
221
 
@@ -193,7 +231,7 @@ public class WebContainerActivity extends BridgeActivity {
193
231
  // this.bridge.getWebView().clearFormData();
194
232
  // this.bridge.getWebView().getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
195
233
 
196
- initView();
234
+ initView(intent);
197
235
  initLayout(false, true, false);
198
236
 
199
237
  disableServiceWorker(this.url, this.bridge);
@@ -223,7 +261,7 @@ public class WebContainerActivity extends BridgeActivity {
223
261
  }
224
262
  }
225
263
 
226
- private void initView(){
264
+ private void initView(Intent intent) {
227
265
 
228
266
  Button backButton = (Button) findViewById(R.id.back);
229
267
  backButton.setOnClickListener(new View.OnClickListener() {
@@ -245,11 +283,11 @@ public class WebContainerActivity extends BridgeActivity {
245
283
  }
246
284
  });
247
285
 
248
- setTheme();
286
+ setTheme(intent);
249
287
 
250
288
  }
251
289
 
252
- private void reload(){
290
+ private void reload() {
253
291
 
254
292
  String url = this.url;
255
293
 
@@ -263,8 +301,7 @@ public class WebContainerActivity extends BridgeActivity {
263
301
 
264
302
  }
265
303
 
266
- private void setTheme() {
267
- Intent intent = getIntent();
304
+ private void setTheme(Intent intent) {
268
305
  String themeColor = intent.getStringExtra("themeColor");
269
306
  if (!TextUtils.isEmpty(themeColor)) {
270
307
  View info = findViewById(R.id.info);
@@ -275,9 +312,10 @@ public class WebContainerActivity extends BridgeActivity {
275
312
  getWindow().setStatusBarColor(Color.parseColor(themeColor));//set statussbar color
276
313
  }
277
314
  }
278
- private void initLayout(boolean showWeb, boolean showInfo, boolean showError){
279
315
 
280
- if(showError){
316
+ private void initLayout(boolean showWeb, boolean showInfo, boolean showError) {
317
+
318
+ if (showError) {
281
319
  showWeb = false;
282
320
  showInfo = false;
283
321
  }
@@ -293,7 +331,7 @@ public class WebContainerActivity extends BridgeActivity {
293
331
 
294
332
  }
295
333
 
296
- private List<Class<? extends Plugin>> loadPlugins(){
334
+ private List<Class<? extends Plugin>> loadPlugins() {
297
335
 
298
336
  List<Class<? extends Plugin>> plugins = null;
299
337
 
@@ -310,9 +348,9 @@ public class WebContainerActivity extends BridgeActivity {
310
348
 
311
349
  private static boolean SW_DISABLED = false;
312
350
 
313
- private static void disableServiceWorker(String originUrl, Bridge bridge){
351
+ private static void disableServiceWorker(String originUrl, Bridge bridge) {
314
352
 
315
- if(SW_DISABLED) return;
353
+ if (SW_DISABLED) return;
316
354
 
317
355
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
318
356
  ServiceWorkerController.getInstance().setServiceWorkerClient(new ServiceWorkerClient() {
@@ -348,7 +386,7 @@ public class WebContainerActivity extends BridgeActivity {
348
386
  }
349
387
 
350
388
 
351
- private JSONObject readConfig(){
389
+ private JSONObject readConfig() {
352
390
 
353
391
  try {
354
392
 
@@ -361,7 +399,7 @@ public class WebContainerActivity extends BridgeActivity {
361
399
  JSONObject jo = new JSONObject(joStr);
362
400
 
363
401
  return jo;
364
- }catch(Exception e){
402
+ } catch (Exception e) {
365
403
  e.printStackTrace();
366
404
  }
367
405
 
@@ -376,7 +414,7 @@ public class WebContainerActivity extends BridgeActivity {
376
414
  boolean canBack = this.bridge.getWebView().canGoBack();
377
415
 
378
416
  System.out.println("WebContainerActivity onBackPressed can back:" + canBack);
379
- if(!canBack){
417
+ if (!canBack) {
380
418
  finish();
381
419
  }
382
420
  }
@@ -387,6 +425,7 @@ public class WebContainerActivity extends BridgeActivity {
387
425
  public Activity activity;
388
426
  private String TAG = "BypassWebViewClient";
389
427
  List<String> externalProtocols;
428
+
390
429
  public BypassWebViewClient(Bridge bridge) {
391
430
  super(bridge);
392
431
  }
@@ -401,6 +440,7 @@ public class WebContainerActivity extends BridgeActivity {
401
440
  }
402
441
  return false;
403
442
  }
443
+
404
444
  public boolean shouldOverrideUrl(WebView view, String url) {
405
445
  if (url.startsWith(WebView.SCHEME_TEL)) {
406
446
  try {
@@ -467,7 +507,6 @@ public class WebContainerActivity extends BridgeActivity {
467
507
  Log.wtf("shouldInterceptRequestUrl:", url);
468
508
 
469
509
 
470
-
471
510
  //support redirect from /scan
472
511
  // for (String r: shouldRedirectList) {
473
512
  // if (url.indexOf(r) > 0) {
@@ -518,14 +557,14 @@ public class WebContainerActivity extends BridgeActivity {
518
557
  }
519
558
 
520
559
  @Override
521
- public void onPageFinished (WebView view, String url){
560
+ public void onPageFinished(WebView view, String url) {
522
561
 
523
562
  debug("onPageFinished", url);
524
563
  //bridge.getWebView().setVisibility(View.VISIBLE);
525
564
  }
526
565
 
527
566
  @Override
528
- public void onReceivedError (WebView view, int errorCode, String description, String failingUrl){
567
+ public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
529
568
  debug("onReceivedErrorOld", errorCode, description, failingUrl);
530
569
 
531
570
  initLayout(false, true, true);
@@ -542,5 +581,4 @@ public class WebContainerActivity extends BridgeActivity {
542
581
  }
543
582
 
544
583
 
545
-
546
584
  }
@@ -14,6 +14,8 @@ 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
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
  ]
@@ -29,8 +31,45 @@ import Capacitor
29
31
  loadWebViewCustom()
30
32
  initView()
31
33
 
34
+ handleOpenUrl()
35
+
32
36
  }
33
37
 
38
+ private func handleOpenUrl() {
39
+ NotificationCenter.default.addObserver(self, selector: #selector(self.handleUniversalLink(notification:)), name: Notification.Name.capacitorOpenUniversalLink, object: nil)
40
+
41
+ NotificationCenter.default.addObserver(self, selector: #selector(self.handleUrlOpened(notification:)), name: Notification.Name.capacitorOpenURL, object: nil)
42
+ }
43
+
44
+ @objc func handleUrlOpened(notification: NSNotification) {
45
+ guard let object = notification.object as? [String: Any?] else {
46
+ return
47
+ }
48
+
49
+ print("handleUrlOpened url:\(object)")
50
+ guard let url = object["url"] as? URL else {
51
+ return
52
+ }
53
+
54
+ let rUrl = URLRequest(url: url)
55
+ webView?.load(rUrl)
56
+ }
57
+
58
+ @objc func handleUniversalLink(notification: NSNotification) {
59
+ guard let object = notification.object as? [String: Any?] else {
60
+ return
61
+ }
62
+
63
+ print("handleUniversalLink url:\(object)")
64
+ guard let url = object["url"] as? URL else {
65
+ return
66
+ }
67
+
68
+
69
+ let rUrl = URLRequest(url: url)
70
+ webView?.load(rUrl)
71
+
72
+ }
34
73
  private func initView(){
35
74
 
36
75
  print("VC initView")
@@ -97,6 +136,7 @@ import Capacitor
97
136
  let url = URL(string: urlString!)
98
137
 
99
138
  let member = self.options?["member"] as? Dictionary<String, Any>
139
+ self.universalLink = member?["universalLink"] as? String ?? ""
100
140
 
101
141
  CorePlugin.member = member
102
142
  let deeplink = self.options?["deeplink"] as? Dictionary<String, Any>
@@ -165,6 +205,22 @@ extension WebContainerViewController: WKNavigationDelegate {
165
205
  return
166
206
  }
167
207
 
208
+ print("navURL--:\(navURL)")
209
+
210
+ if !universalLink.isEmpty && navURL.absoluteString.starts(with: universalLink) {
211
+
212
+ if navURL.absoluteString.range(of: "redirect=") != nil, let redirect = navURL.absoluteString.components(separatedBy:"redirect=").last, let redirectUrl = URL(string: redirect) {
213
+ self.redirectLink = redirect
214
+ print("navURL-- redirect:\(redirect)")
215
+ webContainerView.showLoading(true)
216
+ webContainerView.showError(false)
217
+ let rUrl = URLRequest(url: redirectUrl)
218
+ webView.load(rUrl)
219
+ }
220
+ decisionHandler(.cancel)
221
+ return;
222
+ }
223
+
168
224
  var isCanOpen = false
169
225
  if externalProtocols.count > 0 {
170
226
  externalProtocols.forEach { (url) in
@@ -263,7 +319,20 @@ extension WebContainerViewController: WKNavigationDelegate {
263
319
  }
264
320
  CAPLog.print("⚡️ WebView failed provisional navigation")
265
321
  CAPLog.print("⚡️ Error: " + error.localizedDescription)
266
- webContainerView.showError(true, error.localizedDescription)
322
+
323
+ if let errorUrl = webView.url?.absoluteString {
324
+ print("navURL-- errorUrl: \(errorUrl)")
325
+ if (!self.redirectLink.isEmpty && errorUrl.starts(with: self.redirectLink)) {
326
+ self.redirectLink = ""
327
+ webContainerView.showError(false)
328
+ webContainerView.showLoading(true)
329
+ }else {
330
+ webContainerView.showError(true, error.localizedDescription)
331
+ }
332
+ }else {
333
+ webContainerView.showError(true, error.localizedDescription)
334
+ }
335
+
267
336
  }
268
337
 
269
338
  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.12",
3
+ "version": "0.0.15",
4
4
  "description": "Aigens Order.Place Core Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",