@aigens/aigens-sdk-core 0.0.6 → 0.0.9

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 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Core = registerPlugin('Core', {\n web: () => import('./web').then(m => new m.CoreWeb()),\n});\nexport * from './definitions';\nexport { Core };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CoreWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async getMember(options) {\n var _a, _b;\n console.log('GET MEMBER', options);\n var result = {};\n var w = window;\n result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;\n return result;\n }\n async dismiss(options) {\n console.log('DISMISS', options);\n return options;\n }\n async finish(options) {\n console.log('FINISH', options);\n return options;\n }\n async openBrowser(options) {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;AACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AACzD,CAAC;;ACFM,MAAM,OAAO,SAASC,cAAS,CAAC;AACvC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;AAC7B,QAAQ,IAAI,EAAE,EAAE,EAAE,CAAC;AACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAC3C,QAAQ,IAAI,MAAM,GAAG,EAAE,CAAC;AACxB,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC;AACvB,QAAQ,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;AAC9I,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACxC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACvC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Core = registerPlugin('Core', {\n web: () => import('./web').then(m => new m.CoreWeb()),\n});\nexport * from './definitions';\nexport { Core };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CoreWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async getMember(options) {\n var _a, _b;\n console.log('GET MEMBER', options);\n var result = {};\n var w = window;\n result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;\n return result;\n }\n async dismiss(options) {\n console.log('DISMISS', options);\n return options;\n }\n async finish(options) {\n console.log('FINISH', options);\n return options;\n }\n async openBrowser(options) {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n async isInstalledApp(options) {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n async openExternalUrl(options) {\n window.open(options.url, \"_blank\");\n return {\n open: true\n };\n }\n async getIsProductionEnvironment() {\n return { isPrd: true };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;AACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AACzD,CAAC;;ACFM,MAAM,OAAO,SAASC,cAAS,CAAC;AACvC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACrC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;AAC7B,QAAQ,IAAI,EAAE,EAAE,EAAE,CAAC;AACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AAC3C,QAAQ,IAAI,MAAM,GAAG,EAAE,CAAC;AACxB,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC;AACvB,QAAQ,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;AAC9I,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AACxC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACvC,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;AAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,MAAM,cAAc,CAAC,OAAO,EAAE;AAClC,QAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACnD,KAAK;AACL,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;AACnC,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC3C,QAAQ,OAAO;AACf,YAAY,IAAI,EAAE,IAAI;AACtB,SAAS,CAAC;AACV,KAAK;AACL,IAAI,MAAM,0BAA0B,GAAG;AACvC,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC/B,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -30,6 +30,19 @@ var capacitorCore = (function (exports, core) {
30
30
  console.log(options);
31
31
  throw new Error('Method not implemented.');
32
32
  }
33
+ async isInstalledApp(options) {
34
+ console.log(options);
35
+ throw new Error('Method not implemented.');
36
+ }
37
+ async openExternalUrl(options) {
38
+ window.open(options.url, "_blank");
39
+ return {
40
+ open: true
41
+ };
42
+ }
43
+ async getIsProductionEnvironment() {
44
+ return { isPrd: true };
45
+ }
33
46
  }
34
47
 
35
48
  var web = /*#__PURE__*/Object.freeze({
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Core = registerPlugin('Core', {\n web: () => import('./web').then(m => new m.CoreWeb()),\n});\nexport * from './definitions';\nexport { Core };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CoreWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async getMember(options) {\n var _a, _b;\n console.log('GET MEMBER', options);\n var result = {};\n var w = window;\n result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;\n return result;\n }\n async dismiss(options) {\n console.log('DISMISS', options);\n return options;\n }\n async finish(options) {\n console.log('FINISH', options);\n return options;\n }\n async openBrowser(options) {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;IACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC;;ICFM,MAAM,OAAO,SAASC,cAAS,CAAC;IACvC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;IAC7B,QAAQ,IAAI,EAAE,EAAE,EAAE,CAAC;IACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,IAAI,MAAM,GAAG,EAAE,CAAC;IACxB,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC;IACvB,QAAQ,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAC9I,QAAQ,OAAO,MAAM,CAAC;IACtB,KAAK;IACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;IAC3B,QAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;IAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst Core = registerPlugin('Core', {\n web: () => import('./web').then(m => new m.CoreWeb()),\n});\nexport * from './definitions';\nexport { Core };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CoreWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async getMember(options) {\n var _a, _b;\n console.log('GET MEMBER', options);\n var result = {};\n var w = window;\n result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;\n return result;\n }\n async dismiss(options) {\n console.log('DISMISS', options);\n return options;\n }\n async finish(options) {\n console.log('FINISH', options);\n return options;\n }\n async openBrowser(options) {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n async isInstalledApp(options) {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n async openExternalUrl(options) {\n window.open(options.url, \"_blank\");\n return {\n open: true\n };\n }\n async getIsProductionEnvironment() {\n return { isPrd: true };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,IAAI,GAAGA,mBAAc,CAAC,MAAM,EAAE;IACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IACzD,CAAC;;ICFM,MAAM,OAAO,SAASC,cAAS,CAAC;IACvC,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL,IAAI,MAAM,SAAS,CAAC,OAAO,EAAE;IAC7B,QAAQ,IAAI,EAAE,EAAE,EAAE,CAAC;IACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,IAAI,MAAM,GAAG,EAAE,CAAC;IACxB,QAAQ,IAAI,CAAC,GAAG,MAAM,CAAC;IACvB,QAAQ,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAC9I,QAAQ,OAAO,MAAM,CAAC;IACtB,KAAK;IACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;IAC3B,QAAQ,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,QAAQ,OAAO,OAAO,CAAC;IACvB,KAAK;IACL,IAAI,MAAM,WAAW,CAAC,OAAO,EAAE;IAC/B,QAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL,IAAI,MAAM,cAAc,CAAC,OAAO,EAAE;IAClC,QAAQ,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,QAAQ,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACnD,KAAK;IACL,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;IACnC,QAAQ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC3C,QAAQ,OAAO;IACf,YAAY,IAAI,EAAE,IAAI;IACtB,SAAS,CAAC;IACV,KAAK;IACL,IAAI,MAAM,0BAA0B,GAAG;IACvC,QAAQ,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC/B,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -9,4 +9,7 @@ CAP_PLUGIN(CorePlugin, "Core",
9
9
  CAP_PLUGIN_METHOD(finish, CAPPluginReturnPromise);
10
10
  CAP_PLUGIN_METHOD(openBrowser, CAPPluginReturnPromise);
11
11
  CAP_PLUGIN_METHOD(getMember, CAPPluginReturnPromise);
12
+ CAP_PLUGIN_METHOD(isInstalledApp, CAPPluginReturnPromise);
13
+ CAP_PLUGIN_METHOD(openExternalUrl, CAPPluginReturnPromise);
14
+ CAP_PLUGIN_METHOD(getIsProductionEnvironment, CAPPluginReturnPromise);
12
15
  )
@@ -8,24 +8,24 @@ import UIKit
8
8
  */
9
9
  @objc(CorePlugin)
10
10
  public class CorePlugin: CAPPlugin {
11
-
11
+
12
12
  private let implementation = Core()
13
13
  public static var member: Dictionary<String, Any>?
14
-
14
+
15
15
  @objc func echo(_ call: CAPPluginCall) {
16
16
 
17
17
  print("CorePlugin echo")
18
-
18
+
19
19
  let value = call.getString("value") ?? ""
20
20
  call.resolve([
21
21
  "value": implementation.echo(value)
22
22
  ])
23
-
24
-
23
+
24
+
25
25
  }
26
-
26
+
27
27
  @objc func dismiss(_ call: CAPPluginCall) {
28
-
28
+
29
29
  print("CorePlugin dismiss")
30
30
 
31
31
  DispatchQueue.main.async {
@@ -38,8 +38,8 @@ public class CorePlugin: CAPPlugin {
38
38
  "success": true
39
39
  //"value": implementation.echo(value)
40
40
  ])
41
-
42
-
41
+
42
+
43
43
  }
44
44
 
45
45
  @objc func getMember(_ call: CAPPluginCall) {
@@ -52,7 +52,7 @@ public class CorePlugin: CAPPlugin {
52
52
  @objc func finish(_ call: CAPPluginCall) {
53
53
 
54
54
  print("CorePlugin finish")
55
-
55
+
56
56
  DispatchQueue.main.async {
57
57
  self.bridge?.viewController?.dismiss(animated: true);
58
58
  }
@@ -69,27 +69,31 @@ public class CorePlugin: CAPPlugin {
69
69
  @objc func openBrowser(_ call: CAPPluginCall) {
70
70
 
71
71
  print("CorePlugin openBrowser")
72
-
72
+
73
73
  let url = call.getString("url")
74
74
 
75
75
 
76
76
  if(url == nil){
77
77
  return
78
78
  }
79
-
79
+
80
80
  let member = call.getObject("member")
81
-
81
+ let externalProtocols = call.getArray("externalProtocols")
82
+
82
83
  DispatchQueue.main.async {
83
84
 
84
85
  let bridgeVC = WebContainerViewController()
85
86
 
86
87
  var options = [String: AnyObject]()
87
88
  options["url"] = url as AnyObject;
88
-
89
+
89
90
  if(member != nil){
90
91
  options["member"] = member as AnyObject;
91
92
  }
92
-
93
+ if (externalProtocols != nil) {
94
+ options["externalProtocols"] = externalProtocols as AnyObject
95
+ }
96
+
93
97
  bridgeVC.options = options;
94
98
 
95
99
  bridgeVC.modalPresentationStyle = .fullScreen
@@ -104,6 +108,44 @@ public class CorePlugin: CAPPlugin {
104
108
  ])
105
109
  }
106
110
 
111
+ @objc func isInstalledApp(_ call: CAPPluginCall) {
112
+ if let url = call.getString("key"), let URL_ = URL(string: url) {
113
+ let can = UIApplication.shared.canOpenURL(URL_)
114
+ call.resolve([
115
+ "install": can
116
+ ])
117
+ }else {
118
+ call.reject("key is missing or is invaild key")
119
+ return
120
+ }
121
+ }
122
+ @objc func getIsProductionEnvironment(_ call: CAPPluginCall) {
123
+ call.resolve([
124
+ "isPrd": true
125
+ ])
126
+ }
127
+
128
+ @objc func openExternalUrl(_ call: CAPPluginCall) {
129
+ if let url = call.getString("url"), let URL_ = URL(string: url) {
130
+ let can = UIApplication.shared.canOpenURL(URL_)
131
+ if !can {
132
+ call.reject("cannot open the url:\(url)")
133
+ return;
134
+ }
135
+ if #available(iOS 10.0, *) {
136
+ UIApplication.shared.open(URL_, options: [:], completionHandler: nil)
137
+ } else {
138
+ UIApplication.shared.openURL(URL_)
139
+ }
140
+ call.resolve([
141
+ "open": true
142
+ ])
143
+
144
+ }else {
145
+ call.reject("url is missing or is invaild url")
146
+ return
147
+ }
148
+ }
107
149
 
108
150
 
109
151
 
@@ -0,0 +1,83 @@
1
+ //
2
+ // WebContainer.swift
3
+ // AigensSdkCore
4
+ //
5
+ // Created by 陈培爵 on 2022/6/7.
6
+ //
7
+
8
+ import UIKit
9
+
10
+ class WebContainer: UIView {
11
+ @IBOutlet weak var activity: UIActivityIndicatorView!
12
+
13
+ @IBOutlet weak var errorWrapper: UIView!
14
+
15
+ @IBOutlet weak var errorTextView: UITextView!
16
+
17
+ public weak var vc: WebContainerViewController?
18
+
19
+ public func setTheme(_ color: String) {
20
+ if let color = UIColor.getHex(hex: color) {
21
+ self.backgroundColor = color
22
+ }
23
+ }
24
+ override func awakeFromNib() {
25
+ super.awakeFromNib()
26
+ print("awakeFromNib")
27
+ }
28
+
29
+ private func hiddenSelf() {
30
+ self.alpha = 1.0
31
+ UIView.animate(withDuration: 0.5, animations: {
32
+ self.alpha = 0
33
+ })
34
+ }
35
+
36
+ public func showLoading(_ show: Bool) {
37
+ if show {
38
+ self.alpha = 1.0
39
+ activity.isHidden = false
40
+ activity.backgroundColor = .clear
41
+ activity.color = .darkGray
42
+ activity.alpha = 1.0
43
+ }else {
44
+ hiddenSelf()
45
+ activity?.isHidden = true
46
+ }
47
+ }
48
+ public func showError(_ show: Bool, _ error: String? = nil) {
49
+ if let e = error {
50
+ errorTextView?.text = e
51
+ }
52
+ if show {
53
+ errorWrapper?.isHidden = false
54
+ self.alpha = 1.0
55
+ }else {
56
+ errorWrapper?.isHidden = true
57
+ self.alpha = 0
58
+ }
59
+
60
+ }
61
+
62
+ /*
63
+ // Only override draw() if you perform custom drawing.
64
+ // An empty implementation adversely affects performance during animation.
65
+ override func draw(_ rect: CGRect) {
66
+ // Drawing code
67
+ }
68
+ */
69
+ @IBAction func dismiss(_ sender: UIButton) {
70
+ self.vc?.dismiss(animated: true);
71
+ }
72
+
73
+ @IBAction func reload(_ sender: UIButton) {
74
+ self.vc?.webView?.reload()
75
+ }
76
+ }
77
+
78
+ extension WebContainer {
79
+ class func webContainer() -> WebContainer {
80
+ let bundle = Bundle(for: WebContainer.self)
81
+ return bundle.loadNibNamed("WebContainer", owner: self, options: nil)?.first as! WebContainer
82
+ }
83
+ }
@@ -0,0 +1,113 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3
+ <device id="retina6_1" orientation="portrait" appearance="light"/>
4
+ <dependencies>
5
+ <deployment identifier="iOS"/>
6
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
7
+ <capability name="Safe area layout guides" minToolsVersion="9.0"/>
8
+ <capability name="System colors in document resources" minToolsVersion="11.0"/>
9
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
10
+ </dependencies>
11
+ <objects>
12
+ <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
13
+ <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14
+ <view contentMode="scaleToFill" id="iN0-l3-epB" customClass="WebContainer" customModule="Plugin" customModuleProvider="target">
15
+ <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
16
+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
17
+ <subviews>
18
+ <activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="large" translatesAutoresizingMaskIntoConstraints="NO" id="QRW-cT-ZYH">
19
+ <rect key="frame" x="188.5" y="119" width="37" height="37"/>
20
+ <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
21
+ <color key="color" systemColor="secondaryLabelColor"/>
22
+ </activityIndicatorView>
23
+ <view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9XO-W2-mxO" userLabel="errorWrapper">
24
+ <rect key="frame" x="0.0" y="206" width="414" height="690"/>
25
+ <subviews>
26
+ <view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XSc-rN-cN8">
27
+ <rect key="frame" x="206.5" y="560" width="1" height="100"/>
28
+ <color key="backgroundColor" systemColor="systemBackgroundColor"/>
29
+ <constraints>
30
+ <constraint firstAttribute="width" constant="1" id="JtJ-kb-hPE"/>
31
+ <constraint firstAttribute="height" constant="100" id="SFb-3i-Gvl"/>
32
+ </constraints>
33
+ </view>
34
+ <button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rie-2B-ejA" userLabel="reload">
35
+ <rect key="frame" x="237.5" y="579" width="70" height="31"/>
36
+ <color key="backgroundColor" systemColor="linkColor"/>
37
+ <state key="normal" title="Button"/>
38
+ <buttonConfiguration key="configuration" style="filled" title="Reload">
39
+ <color key="baseForegroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
40
+ </buttonConfiguration>
41
+ <connections>
42
+ <action selector="reload:" destination="iN0-l3-epB" eventType="touchUpInside" id="PwX-vF-t6u"/>
43
+ </connections>
44
+ </button>
45
+ <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" text="Got some errors, please try again later." textAlignment="center" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8vI-mF-YrJ">
46
+ <rect key="frame" x="30" y="30" width="354" height="519"/>
47
+ <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
48
+ <color key="textColor" systemColor="systemPinkColor"/>
49
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
50
+ <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
51
+ </textView>
52
+ <button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3jG-Lv-8dD" userLabel="back">
53
+ <rect key="frame" x="120.5" y="579" width="70" height="31"/>
54
+ <color key="backgroundColor" systemColor="linkColor"/>
55
+ <state key="normal" title="Button"/>
56
+ <buttonConfiguration key="configuration" style="filled" title="Back">
57
+ <color key="baseForegroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
58
+ </buttonConfiguration>
59
+ <connections>
60
+ <action selector="dismiss:" destination="iN0-l3-epB" eventType="touchUpInside" id="uVj-47-Wse"/>
61
+ </connections>
62
+ </button>
63
+ </subviews>
64
+ <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
65
+ <constraints>
66
+ <constraint firstItem="8vI-mF-YrJ" firstAttribute="leading" secondItem="9XO-W2-mxO" secondAttribute="leading" constant="30" id="AS7-Ga-vyq"/>
67
+ <constraint firstItem="Rie-2B-ejA" firstAttribute="leading" secondItem="XSc-rN-cN8" secondAttribute="trailing" constant="30" id="CyI-hc-XkI"/>
68
+ <constraint firstItem="3jG-Lv-8dD" firstAttribute="bottom" secondItem="Rie-2B-ejA" secondAttribute="bottom" id="HAh-cE-mQ6"/>
69
+ <constraint firstItem="XSc-rN-cN8" firstAttribute="leading" secondItem="3jG-Lv-8dD" secondAttribute="trailing" constant="30" id="PAe-EE-twu"/>
70
+ <constraint firstAttribute="bottom" secondItem="XSc-rN-cN8" secondAttribute="bottom" constant="30" id="RPJ-VJ-HXw"/>
71
+ <constraint firstAttribute="bottom" secondItem="3jG-Lv-8dD" secondAttribute="bottom" constant="80" id="Upv-ms-zNA"/>
72
+ <constraint firstItem="8vI-mF-YrJ" firstAttribute="top" secondItem="9XO-W2-mxO" secondAttribute="top" constant="30" id="YIP-1g-G6E"/>
73
+ <constraint firstItem="3jG-Lv-8dD" firstAttribute="top" secondItem="8vI-mF-YrJ" secondAttribute="bottom" constant="30" id="aeR-w6-BjA"/>
74
+ <constraint firstItem="8vI-mF-YrJ" firstAttribute="centerX" secondItem="9XO-W2-mxO" secondAttribute="centerX" id="kmK-Va-dvk"/>
75
+ <constraint firstAttribute="trailing" secondItem="8vI-mF-YrJ" secondAttribute="trailing" constant="30" id="mUr-wg-3M2"/>
76
+ <constraint firstItem="XSc-rN-cN8" firstAttribute="centerX" secondItem="9XO-W2-mxO" secondAttribute="centerX" id="pNO-0x-6Wm"/>
77
+ </constraints>
78
+ </view>
79
+ </subviews>
80
+ <viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
81
+ <color key="backgroundColor" systemColor="systemBackgroundColor"/>
82
+ <constraints>
83
+ <constraint firstItem="QRW-cT-ZYH" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="75" id="R5H-tF-5z7"/>
84
+ <constraint firstItem="9XO-W2-mxO" firstAttribute="top" secondItem="QRW-cT-ZYH" secondAttribute="bottom" constant="50" id="X4C-yj-HyP"/>
85
+ <constraint firstAttribute="bottom" secondItem="9XO-W2-mxO" secondAttribute="bottom" id="cOL-UR-HYb"/>
86
+ <constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="9XO-W2-mxO" secondAttribute="trailing" id="fAe-qZ-xE4"/>
87
+ <constraint firstItem="9XO-W2-mxO" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="haw-0Q-SQQ"/>
88
+ <constraint firstItem="QRW-cT-ZYH" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="lwz-JW-uoD"/>
89
+ </constraints>
90
+ <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
91
+ <connections>
92
+ <outlet property="activity" destination="QRW-cT-ZYH" id="fKy-zs-iDE"/>
93
+ <outlet property="errorTextView" destination="8vI-mF-YrJ" id="4uw-Iq-Axh"/>
94
+ <outlet property="errorWrapper" destination="9XO-W2-mxO" id="ipj-rF-hT1"/>
95
+ </connections>
96
+ <point key="canvasLocation" x="137.68115942028987" y="102.45535714285714"/>
97
+ </view>
98
+ </objects>
99
+ <resources>
100
+ <systemColor name="linkColor">
101
+ <color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
102
+ </systemColor>
103
+ <systemColor name="secondaryLabelColor">
104
+ <color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
105
+ </systemColor>
106
+ <systemColor name="systemBackgroundColor">
107
+ <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
108
+ </systemColor>
109
+ <systemColor name="systemPinkColor">
110
+ <color red="1" green="0.17647058823529413" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
111
+ </systemColor>
112
+ </resources>
113
+ </document>
@@ -11,15 +11,99 @@ import Capacitor
11
11
 
12
12
  @objc open class WebContainerViewController: CAPBridgeViewController {
13
13
 
14
+ // {themeColor: "#xxxxxx"}
14
15
  public var options: Dictionary<String, Any>?
15
-
16
+
17
+ var externalProtocols: [String] = [
18
+ "octopus://", "alipay://", "alipays://", "alipayhk://", "https://itunes.apple.com", "tel:", "mailto:", "itms-apps://itunes.apple.com", "https://apps.apple.com", "payme://"
19
+ ]
20
+ let containerView = WebContainer.webContainer()
21
+ var webContainerView: WebContainer {
22
+ return containerView
23
+ }
16
24
  override open func viewDidLoad() {
17
25
 
18
26
  print("WebContainerViewController viewDidLoad")
19
27
 
20
28
  self.becomeFirstResponder()
21
29
  loadWebViewCustom()
22
- //loadWebView()
30
+ initView()
31
+
32
+ }
33
+
34
+ private func initView(){
35
+
36
+ print("VC initView")
37
+
38
+ //let bundle = Bundle(for: WebContainerViewController.self)
39
+ //let containerView = WebContainerView()
40
+ //let containerView = bundle.loadNibNamed("WebContainerView", owner: self, options: nil)?.first as! UIView
41
+
42
+ self.view.addSubview(webContainerView)
43
+ webContainerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
44
+ setupOptions(webContainerView)
45
+ containerView.vc = self
46
+
47
+ //
48
+ //
49
+
50
+
51
+ // let containerView = WebContainerView()
52
+ // self.view = containerView
53
+ //
54
+ // //containerView.frame = self.view!.bounds
55
+ // containerView.backgroundColor = UIColor.red
56
+ // containerView.translatesAutoresizingMaskIntoConstraints = false
57
+ //
58
+ // let webview = self.webView
59
+ // webview?.frame = containerView.webArea!.bounds
60
+ // webview?.frame.size = containerView.webArea.frame.size
61
+ // containerView.webArea.addSubview(self.webView!)
62
+ //
63
+
64
+
65
+ }
66
+
67
+ open override func viewWillLayoutSubviews() {
68
+ super.viewWillLayoutSubviews()
69
+ webContainerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
70
+ }
71
+
72
+ private func setupOptions(_ view: WebContainer) {
73
+ if let theme = self.options?["themeColor"] as? String, let color = UIColor.getHex(hex: theme) {
74
+ self.view.backgroundColor = color
75
+ self.webView?.backgroundColor = color
76
+ self.webView?.scrollView.backgroundColor = color
77
+ view.setTheme(theme)
78
+ }
79
+ if let externalProtocols = options?["externalProtocols"] as? [String] {
80
+ self.externalProtocols.append(contentsOf: externalProtocols)
81
+ }
82
+
83
+ }
84
+
85
+ public final func loadWebViewCustom() {
86
+
87
+ //let bridge = self.bridge
88
+ //let plugins = self.bridge["plugins"]
89
+
90
+
91
+ let urlString = self.options?["url"] as? String;
92
+
93
+ if(urlString == nil){
94
+ return;
95
+ }
96
+
97
+ let url = URL(string: urlString!)
98
+
99
+ let member = self.options?["member"] as? Dictionary<String, Any>
100
+
101
+ CorePlugin.member = member
102
+
103
+ //bridge.webViewDelegationHandler.willLoadWebview(webView)
104
+ _ = webView?.load(URLRequest(url: url!))
105
+ webView?.navigationDelegate = self
106
+
23
107
  }
24
108
 
25
109
  //this method overwrite parent to return a desc with custom config.json
@@ -48,29 +132,153 @@ import Capacitor
48
132
 
49
133
  return descriptor
50
134
  }
135
+
136
+ deinit {
137
+ print("WebContainerViewController deinit")
138
+ }
51
139
 
52
- public final func loadWebViewCustom() {
53
-
54
- //let bridge = self.bridge
55
- //let plugins = self.bridge["plugins"]
56
-
140
+
141
+ }
57
142
 
58
- let urlString = self.options?["url"] as? String;
143
+ extension WebContainerViewController: WKNavigationDelegate {
144
+ // The force unwrap is part of the protocol declaration, so we should keep it.
145
+ // swiftlint:disable:next implicitly_unwrapped_optional
146
+ public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
147
+ // Reset the bridge on each navigation
148
+ // self.bridge?.reset()
149
+ }
150
+
151
+ public func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
152
+ webContainerView.showError(false)
153
+ webContainerView.showLoading(true)
154
+ }
155
+
156
+ public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
157
+ // post a notification for any listeners
158
+ NotificationCenter.default.post(name: .capacitorDecidePolicyForNavigationAction, object: navigationAction)
59
159
 
60
- if(urlString == nil){
61
- return;
160
+ // sanity check, these shouldn't ever be nil in practice
161
+ guard let bridge = bridge, let navURL = navigationAction.request.url else {
162
+ decisionHandler(.allow)
163
+ return
62
164
  }
63
-
64
- let url = URL(string: urlString!)
65
-
66
- let member = self.options?["member"] as? Dictionary<String, Any>
67
165
 
68
- CorePlugin.member = member
166
+ var isCanOpen = false
167
+ if externalProtocols.count > 0 {
168
+ externalProtocols.forEach { (url) in
169
+ if (navURL.absoluteString.starts(with: url)) {
170
+ isCanOpen = UIApplication.shared.canOpenURL(navURL) ;
171
+ return;
172
+ }
173
+ }
174
+ }
69
175
 
176
+ if isCanOpen {
177
+ if #available(iOS 10.0, *) {
178
+ UIApplication.shared.open(navURL, options: [:], completionHandler: nil);
179
+ } else {
180
+ UIApplication.shared.openURL(navURL)
181
+ }
182
+ decisionHandler(.cancel)
183
+ return;
184
+ }
70
185
 
71
- //bridge.webViewDelegationHandler.willLoadWebview(webView)
72
- _ = webView?.load(URLRequest(url: url!))
73
186
 
187
+ // first, give plugins the chance to handle the decision
188
+ // for pluginObject in bridge.plugins {
189
+ // let plugin = pluginObject.value
190
+ // let selector = NSSelectorFromString("shouldOverrideLoad:")
191
+ // if plugin.responds(to: selector) {
192
+ // let shouldOverrideLoad = plugin.shouldOverrideLoad(navigationAction)
193
+ // if shouldOverrideLoad != nil {
194
+ // if shouldOverrideLoad == true {
195
+ // decisionHandler(.cancel)
196
+ // return
197
+ // } else if shouldOverrideLoad == false {
198
+ // decisionHandler(.allow)
199
+ // return
200
+ // }
201
+ // }
202
+ // }
203
+ // }
204
+
205
+ // next, check if this is covered by the allowedNavigation configuration
206
+ if let host = navURL.host, bridge.config.shouldAllowNavigation(to: host) {
207
+ decisionHandler(.allow)
208
+ return
209
+ }
210
+
211
+ // otherwise, is this a new window or a main frame navigation but to an outside source
212
+ let toplevelNavigation = (navigationAction.targetFrame == nil || navigationAction.targetFrame?.isMainFrame == true)
213
+ if navURL.absoluteString.contains(bridge.config.serverURL.absoluteString) == false, toplevelNavigation {
214
+ // disallow and let the system handle it
215
+ if UIApplication.shared.applicationState == .active {
216
+ UIApplication.shared.open(navURL, options: [:], completionHandler: nil)
217
+ }
218
+ decisionHandler(.cancel)
219
+ return
220
+ }
221
+
222
+ // fallthrough to allowing it
223
+ decisionHandler(.allow)
224
+ }
225
+
226
+
227
+ // The force unwrap is part of the protocol declaration, so we should keep it.
228
+ // swiftlint:disable:next implicitly_unwrapped_optional
229
+ public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
230
+ // if case .initialLoad(let isOpaque) = webViewLoadingState {
231
+ // webView.isOpaque = isOpaque
232
+ // webViewLoadingState = .subsequentLoad
233
+ // }
234
+ webContainerView.showLoading(false)
235
+ webContainerView.showError(false)
236
+ CAPLog.print("⚡️ WebView loaded")
237
+ }
238
+
239
+ // The force unwrap is part of the protocol declaration, so we should keep it.
240
+ // swiftlint:disable:next implicitly_unwrapped_optional
241
+ public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
242
+ // if case .initialLoad(let isOpaque) = webViewLoadingState {
243
+ // webView.isOpaque = isOpaque
244
+ // webViewLoadingState = .subsequentLoad
245
+ // }
246
+ webContainerView.showLoading(false)
247
+
248
+ webContainerView.showError(true, error.localizedDescription)
249
+ CAPLog.print("⚡️ WebView failed to load")
250
+ CAPLog.print("⚡️ Error: " + error.localizedDescription)
251
+ }
252
+
253
+ // The force unwrap is part of the protocol declaration, so we should keep it.
254
+ // swiftlint:disable:next implicitly_unwrapped_optional
255
+ public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
256
+ webContainerView.showLoading(false)
257
+ // cancel
258
+ let e = error as NSError
259
+ if (e.code == NSURLErrorCancelled || e.code == -999) {
260
+ webContainerView.showError(false)
261
+ }
262
+ CAPLog.print("⚡️ WebView failed provisional navigation")
263
+ CAPLog.print("⚡️ Error: " + error.localizedDescription)
264
+ webContainerView.showError(true, error.localizedDescription)
265
+ }
266
+
267
+ public func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
268
+ webView.reload()
269
+ }
270
+ }
74
271
 
272
+ extension UIColor {
273
+ static func getHex(hex: String, _ alpha: CGFloat = 1.0) -> UIColor? {
274
+ guard !hex.isEmpty && hex.hasPrefix("#") else { return nil }
275
+ var rgbValue: UInt32 = 0
276
+ let scanner = Scanner(string: hex)
277
+ scanner.scanLocation = 1
278
+ guard scanner.scanHexInt32(&rgbValue) else { return nil }
279
+ return UIColor(red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
280
+ green: CGFloat((rgbValue & 0xFF00) >> 8) / 255.0,
281
+ blue: CGFloat((rgbValue & 0xFF)) / 255.0,
282
+ alpha: alpha);
75
283
  }
76
284
  }