@simplymobile/capacitor-godex-printer 0.0.4 → 1.0.0

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.
Binary file
@@ -1,38 +1,54 @@
1
1
  package pl.simplymobile.plugins.godexprinter;
2
2
 
3
+ import android.util.Log;
4
+
3
5
  import com.getcapacitor.JSObject;
4
6
  import com.getcapacitor.Plugin;
5
7
  import com.getcapacitor.PluginCall;
6
8
  import com.getcapacitor.PluginMethod;
7
9
  import com.getcapacitor.annotation.CapacitorPlugin;
10
+ import com.godex.Godex;
11
+
12
+ import java.io.IOException;
8
13
 
9
14
  @CapacitorPlugin(name = "GodexPrinter")
10
15
  public class GodexPrinterPlugin extends Plugin {
11
16
 
12
- private GodexPrinter implementation;
17
+ private boolean connected = false;
13
18
 
14
19
  @Override
15
20
  public void load() {
16
- implementation = new GodexPrinter();
17
- implementation.setDefaults(this.getActivity().getApplicationContext());
21
+ Godex.debug(3);
22
+ var context = this.getActivity().getApplicationContext();
23
+ Godex.getMainContext(context);
24
+ try {
25
+ connected = Godex.openport(null, 3);
26
+ } catch (Exception e) {
27
+ Log.i("connectToUSB", e.getMessage());
28
+ }
18
29
  }
19
30
 
20
31
  @PluginMethod
21
32
  public void getVersion(PluginCall call) {
22
33
  JSObject ret = new JSObject();
23
- ret.put("version", implementation.getVersion());
34
+
35
+ var value = Godex.getVersion();
36
+ Log.i("getVersion", value + "test");
37
+
38
+ ret.put("version", value);
24
39
  call.resolve(ret);
25
40
  }
26
41
 
27
42
  @PluginMethod
28
43
  public void connectToUSB(PluginCall call) {
29
44
  JSObject ret = new JSObject();
30
- var result = implementation.connectToUSB();
45
+ Log.i("connectToUSB", "connect started!");
31
46
 
32
- if (result) {
33
- ret.put("value", "USB Connected");
34
- } else {
35
- ret.put("value", "USB Connect fail");
47
+ try {
48
+ connected = Godex.openport(null, 3);
49
+ } catch (Exception e) {
50
+ Log.i("connectToUSB", e.getMessage());
51
+ ret.put("value", e.getMessage());
36
52
  }
37
53
 
38
54
  call.resolve(ret);
@@ -43,35 +59,46 @@ public class GodexPrinterPlugin extends Plugin {
43
59
  String value = call.getString("value");
44
60
  JSObject ret = new JSObject();
45
61
 
46
- var connectResult = implementation.connectToUSB();
47
- if (!connectResult) {
48
- ret.put("value", "USB Connect fail");
49
- call.resolve(ret);
50
- return;
51
- }
62
+ connected = Godex.openport(null, 3);
52
63
 
53
- var printResult = implementation.printFromUSB(value);
54
- if (!printResult) {
55
- ret.put("value", "Print fail");
64
+ if (!connected) {
65
+ ret.put("value", "Błąd połączenia USB");
56
66
  call.resolve(ret);
57
67
  return;
58
68
  }
59
69
 
60
- var disconnectResult = implementation.disconnect();
61
- if (!disconnectResult) {
62
- ret.put("value", "Disconnect fail");
63
- call.resolve(ret);
64
- return;
70
+ try {
71
+ var printResult = Godex.sendCommand(value);
72
+ if (!printResult) {
73
+ try {
74
+ Godex.close();
75
+ } catch (IOException e) {
76
+ Log.i("connectToUSB", e.getMessage());
77
+ }
78
+ ret.put("value", "Błąd wydruku! Spróbuj jeszcze raz.");
79
+ call.resolve(ret);
80
+ return;
81
+ }
82
+ ret.put("value", "Wydruk udany!");
83
+ } catch (Exception e) {
84
+ ret.put("value", "Zezwól na dostęp do USB i uruchom wydruk jeszcze raz.");
65
85
  }
66
86
 
67
- ret.put("value", "Print success!");
68
87
  call.resolve(ret);
69
88
  }
70
89
 
71
90
  @PluginMethod
72
- public void disconnect(PluginCall call) {
91
+ public void disconnectPrinter(PluginCall call) {
73
92
  JSObject ret = new JSObject();
74
- var result = implementation.disconnect();
93
+ connected = false;
94
+ var result = false;
95
+
96
+ try {
97
+ result = Godex.close();
98
+ } catch (IOException e) {
99
+ Log.i("connectToUSB", e.getMessage());
100
+ }
101
+
75
102
 
76
103
  if (result) {
77
104
  ret.put("value", "Disconnected");
@@ -85,8 +112,10 @@ public class GodexPrinterPlugin extends Plugin {
85
112
  @PluginMethod
86
113
  public void getPrinterDPI(PluginCall call) {
87
114
  JSObject ret = new JSObject();
115
+ Log.i("getPrinterDPI", "connect started!");
116
+ var value = Godex.getPrinterDPI();
88
117
 
89
- ret.put("value", implementation.getPrinterDPI());
118
+ ret.put("value", value);
90
119
 
91
120
  call.resolve(ret);
92
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplymobile/capacitor-godex-printer",
3
- "version": "0.0.4",
3
+ "version": "1.0.0",
4
4
  "description": "Capacitor GoDEX printer plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,55 +0,0 @@
1
- package pl.simplymobile.plugins.godexprinter;
2
-
3
- import android.content.Context;
4
- import android.util.Log;
5
-
6
- import com.godex.Godex;
7
-
8
- import java.io.IOException;
9
-
10
- public class GodexPrinter {
11
-
12
- private boolean connected = false;
13
-
14
- public void setDefaults(Context context) {
15
- Godex.debug(3);
16
- Godex.getMainContext(context);
17
- }
18
-
19
- public String getVersion() {
20
- var value = Godex.getVersion();
21
- Log.i("getVersion", value);
22
- return Godex.getVersion();
23
- }
24
-
25
- public boolean printFromUSB(String value) {
26
- Log.i("printFromUSB", "print started!");
27
- return Godex.sendCommand(value);
28
- }
29
-
30
- public boolean connectToUSB() {
31
- Log.i("connectToUSB", "connect started!");
32
-
33
- if (connected) {
34
- return true;
35
- }
36
-
37
- connected = Godex.openport(null, 3);
38
- return connected;
39
- }
40
-
41
- public int getPrinterDPI() {
42
- Log.i("getPrinterDPI", "connect started!");
43
- return Godex.getPrinterDPI();
44
- }
45
-
46
- public boolean disconnect() {
47
- connected = false;
48
- try {
49
- return Godex.close();
50
- } catch (IOException e) {
51
- Log.i("connectToUSB", e.getMessage());
52
- return false;
53
- }
54
- }
55
- }