@aigens/aigens-sdk-core 0.0.10 → 0.0.13
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.
@@ -48,15 +48,25 @@ public class WebContainerActivity extends BridgeActivity {
|
|
48
48
|
private Map member;
|
49
49
|
private Map deeplink;
|
50
50
|
private boolean ENVIRONMENT_PRODUCTION = true;
|
51
|
+
private String[] shouldRedirectList = new String[] {
|
52
|
+
"/scan?",
|
53
|
+
"/qr?",
|
54
|
+
"//scan",
|
55
|
+
"/api/v1/pay",
|
56
|
+
"/api/v1/wechat",
|
57
|
+
"/api/v1/qfpaywechat"
|
58
|
+
};
|
51
59
|
private List<String> externalProtocols = new ArrayList<String>(){{
|
52
60
|
add("octopus://");
|
53
61
|
add("alipay://");
|
54
62
|
add("alipays://");
|
55
63
|
add("alipayhk://");
|
64
|
+
add("weixin://");
|
56
65
|
add("tel:");
|
57
66
|
add("mailto:");
|
58
67
|
add("payme://");
|
59
68
|
add("https://play.google.com");
|
69
|
+
add("hsbcpaymepay://");
|
60
70
|
}};
|
61
71
|
|
62
72
|
private void debug(Object... msgs){
|
@@ -310,11 +320,12 @@ public class WebContainerActivity extends BridgeActivity {
|
|
310
320
|
public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
|
311
321
|
|
312
322
|
// Fixed: Sometimes the plugin cannot be loaded
|
313
|
-
String currentUrl = request.getUrl().toString();
|
314
|
-
if (currentUrl.equals(originUrl)) {
|
315
|
-
return bridge.getLocalServer().shouldInterceptRequest(request);
|
316
|
-
}
|
317
|
-
return null;
|
323
|
+
// String currentUrl = request.getUrl().toString();
|
324
|
+
// if (currentUrl.equals(originUrl)) {
|
325
|
+
// return bridge.getLocalServer().shouldInterceptRequest(request);
|
326
|
+
// }
|
327
|
+
// return null;
|
328
|
+
return bridge.getLocalServer().shouldInterceptRequest(request);
|
318
329
|
}
|
319
330
|
});
|
320
331
|
}
|
@@ -453,17 +464,26 @@ public class WebContainerActivity extends BridgeActivity {
|
|
453
464
|
String url = request.getUrl().toString();
|
454
465
|
//debug("shouldInterceptRequest", url);
|
455
466
|
|
467
|
+
Log.wtf("shouldInterceptRequestUrl:", url);
|
468
|
+
|
456
469
|
|
457
470
|
|
458
471
|
//support redirect from /scan
|
459
|
-
|
460
|
-
|
461
|
-
|
472
|
+
// for (String r: shouldRedirectList) {
|
473
|
+
// if (url.indexOf(r) > 0) {
|
474
|
+
// return null;
|
475
|
+
// }
|
476
|
+
// }
|
477
|
+
|
478
|
+
// call super.shouldInterceptRequest(view, request); at: disableServiceWorker method
|
479
|
+
return null;
|
480
|
+
|
481
|
+
// if(url.indexOf("/scan?") > 0 || url.indexOf("/qr?") > 0 || url.indexOf("//scan") > 0){
|
482
|
+
// return null;
|
483
|
+
// }
|
462
484
|
|
463
|
-
return super.shouldInterceptRequest(view, request);
|
485
|
+
// return super.shouldInterceptRequest(view, request);
|
464
486
|
|
465
|
-
//super.shouldInterceptRequest(view, request);
|
466
|
-
//return null;
|
467
487
|
}
|
468
488
|
|
469
489
|
|
@@ -13,9 +13,11 @@ import Capacitor
|
|
13
13
|
|
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://"
|
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 {
|
@@ -28,22 +30,22 @@ import Capacitor
|
|
28
30
|
self.becomeFirstResponder()
|
29
31
|
loadWebViewCustom()
|
30
32
|
initView()
|
31
|
-
|
33
|
+
|
32
34
|
}
|
33
|
-
|
35
|
+
|
34
36
|
private func initView(){
|
35
|
-
|
37
|
+
|
36
38
|
print("VC initView")
|
37
|
-
|
39
|
+
|
38
40
|
//let bundle = Bundle(for: WebContainerViewController.self)
|
39
41
|
//let containerView = WebContainerView()
|
40
42
|
//let containerView = bundle.loadNibNamed("WebContainerView", owner: self, options: nil)?.first as! UIView
|
41
|
-
|
43
|
+
|
42
44
|
self.view.addSubview(webContainerView)
|
43
45
|
webContainerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
|
44
46
|
setupOptions(webContainerView)
|
45
47
|
containerView.vc = self
|
46
|
-
|
48
|
+
|
47
49
|
//
|
48
50
|
//
|
49
51
|
|
@@ -61,14 +63,14 @@ import Capacitor
|
|
61
63
|
// containerView.webArea.addSubview(self.webView!)
|
62
64
|
//
|
63
65
|
|
64
|
-
|
66
|
+
|
65
67
|
}
|
66
|
-
|
68
|
+
|
67
69
|
open override func viewWillLayoutSubviews() {
|
68
70
|
super.viewWillLayoutSubviews()
|
69
71
|
webContainerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
|
70
72
|
}
|
71
|
-
|
73
|
+
|
72
74
|
private func setupOptions(_ view: WebContainer) {
|
73
75
|
if let theme = self.options?["themeColor"] as? String, let color = UIColor.getHex(hex: theme) {
|
74
76
|
self.view.backgroundColor = color
|
@@ -79,9 +81,9 @@ import Capacitor
|
|
79
81
|
if let externalProtocols = options?["externalProtocols"] as? [String] {
|
80
82
|
self.externalProtocols.append(contentsOf: externalProtocols)
|
81
83
|
}
|
82
|
-
|
84
|
+
|
83
85
|
}
|
84
|
-
|
86
|
+
|
85
87
|
public final func loadWebViewCustom() {
|
86
88
|
|
87
89
|
//let bridge = self.bridge
|
@@ -95,13 +97,14 @@ import Capacitor
|
|
95
97
|
}
|
96
98
|
|
97
99
|
let url = URL(string: urlString!)
|
98
|
-
|
100
|
+
|
99
101
|
let member = self.options?["member"] as? Dictionary<String, Any>
|
100
|
-
|
102
|
+
self.universalLink = member?["universalLink"] as? String ?? ""
|
103
|
+
|
101
104
|
CorePlugin.member = member
|
102
105
|
let deeplink = self.options?["deeplink"] as? Dictionary<String, Any>
|
103
106
|
CorePlugin.deeplink = deeplink
|
104
|
-
|
107
|
+
|
105
108
|
//bridge.webViewDelegationHandler.willLoadWebview(webView)
|
106
109
|
_ = webView?.load(URLRequest(url: url!))
|
107
110
|
webView?.navigationDelegate = self
|
@@ -134,12 +137,12 @@ import Capacitor
|
|
134
137
|
|
135
138
|
return descriptor
|
136
139
|
}
|
137
|
-
|
140
|
+
|
138
141
|
deinit {
|
139
142
|
print("WebContainerViewController deinit")
|
140
143
|
}
|
141
144
|
|
142
|
-
|
145
|
+
|
143
146
|
}
|
144
147
|
|
145
148
|
extension WebContainerViewController: WKNavigationDelegate {
|
@@ -149,12 +152,12 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
149
152
|
// Reset the bridge on each navigation
|
150
153
|
// self.bridge?.reset()
|
151
154
|
}
|
152
|
-
|
155
|
+
|
153
156
|
public func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
|
154
157
|
webContainerView.showError(false)
|
155
158
|
webContainerView.showLoading(true)
|
156
159
|
}
|
157
|
-
|
160
|
+
|
158
161
|
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
159
162
|
// post a notification for any listeners
|
160
163
|
NotificationCenter.default.post(name: .capacitorDecidePolicyForNavigationAction, object: navigationAction)
|
@@ -164,7 +167,23 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
164
167
|
decisionHandler(.allow)
|
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
|
@@ -174,7 +193,7 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
174
193
|
}
|
175
194
|
}
|
176
195
|
}
|
177
|
-
|
196
|
+
|
178
197
|
if isCanOpen {
|
179
198
|
if #available(iOS 10.0, *) {
|
180
199
|
UIApplication.shared.open(navURL, options: [:], completionHandler: nil);
|
@@ -184,7 +203,7 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
184
203
|
decisionHandler(.cancel)
|
185
204
|
return;
|
186
205
|
}
|
187
|
-
|
206
|
+
|
188
207
|
|
189
208
|
// first, give plugins the chance to handle the decision
|
190
209
|
// for pluginObject in bridge.plugins {
|
@@ -224,8 +243,8 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
224
243
|
// fallthrough to allowing it
|
225
244
|
decisionHandler(.allow)
|
226
245
|
}
|
227
|
-
|
228
|
-
|
246
|
+
|
247
|
+
|
229
248
|
// The force unwrap is part of the protocol declaration, so we should keep it.
|
230
249
|
// swiftlint:disable:next implicitly_unwrapped_optional
|
231
250
|
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
@@ -237,7 +256,7 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
237
256
|
webContainerView.showError(false)
|
238
257
|
CAPLog.print("⚡️ WebView loaded")
|
239
258
|
}
|
240
|
-
|
259
|
+
|
241
260
|
// The force unwrap is part of the protocol declaration, so we should keep it.
|
242
261
|
// swiftlint:disable:next implicitly_unwrapped_optional
|
243
262
|
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
@@ -246,12 +265,12 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
246
265
|
// webViewLoadingState = .subsequentLoad
|
247
266
|
// }
|
248
267
|
webContainerView.showLoading(false)
|
249
|
-
|
268
|
+
|
250
269
|
webContainerView.showError(true, error.localizedDescription)
|
251
270
|
CAPLog.print("⚡️ WebView failed to load")
|
252
271
|
CAPLog.print("⚡️ Error: " + error.localizedDescription)
|
253
272
|
}
|
254
|
-
|
273
|
+
|
255
274
|
// The force unwrap is part of the protocol declaration, so we should keep it.
|
256
275
|
// swiftlint:disable:next implicitly_unwrapped_optional
|
257
276
|
public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
|
@@ -263,9 +282,22 @@ extension WebContainerViewController: WKNavigationDelegate {
|
|
263
282
|
}
|
264
283
|
CAPLog.print("⚡️ WebView failed provisional navigation")
|
265
284
|
CAPLog.print("⚡️ Error: " + error.localizedDescription)
|
266
|
-
|
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) {
|
270
302
|
webView.reload()
|
271
303
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@aigens/aigens-sdk-core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.13",
|
4
4
|
"description": "Aigens Order.Place Core Plugin",
|
5
5
|
"main": "dist/plugin.cjs.js",
|
6
6
|
"module": "dist/esm/index.js",
|
@@ -74,8 +74,5 @@
|
|
74
74
|
"android": {
|
75
75
|
"src": "android"
|
76
76
|
}
|
77
|
-
},
|
78
|
-
"dependencies": {
|
79
|
-
"aigens-mono": "file:../.."
|
80
77
|
}
|
81
78
|
}
|