@aigens/aigens-sdk-core 0.0.5 → 0.0.6

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.
package/README.md CHANGED
@@ -14,10 +14,10 @@ npx cap sync
14
14
  <docgen-index>
15
15
 
16
16
  * [`echo(...)`](#echo)
17
+ * [`dismiss(...)`](#dismiss)
17
18
  * [`finish(...)`](#finish)
18
19
  * [`getMember(...)`](#getmember)
19
20
  * [`openBrowser(...)`](#openbrowser)
20
- * [`scan(...)`](#scan)
21
21
 
22
22
  </docgen-index>
23
23
 
@@ -39,10 +39,10 @@ echo(options: any) => Promise<any>
39
39
  --------------------
40
40
 
41
41
 
42
- ### finish(...)
42
+ ### dismiss(...)
43
43
 
44
44
  ```typescript
45
- finish(options: any) => Promise<any>
45
+ dismiss(options: any) => Promise<any>
46
46
  ```
47
47
 
48
48
  | Param | Type |
@@ -54,10 +54,10 @@ finish(options: any) => Promise<any>
54
54
  --------------------
55
55
 
56
56
 
57
- ### getMember(...)
57
+ ### finish(...)
58
58
 
59
59
  ```typescript
60
- getMember(options: any) => Promise<any>
60
+ finish(options: any) => Promise<any>
61
61
  ```
62
62
 
63
63
  | Param | Type |
@@ -69,10 +69,10 @@ getMember(options: any) => Promise<any>
69
69
  --------------------
70
70
 
71
71
 
72
- ### openBrowser(...)
72
+ ### getMember(...)
73
73
 
74
74
  ```typescript
75
- openBrowser(options: any) => Promise<any>
75
+ getMember(options: any) => Promise<any>
76
76
  ```
77
77
 
78
78
  | Param | Type |
@@ -84,10 +84,10 @@ openBrowser(options: any) => Promise<any>
84
84
  --------------------
85
85
 
86
86
 
87
- ### scan(...)
87
+ ### openBrowser(...)
88
88
 
89
89
  ```typescript
90
- scan(options: any) => Promise<any>
90
+ openBrowser(options: any) => Promise<any>
91
91
  ```
92
92
 
93
93
  | Param | Type |
@@ -53,9 +53,6 @@ dependencies {
53
53
  implementation project(':capacitor-android')
54
54
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
55
 
56
- implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
57
- implementation 'com.google.zxing:core:3.3.0'
58
-
59
56
  testImplementation "junit:junit:$junitVersion"
60
57
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
61
58
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -12,8 +12,6 @@ import com.getcapacitor.Plugin;
12
12
  import com.getcapacitor.PluginCall;
13
13
  import com.getcapacitor.PluginMethod;
14
14
  import com.getcapacitor.annotation.CapacitorPlugin;
15
- import com.journeyapps.barcodescanner.ScanContract;
16
- import com.journeyapps.barcodescanner.ScanOptions;
17
15
 
18
16
  import org.json.JSONException;
19
17
 
@@ -25,7 +23,7 @@ import java.util.Map;
25
23
  @CapacitorPlugin(name = "Core")
26
24
  public class CorePlugin extends Plugin {
27
25
 
28
- public static boolean DEBUG = false;
26
+ public static boolean DEBUG = true;
29
27
 
30
28
  private static Map member;
31
29
 
@@ -44,11 +42,6 @@ public class CorePlugin extends Plugin {
44
42
  @Override
45
43
  protected void handleOnStart(){
46
44
 
47
- debug("CorePlugin handleOnStart");
48
-
49
- prepareScan();
50
-
51
- debug("CorePlugin handleOnStart END");
52
45
  }
53
46
 
54
47
  @PluginMethod()
@@ -72,83 +65,6 @@ public class CorePlugin extends Plugin {
72
65
  call.resolve(ret);
73
66
  }
74
67
 
75
- private PluginCall scanCall;
76
-
77
- @PluginMethod()
78
- public void scan(PluginCall call) {
79
-
80
- debug("SCANNING!!");
81
-
82
- this.scanCall = call;
83
- scanRaw();
84
-
85
-
86
- }
87
-
88
- // Register the launcher and result handler
89
-
90
- private ActivityResultLauncher<ScanOptions> barcodeLauncher;
91
-
92
- private void prepareScan(){
93
-
94
- AppCompatActivity act = getActivity();
95
-
96
- barcodeLauncher = act.registerForActivityResult(new ScanContract(),
97
- result -> {
98
-
99
- if(scanCall == null){
100
- debug("Missing scan callback");
101
- return;
102
- }
103
-
104
- if(result.getContents() == null) {
105
- //Toast.makeText(MyActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
106
- debug("scan cancelled");
107
- JSObject ret = new JSObject();
108
- ret.put("hasContent", false);
109
- ret.put("success", false);
110
- scanCall.resolve(ret);
111
- } else {
112
- //Toast.makeText(MyActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
113
- String val = result.getContents();
114
-
115
- debug("scan result:" + val);
116
-
117
- if(val != null && val.length() > 0){
118
-
119
- JSObject ret = new JSObject();
120
- ret.put("content", val);
121
- ret.put("hasContent", true);
122
- ret.put("success", true);
123
- scanCall.resolve(ret);
124
- }else{
125
-
126
- JSObject ret = new JSObject();
127
- ret.put("hasContent", false);
128
- ret.put("success", false);
129
- scanCall.resolve(ret);
130
- }
131
-
132
-
133
-
134
- }
135
- scanCall = null;
136
- });
137
- }
138
-
139
- private void scanRaw(){
140
-
141
- ScanOptions options = new ScanOptions();
142
- //options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
143
- options.setPrompt("");
144
- //options.setCameraId(0); // Use a specific camera of the device
145
- options.setBeepEnabled(false);
146
- options.setOrientationLocked(false);
147
- options.setBarcodeImageEnabled(true);
148
-
149
- //options.setBarcodeImageEnabled(true);
150
- barcodeLauncher.launch(options);
151
- }
152
68
 
153
69
  // Launch
154
70
  //public void onButtonClick(View view) {
@@ -162,6 +78,13 @@ public class CorePlugin extends Plugin {
162
78
 
163
79
  }
164
80
 
81
+ @PluginMethod()
82
+ public void dismiss(PluginCall call) {
83
+
84
+ getActivity().finish();
85
+
86
+ }
87
+
165
88
  @PluginMethod()
166
89
  public void openBrowser(PluginCall call) {
167
90
 
package/dist/docs.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "slug": "echo"
23
23
  },
24
24
  {
25
- "name": "finish",
25
+ "name": "dismiss",
26
26
  "signature": "(options: any) => Promise<any>",
27
27
  "parameters": [
28
28
  {
@@ -35,10 +35,10 @@
35
35
  "tags": [],
36
36
  "docs": "",
37
37
  "complexTypes": [],
38
- "slug": "finish"
38
+ "slug": "dismiss"
39
39
  },
40
40
  {
41
- "name": "getMember",
41
+ "name": "finish",
42
42
  "signature": "(options: any) => Promise<any>",
43
43
  "parameters": [
44
44
  {
@@ -51,10 +51,10 @@
51
51
  "tags": [],
52
52
  "docs": "",
53
53
  "complexTypes": [],
54
- "slug": "getmember"
54
+ "slug": "finish"
55
55
  },
56
56
  {
57
- "name": "openBrowser",
57
+ "name": "getMember",
58
58
  "signature": "(options: any) => Promise<any>",
59
59
  "parameters": [
60
60
  {
@@ -67,10 +67,10 @@
67
67
  "tags": [],
68
68
  "docs": "",
69
69
  "complexTypes": [],
70
- "slug": "openbrowser"
70
+ "slug": "getmember"
71
71
  },
72
72
  {
73
- "name": "scan",
73
+ "name": "openBrowser",
74
74
  "signature": "(options: any) => Promise<any>",
75
75
  "parameters": [
76
76
  {
@@ -83,7 +83,7 @@
83
83
  "tags": [],
84
84
  "docs": "",
85
85
  "complexTypes": [],
86
- "slug": "scan"
86
+ "slug": "openbrowser"
87
87
  }
88
88
  ],
89
89
  "properties": []
@@ -1,7 +1,7 @@
1
1
  export interface CorePlugin {
2
2
  echo(options: any): Promise<any>;
3
+ dismiss(options: any): Promise<any>;
3
4
  finish(options: any): Promise<any>;
4
5
  getMember(options: any): Promise<any>;
5
6
  openBrowser(options: any): Promise<any>;
6
- scan(options: any): Promise<any>;
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CorePlugin {\n echo(options: any): Promise<any>;\n finish(options: any): Promise<any>;\n getMember(options: any): Promise<any>;\n openBrowser(options: any): Promise<any>;\n scan(options: any): Promise<any>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CorePlugin {\n echo(options: any): Promise<any>;\n dismiss(options: any): Promise<any>;\n finish(options: any): Promise<any>;\n getMember(options: any): Promise<any>;\n openBrowser(options: any): Promise<any>;\n\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { CorePlugin } from './definitions';
3
3
  export declare class CoreWeb extends WebPlugin implements CorePlugin {
4
4
  echo(options: any): Promise<any>;
5
5
  getMember(options: any): Promise<any>;
6
+ dismiss(options: any): Promise<any>;
6
7
  finish(options: any): Promise<any>;
7
8
  openBrowser(options: any): Promise<any>;
8
- scan(options: any): Promise<any>;
9
9
  }
package/dist/esm/web.js CHANGED
@@ -12,6 +12,10 @@ export class CoreWeb extends WebPlugin {
12
12
  result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;
13
13
  return result;
14
14
  }
15
+ async dismiss(options) {
16
+ console.log('DISMISS', options);
17
+ return options;
18
+ }
15
19
  async finish(options) {
16
20
  console.log('FINISH', options);
17
21
  return options;
@@ -20,9 +24,5 @@ export class CoreWeb extends WebPlugin {
20
24
  console.log(options);
21
25
  throw new Error('Method not implemented.');
22
26
  }
23
- async scan(options) {
24
- console.log(options);
25
- throw new Error('Method not implemented.');
26
- }
27
27
  }
28
28
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,OAAQ,SAAQ,SAAS;IAClC,KAAK,CAAC,IAAI,CAAC,OAAY;QACnB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAY;;QACxB,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACnC,IAAI,MAAM,GAAG,EAAS,CAAC;QACvB,IAAI,CAAC,GAAG,MAAa,CAAC;QACtB,MAAM,CAAC,MAAM,eAAG,CAAC,CAAC,MAAM,0CAAE,OAAO,0CAAE,MAAM,CAAC;QAC1C,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAY;QACrB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAY;QAC1B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAY;QACnB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CACJ","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { CorePlugin } from './definitions';\n\n\nexport class CoreWeb extends WebPlugin implements CorePlugin {\n async echo(options: any): Promise<any> {\n console.log('ECHO', options);\n return options;\n }\n\n async getMember(options: any): Promise<any> {\n console.log('GET MEMBER', options);\n var result = {} as any;\n var w = window as any;\n result.member = w.aigens?.context?.member;\n return result;\n }\n\n async finish(options: any): Promise<any> {\n console.log('FINISH', options);\n return options;\n }\n\n async openBrowser(options: any): Promise<any> {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n\n async scan(options: any): Promise<any> {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,OAAQ,SAAQ,SAAS;IAClC,KAAK,CAAC,IAAI,CAAC,OAAY;QACnB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAY;;QACxB,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QACnC,IAAI,MAAM,GAAG,EAAS,CAAC;QACvB,IAAI,CAAC,GAAG,MAAa,CAAC;QACtB,MAAM,CAAC,MAAM,eAAG,CAAC,CAAC,MAAM,0CAAE,OAAO,0CAAE,MAAM,CAAC;QAC1C,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAY;QACtB,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAY;QACrB,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAY;QAC1B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;CAGJ","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { CorePlugin } from './definitions';\n\n\nexport class CoreWeb extends WebPlugin implements CorePlugin {\n async echo(options: any): Promise<any> {\n console.log('ECHO', options);\n return options;\n }\n\n async getMember(options: any): Promise<any> {\n console.log('GET MEMBER', options);\n var result = {} as any;\n var w = window as any;\n result.member = w.aigens?.context?.member;\n return result;\n }\n\n async dismiss(options: any): Promise<any> {\n console.log('DISMISS', options);\n return options;\n }\n\n async finish(options: any): Promise<any> {\n console.log('FINISH', options);\n return options;\n }\n\n async openBrowser(options: any): Promise<any> {\n console.log(options);\n throw new Error('Method not implemented.');\n }\n\n\n}\n"]}
@@ -21,6 +21,10 @@ class CoreWeb extends core.WebPlugin {
21
21
  result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;
22
22
  return result;
23
23
  }
24
+ async dismiss(options) {
25
+ console.log('DISMISS', options);
26
+ return options;
27
+ }
24
28
  async finish(options) {
25
29
  console.log('FINISH', options);
26
30
  return options;
@@ -29,10 +33,6 @@ class CoreWeb extends core.WebPlugin {
29
33
  console.log(options);
30
34
  throw new Error('Method not implemented.');
31
35
  }
32
- async scan(options) {
33
- console.log(options);
34
- throw new Error('Method not implemented.');
35
- }
36
36
  }
37
37
 
38
38
  var web = /*#__PURE__*/Object.freeze({
@@ -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 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 scan(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,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,IAAI,CAAC,OAAO,EAAE;AACxB,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}\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;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -18,6 +18,10 @@ var capacitorCore = (function (exports, core) {
18
18
  result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;
19
19
  return result;
20
20
  }
21
+ async dismiss(options) {
22
+ console.log('DISMISS', options);
23
+ return options;
24
+ }
21
25
  async finish(options) {
22
26
  console.log('FINISH', options);
23
27
  return options;
@@ -26,10 +30,6 @@ var capacitorCore = (function (exports, core) {
26
30
  console.log(options);
27
31
  throw new Error('Method not implemented.');
28
32
  }
29
- async scan(options) {
30
- console.log(options);
31
- throw new Error('Method not implemented.');
32
- }
33
33
  }
34
34
 
35
35
  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 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 scan(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,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,IAAI,CAAC,OAAO,EAAE;IACxB,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}\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;;;;;;;;;;;;;;;;;"}
@@ -5,8 +5,8 @@
5
5
  // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
6
  CAP_PLUGIN(CorePlugin, "Core",
7
7
  CAP_PLUGIN_METHOD(echo, CAPPluginReturnPromise);
8
+ CAP_PLUGIN_METHOD(dismiss, CAPPluginReturnPromise);
8
9
  CAP_PLUGIN_METHOD(finish, CAPPluginReturnPromise);
9
10
  CAP_PLUGIN_METHOD(openBrowser, CAPPluginReturnPromise);
10
- CAP_PLUGIN_METHOD(scan, CAPPluginReturnPromise);
11
11
  CAP_PLUGIN_METHOD(getMember, CAPPluginReturnPromise);
12
12
  )
@@ -1,6 +1,5 @@
1
1
  import Foundation
2
2
  import Capacitor
3
- import AVFoundation
4
3
  import UIKit
5
4
 
6
5
  /**
@@ -8,19 +7,39 @@ import UIKit
8
7
  * here: https://capacitorjs.com/docs/plugins/ios
9
8
  */
10
9
  @objc(CorePlugin)
11
- public class CorePlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegate {
10
+ public class CorePlugin: CAPPlugin {
12
11
 
13
12
  private let implementation = Core()
14
13
  public static var member: Dictionary<String, Any>?
15
14
 
16
15
  @objc func echo(_ call: CAPPluginCall) {
17
16
 
17
+ print("CorePlugin echo")
18
+
18
19
  let value = call.getString("value") ?? ""
19
20
  call.resolve([
20
21
  "value": implementation.echo(value)
21
22
  ])
22
23
 
23
24
 
25
+ }
26
+
27
+ @objc func dismiss(_ call: CAPPluginCall) {
28
+
29
+ print("CorePlugin dismiss")
30
+
31
+ DispatchQueue.main.async {
32
+ self.bridge?.viewController?.dismiss(animated: true);
33
+ }
34
+
35
+
36
+ //let value = call.getString("value") ?? ""
37
+ call.resolve([
38
+ "success": true
39
+ //"value": implementation.echo(value)
40
+ ])
41
+
42
+
24
43
  }
25
44
 
26
45
  @objc func getMember(_ call: CAPPluginCall) {
@@ -32,6 +51,8 @@ public class CorePlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegate {
32
51
 
33
52
  @objc func finish(_ call: CAPPluginCall) {
34
53
 
54
+ print("CorePlugin finish")
55
+
35
56
  DispatchQueue.main.async {
36
57
  self.bridge?.viewController?.dismiss(animated: true);
37
58
  }
@@ -44,24 +65,11 @@ public class CorePlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegate {
44
65
  ])
45
66
  }
46
67
 
47
- @objc func scan(_ call: CAPPluginCall) {
48
-
49
- let cancelButton = call.getString("cancelButton")
50
- if(cancelButton != nil){
51
- self.cancelText = cancelButton!
52
- }else{
53
- self.cancelText = "Cancel"
54
- }
55
-
56
- DispatchQueue.main.async {
57
- self.loadScan()
58
- self.startScan(call)
59
- }
60
- }
61
-
62
68
 
63
69
  @objc func openBrowser(_ call: CAPPluginCall) {
64
70
 
71
+ print("CorePlugin openBrowser")
72
+
65
73
  let url = call.getString("url")
66
74
 
67
75
 
@@ -96,561 +104,8 @@ public class CorePlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegate {
96
104
  ])
97
105
  }
98
106
 
99
- //SCAN PLAUGIN HERE
100
107
 
101
- class CameraView: UIView {
102
- var videoPreviewLayer:AVCaptureVideoPreviewLayer?
103
-
104
- func interfaceOrientationToVideoOrientation(_ orientation : UIInterfaceOrientation) -> AVCaptureVideoOrientation {
105
- switch (orientation) {
106
- case UIInterfaceOrientation.portrait:
107
- return AVCaptureVideoOrientation.portrait
108
- case UIInterfaceOrientation.portraitUpsideDown:
109
- return AVCaptureVideoOrientation.portraitUpsideDown
110
- case UIInterfaceOrientation.landscapeLeft:
111
- return AVCaptureVideoOrientation.landscapeLeft
112
- case UIInterfaceOrientation.landscapeRight:
113
- return AVCaptureVideoOrientation.landscapeRight
114
- default:
115
- return AVCaptureVideoOrientation.portraitUpsideDown
116
- }
117
- }
118
-
119
- override func layoutSubviews() {
120
- super.layoutSubviews()
121
- if let sublayers = self.layer.sublayers {
122
- for layer in sublayers {
123
- layer.frame = self.bounds
124
- }
125
- }
126
-
127
- self.videoPreviewLayer?.connection?.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation)
128
- }
129
-
130
-
131
- func addPreviewLayer(_ previewLayer:AVCaptureVideoPreviewLayer?) {
132
- previewLayer!.videoGravity = AVLayerVideoGravity.resizeAspectFill
133
- previewLayer!.frame = self.bounds
134
- self.layer.addSublayer(previewLayer!)
135
- self.videoPreviewLayer = previewLayer
136
- }
137
-
138
- func removePreviewLayer() {
139
- if self.videoPreviewLayer != nil {
140
- self.videoPreviewLayer!.removeFromSuperlayer()
141
- self.videoPreviewLayer = nil
142
- }
143
- }
144
- }
145
-
146
- var cameraView: CameraView!
147
- var cancelButton: UIButton!
148
- var captureSession:AVCaptureSession?
149
- var captureVideoPreviewLayer:AVCaptureVideoPreviewLayer?
150
- var metaOutput: AVCaptureMetadataOutput?
151
-
152
- var currentCamera: Int = 0
153
- var frontCamera: AVCaptureDevice?
154
- var backCamera: AVCaptureDevice?
155
-
156
- var cancelText: String = "Cancel"
157
- var isScanning: Bool = false
158
- var shouldRunScan: Bool = false
159
- var didRunCameraSetup: Bool = false
160
- var didRunCameraPrepare: Bool = false
161
- var isBackgroundHidden: Bool = false
162
-
163
- var savedCall: CAPPluginCall? = nil
164
- var scanningPaused: Bool = false
165
- var lastScanResult: String? = nil
166
-
167
- enum SupportedFormat: String, CaseIterable {
168
- // 1D Product
169
- //!\ UPC_A is part of EAN_13 according to Apple docs
170
- case UPC_E
171
- //!\ UPC_EAN_EXTENSION is not supported by AVFoundation
172
- case EAN_8
173
- case EAN_13
174
- // 1D Industrial
175
- case CODE_39
176
- case CODE_39_MOD_43
177
- case CODE_93
178
- case CODE_128
179
- //!\ CODABAR is not supported by AVFoundation
180
- case ITF
181
- case ITF_14
182
- // 2D
183
- case AZTEC
184
- case DATA_MATRIX
185
- //!\ MAXICODE is not supported by AVFoundation
186
- case PDF_417
187
- case QR_CODE
188
- //!\ RSS_14 is not supported by AVFoundation
189
- //!\ RSS_EXPANDED is not supported by AVFoundation
190
-
191
- var value: AVMetadataObject.ObjectType {
192
- switch self {
193
- // 1D Product
194
- case .UPC_E: return AVMetadataObject.ObjectType.upce
195
- case .EAN_8: return AVMetadataObject.ObjectType.ean8
196
- case .EAN_13: return AVMetadataObject.ObjectType.ean13
197
- // 1D Industrial
198
- case .CODE_39: return AVMetadataObject.ObjectType.code39
199
- case .CODE_39_MOD_43: return AVMetadataObject.ObjectType.code39Mod43
200
- case .CODE_93: return AVMetadataObject.ObjectType.code93
201
- case .CODE_128: return AVMetadataObject.ObjectType.code128
202
- case .ITF: return AVMetadataObject.ObjectType.interleaved2of5
203
- case .ITF_14: return AVMetadataObject.ObjectType.itf14
204
- // 2D
205
- case .AZTEC: return AVMetadataObject.ObjectType.aztec
206
- case .DATA_MATRIX: return AVMetadataObject.ObjectType.dataMatrix
207
- case .PDF_417: return AVMetadataObject.ObjectType.pdf417
208
- case .QR_CODE: return AVMetadataObject.ObjectType.qr
209
- }
210
- }
211
- }
212
-
213
- var targetedFormats = [AVMetadataObject.ObjectType]()
214
-
215
- enum CaptureError: Error {
216
- case backCameraUnavailable
217
- case frontCameraUnavailable
218
- case couldNotCaptureInput(error: NSError)
219
- }
220
108
 
221
- @objc func buttonTapped( _ button : UIButton)
222
- {
223
-
224
- self.destroy()
225
- }
226
-
227
-
228
-
229
- private func loadScan() {
230
-
231
- if(self.cameraView != nil){
232
- return
233
- }
234
-
235
-
236
- self.cameraView = CameraView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
237
- self.cameraView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
238
-
239
- let button = UIButton()
240
- //button.backgroundColor = UIColor.orange
241
-
242
- //let iconImage = UIImage(named: "search")
243
- //button.setImage(iconImage, for: .normal)
244
-
245
- button.setTitle("< " + self.cancelText, for: .normal)
246
- button.contentMode = UIView.ContentMode.scaleToFill
247
- button.frame = CGRect(x: 20, y: 10, width:200 , height:100)
248
- button.titleLabel?.textColor = UIColor.white
249
- button.contentHorizontalAlignment = .left
250
-
251
- button.addTarget(self, action: #selector(self.buttonTapped(_:)), for: UIControl.Event.touchUpInside)
252
-
253
- self.cancelButton = button
254
-
255
- }
256
-
257
- private func hasCameraPermission() -> Bool {
258
- let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
259
- if (status == AVAuthorizationStatus.authorized) {
260
- return true
261
- }
262
- return false
263
- }
264
-
265
- private func addViews(){
266
- self.webView!.superview!.insertSubview(cameraView, aboveSubview: self.webView!)
267
- self.webView!.superview!.insertSubview(cancelButton, aboveSubview: cameraView)
268
- }
269
-
270
- private func removeViews(){
271
-
272
- DispatchQueue.main.async {
273
- self.cancelButton.removeFromSuperview()
274
- self.cameraView.removeFromSuperview()
275
- }
276
-
277
- }
278
-
279
- private func setupCamera(cameraDirection: String? = "back") -> Bool {
280
- do {
281
- var cameraDir = cameraDirection
282
- cameraView.backgroundColor = UIColor.clear
283
- //self.webView!.superview!.insertSubview(cameraView, belowSubview: self.webView!)
284
-
285
- //self.webView!.superview!.insertSubview(cameraView, aboveSubview: self.webView!)
286
- //self.webView!.superview!.insertSubview(cancelButton, aboveSubview: cameraView)
287
- addViews()
288
-
289
- let availableVideoDevices = discoverCaptureDevices()
290
- for device in availableVideoDevices {
291
- if device.position == AVCaptureDevice.Position.back {
292
- backCamera = device
293
- }
294
- else if device.position == AVCaptureDevice.Position.front {
295
- frontCamera = device
296
- }
297
- }
298
- // older iPods have no back camera
299
- if (cameraDir == "back") {
300
- if (backCamera == nil) {
301
- cameraDir = "front"
302
- }
303
- } else {
304
- if (frontCamera == nil) {
305
- cameraDir = "back"
306
- }
307
- }
308
- let input: AVCaptureDeviceInput
309
- input = try self.createCaptureDeviceInput(cameraDirection: cameraDir)
310
- captureSession = AVCaptureSession()
311
- captureSession!.addInput(input)
312
- metaOutput = AVCaptureMetadataOutput()
313
- captureSession!.addOutput(metaOutput!)
314
- metaOutput!.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
315
- captureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession!)
316
- cameraView.addPreviewLayer(captureVideoPreviewLayer)
317
- self.didRunCameraSetup = true
318
- return true
319
- } catch CaptureError.backCameraUnavailable {
320
- //
321
- } catch CaptureError.frontCameraUnavailable {
322
- //
323
- } catch CaptureError.couldNotCaptureInput {
324
- //
325
- } catch {
326
- //
327
- }
328
- return false
329
- }
330
-
331
- @available(swift, deprecated: 5.6, message: "New Xcode? Check if `AVCaptureDevice.DeviceType` has new types and add them accordingly.")
332
- private func discoverCaptureDevices() -> [AVCaptureDevice] {
333
- if #available(iOS 13.0, *) {
334
- return AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualCamera, .builtInTelephotoCamera, .builtInTrueDepthCamera, .builtInUltraWideCamera, .builtInDualWideCamera, .builtInWideAngleCamera], mediaType: .video, position: .unspecified).devices
335
- } else {
336
- return AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera, .builtInWideAngleCamera, .builtInTelephotoCamera, .builtInTrueDepthCamera], mediaType: .video, position: .unspecified).devices
337
- }
338
- }
339
-
340
- private func createCaptureDeviceInput(cameraDirection: String? = "back") throws -> AVCaptureDeviceInput {
341
- var captureDevice: AVCaptureDevice
342
- if(cameraDirection == "back"){
343
- if(backCamera != nil){
344
- captureDevice = backCamera!
345
- } else {
346
- throw CaptureError.backCameraUnavailable
347
- }
348
- } else {
349
- if(frontCamera != nil){
350
- captureDevice = frontCamera!
351
- } else {
352
- throw CaptureError.frontCameraUnavailable
353
- }
354
- }
355
- let captureDeviceInput: AVCaptureDeviceInput
356
- do {
357
- captureDeviceInput = try AVCaptureDeviceInput(device: captureDevice)
358
- } catch let error as NSError {
359
- throw CaptureError.couldNotCaptureInput(error: error)
360
- }
361
- return captureDeviceInput
362
- }
363
-
364
- private func dismantleCamera() {
365
- // opposite of setupCamera
366
-
367
- if (self.captureSession != nil) {
368
- DispatchQueue.main.async {
369
- self.captureSession!.stopRunning()
370
- self.cameraView.removePreviewLayer()
371
- self.captureVideoPreviewLayer = nil
372
- self.metaOutput = nil
373
- self.captureSession = nil
374
- self.frontCamera = nil
375
- self.backCamera = nil
376
- }
377
- }
378
-
379
- self.isScanning = false
380
- self.didRunCameraSetup = false
381
- self.didRunCameraPrepare = false
382
-
383
- // If a call is saved and a scan will not run, free the saved call
384
- if (self.savedCall != nil && !self.shouldRunScan) {
385
- self.savedCall = nil
386
- }
387
- }
388
-
389
- private func prepare(_ call: CAPPluginCall? = nil) {
390
- // undo previous setup
391
- // because it may be prepared with a different config
392
- self.dismantleCamera()
393
-
394
- DispatchQueue.main.async {
395
- // setup camera with new config
396
- if (self.setupCamera(cameraDirection: call?.getString("cameraDirection") ?? "back")) {
397
- // indicate this method was run
398
- self.didRunCameraPrepare = true
399
-
400
- if (self.shouldRunScan) {
401
- self.scan()
402
- }
403
- } else {
404
- self.shouldRunScan = false
405
- }
406
- }
407
- }
408
-
409
- private func destroy() {
410
-
411
- self.removeViews()
412
-
413
- self.showBackground()
414
-
415
- self.dismantleCamera()
416
- }
417
-
418
- private func scan() {
419
- if (!self.didRunCameraPrepare) {
420
- //In iOS 14 don't identify permissions needed, so force to ask it's better than nothing. Provisional.
421
- var iOS14min: Bool = false
422
- if #available(iOS 14.0, *) { iOS14min = true; }
423
- if (!self.hasCameraPermission() && !iOS14min) {
424
- // @TODO()
425
- // requestPermission()
426
- } else {
427
- self.shouldRunScan = true
428
- self.prepare(savedCall)
429
- }
430
- } else {
431
- self.didRunCameraPrepare = false
432
-
433
- self.shouldRunScan = false
434
-
435
- targetedFormats = [AVMetadataObject.ObjectType]();
436
-
437
- if ((savedCall?.options["targetedFormats"]) != nil) {
438
- let _targetedFormats = savedCall?.getArray("targetedFormats", String.self)
439
-
440
- if (_targetedFormats != nil && _targetedFormats?.count ?? 0 > 0) {
441
- _targetedFormats?.forEach { targetedFormat in
442
- if let value = SupportedFormat(rawValue: targetedFormat)?.value {
443
- print(value)
444
- targetedFormats.append(value)
445
- }
446
- }
447
- }
448
-
449
- if (targetedFormats.count == 0) {
450
- print("The property targetedFormats was not set correctly.")
451
- }
452
- }
453
-
454
- if (targetedFormats.count == 0) {
455
- for supportedFormat in SupportedFormat.allCases {
456
- targetedFormats.append(supportedFormat.value)
457
- }
458
- }
459
-
460
- DispatchQueue.main.async {
461
- self.metaOutput!.metadataObjectTypes = self.targetedFormats
462
- self.captureSession!.startRunning()
463
- }
464
-
465
- self.hideBackground()
466
-
467
- self.isScanning = true
468
- }
469
- }
470
-
471
- private func hideBackground() {
472
- /*
473
- DispatchQueue.main.async {
474
- self.bridge?.webView!.isOpaque = false
475
- self.bridge?.webView!.backgroundColor = UIColor.clear
476
- self.bridge?.webView!.scrollView.backgroundColor = UIColor.clear
477
-
478
- let javascript = "document.documentElement.style.backgroundColor = 'transparent'"
479
-
480
- self.bridge?.webView!.evaluateJavaScript(javascript)
481
- }*/
482
- }
483
-
484
- private func showBackground() {
485
-
486
- /*
487
- DispatchQueue.main.async {
488
- let javascript = "document.documentElement.style.backgroundColor = ''"
489
-
490
- self.bridge?.webView!.evaluateJavaScript(javascript) { (result, error) in
491
- self.bridge?.webView!.isOpaque = true
492
- self.bridge?.webView!.backgroundColor = UIColor.white
493
- self.bridge?.webView!.scrollView.backgroundColor = UIColor.white
494
- }
495
- }*/
496
- }
497
-
498
- // This method processes metadataObjects captured by iOS.
499
- public func metadataOutput(_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
500
-
501
- if (metadataObjects.count == 0 || !self.isScanning) {
502
- // while nothing is detected, or if scanning is false, do nothing.
503
- return
504
- }
505
-
506
- let found = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
507
- if (targetedFormats.contains(found.type)) {
508
- var jsObject = PluginCallResultData()
509
-
510
- if (found.stringValue != nil) {
511
- jsObject["hasContent"] = true
512
- jsObject["content"] = found.stringValue
513
- jsObject["format"] = formatStringFromMetadata(found.type)
514
- } else {
515
- jsObject["hasContent"] = false
516
- }
517
-
518
- if (savedCall != nil) {
519
- if (savedCall!.keepAlive) {
520
- if (!scanningPaused && found.stringValue != lastScanResult ) {
521
- lastScanResult = found.stringValue
522
- savedCall!.resolve(jsObject)
523
- }
524
- } else {
525
- savedCall!.resolve(jsObject)
526
- savedCall = nil
527
- destroy()
528
- }
529
- } else {
530
- self.destroy()
531
- }
532
- }
533
- }
534
-
535
- private func formatStringFromMetadata(_ type: AVMetadataObject.ObjectType) -> String {
536
- switch type {
537
- case AVMetadataObject.ObjectType.upce:
538
- return "UPC_E"
539
- case AVMetadataObject.ObjectType.ean8:
540
- return "EAN_8"
541
- case AVMetadataObject.ObjectType.ean13:
542
- return "EAN_13"
543
- case AVMetadataObject.ObjectType.code39:
544
- return "CODE_39"
545
- case AVMetadataObject.ObjectType.code39Mod43:
546
- return "CODE_39_MOD_43"
547
- case AVMetadataObject.ObjectType.code93:
548
- return "CODE_93"
549
- case AVMetadataObject.ObjectType.code128:
550
- return "CODE_128"
551
- case AVMetadataObject.ObjectType.interleaved2of5:
552
- return "ITF"
553
- case AVMetadataObject.ObjectType.itf14:
554
- return "ITF_14"
555
- case AVMetadataObject.ObjectType.aztec:
556
- return "AZTEC"
557
- case AVMetadataObject.ObjectType.dataMatrix:
558
- return "DATA_MATRIX"
559
- case AVMetadataObject.ObjectType.pdf417:
560
- return "PDF_417"
561
- case AVMetadataObject.ObjectType.qr:
562
- return "QR_CODE"
563
- default:
564
- return type.rawValue
565
- }
566
- }
567
-
568
- @objc func prepare(_ call: CAPPluginCall) {
569
- self.prepare()
570
- call.resolve()
571
- }
572
-
573
- @objc func hideBackground(_ call: CAPPluginCall) {
574
- self.hideBackground()
575
- call.resolve()
576
- }
577
-
578
- @objc func showBackground(_ call: CAPPluginCall) {
579
- self.showBackground()
580
- call.resolve()
581
- }
582
-
583
- @objc func startScan(_ call: CAPPluginCall) {
584
- self.savedCall = call
585
- self.scan()
586
- }
587
-
588
- @objc func startScanning(_ call: CAPPluginCall) {
589
- self.savedCall = call
590
- self.savedCall?.keepAlive = true
591
- scanningPaused = false
592
- lastScanResult = nil
593
- self.scan()
594
- }
595
-
596
- @objc func pauseScanning(_ call: CAPPluginCall) {
597
- scanningPaused = true
598
- call.resolve()
599
- }
600
-
601
- @objc func resumeScanning(_ call: CAPPluginCall) {
602
- scanningPaused = false
603
- call.resolve()
604
- }
605
-
606
- @objc func stopScan(_ call: CAPPluginCall) {
607
- if ((call.getBool("resolveScan") ?? false) && self.savedCall != nil) {
608
- var jsObject = PluginCallResultData()
609
- jsObject["hasContent"] = false
610
-
611
- savedCall?.resolve(jsObject)
612
- savedCall = nil
613
- }
614
-
615
- self.destroy()
616
- call.resolve()
617
- }
618
-
619
- @objc func checkPermission(_ call: CAPPluginCall) {
620
- let force = call.getBool("force") ?? false
621
-
622
- var savedReturnObject = PluginCallResultData()
623
-
624
- DispatchQueue.main.async {
625
- switch AVCaptureDevice.authorizationStatus(for: .video) {
626
- case .authorized:
627
- savedReturnObject["granted"] = true
628
- case .denied:
629
- savedReturnObject["denied"] = true
630
- case .notDetermined:
631
- savedReturnObject["neverAsked"] = true
632
- case .restricted:
633
- savedReturnObject["restricted"] = true
634
- @unknown default:
635
- savedReturnObject["unknown"] = true
636
- }
637
-
638
- if (force && savedReturnObject["neverAsked"] != nil) {
639
- savedReturnObject["asked"] = true
640
-
641
- AVCaptureDevice.requestAccess(for: .video) { (authorized) in
642
- if (authorized) {
643
- savedReturnObject["granted"] = true
644
- } else {
645
- savedReturnObject["denied"] = true
646
- }
647
- call.resolve(savedReturnObject)
648
- }
649
- } else {
650
- call.resolve(savedReturnObject)
651
- }
652
- }
653
- }
654
109
 
655
110
  /*
656
111
  @objc func openAppSettings(_ call: CAPPluginCall) {
@@ -668,65 +123,8 @@ public class CorePlugin: CAPPlugin, AVCaptureMetadataOutputObjectsDelegate {
668
123
  }
669
124
  */
670
125
 
671
- @objc func enableTorch(_ call: CAPPluginCall) {
672
- guard let device = AVCaptureDevice.default(for: AVMediaType.video) else { return }
673
- guard device.hasTorch else { return }
674
- guard device.isTorchAvailable else { return }
675
-
676
- do {
677
- try device.lockForConfiguration()
678
-
679
- do {
680
- try device.setTorchModeOn(level: 1.0)
681
- } catch {
682
- print(error)
683
- }
684
-
685
- device.unlockForConfiguration()
686
- } catch {
687
- print(error)
688
- }
689
-
690
- call.resolve()
691
- }
692
126
 
693
- @objc func disableTorch(_ call: CAPPluginCall) {
694
- guard let device = AVCaptureDevice.default(for: AVMediaType.video) else { return }
695
- guard device.hasTorch else { return }
696
- guard device.isTorchAvailable else { return }
697
127
 
698
- do {
699
- try device.lockForConfiguration()
700
- device.torchMode = .off
701
128
 
702
- device.unlockForConfiguration()
703
- } catch {
704
- print(error)
705
- }
706
-
707
- call.resolve()
708
- }
709
-
710
- @objc func toggleTorch(_ call: CAPPluginCall) {
711
- guard let device = AVCaptureDevice.default(for: AVMediaType.video) else { return }
712
- guard device.hasTorch else { return }
713
- guard device.isTorchAvailable else { return }
714
-
715
- if (device.torchMode == .on) {
716
- self.disableTorch(call)
717
- } else {
718
- self.enableTorch(call)
719
- }
720
- }
721
-
722
- @objc func getTorchState(_ call: CAPPluginCall) {
723
- guard let device = AVCaptureDevice.default(for: AVMediaType.video) else { return }
724
-
725
- var result = PluginCallResultData()
726
-
727
- result["isEnabled"] = device.torchMode == .on
728
-
729
- call.resolve(result)
730
- }
731
129
 
732
130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigens/aigens-sdk-core",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Aigens Order.Place Core Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",