@skalfa/skalfa-printer 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.
- package/LICENSE +21 -0
- package/README.md +56 -0
- package/dist/PrinterSelect.component.d.ts +7 -0
- package/dist/PrinterSelect.component.js +51 -0
- package/dist/commands.d.ts +11 -0
- package/dist/commands.js +17 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +23 -0
- package/dist/usePrinter.hook.d.ts +13 -0
- package/dist/usePrinter.hook.js +114 -0
- package/dist/utils.d.ts +33 -0
- package/dist/utils.js +64 -0
- package/package.json +29 -0
- package/src-rust/Cargo.lock +4473 -0
- package/src-rust/Cargo.toml +30 -0
- package/src-rust/build.rs +5 -0
- package/src-rust/permissions/autogenerated/commands/get_printer_status.toml +13 -0
- package/src-rust/permissions/autogenerated/commands/list_printers.toml +13 -0
- package/src-rust/permissions/autogenerated/commands/print_raw.toml +13 -0
- package/src-rust/permissions/autogenerated/reference.md +97 -0
- package/src-rust/permissions/default.toml +3 -0
- package/src-rust/permissions/schemas/schema.json +342 -0
- package/src-rust/src/commands.rs +62 -0
- package/src-rust/src/error.rs +34 -0
- package/src-rust/src/lib.rs +20 -0
- package/src-rust/src/printer_windows.rs +291 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "tauri-plugin-skalfa-printer"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Tauri 2 plugin for thermal/raw printing via Windows Print Spooler API"
|
|
6
|
+
authors = ["Skalfa"]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
links = "tauri-plugin-skalfa-printer"
|
|
9
|
+
|
|
10
|
+
[lib]
|
|
11
|
+
name = "tauri_plugin_skalfa_printer"
|
|
12
|
+
crate-type = ["lib"]
|
|
13
|
+
|
|
14
|
+
[build-dependencies]
|
|
15
|
+
tauri-plugin = { version = "2", features = ["build"] }
|
|
16
|
+
|
|
17
|
+
[dependencies]
|
|
18
|
+
tauri = { version = "2", features = [] }
|
|
19
|
+
serde = { version = "1", features = ["derive"] }
|
|
20
|
+
serde_json = "1"
|
|
21
|
+
thiserror = "2"
|
|
22
|
+
log = "0.4"
|
|
23
|
+
|
|
24
|
+
[target.'cfg(windows)'.dependencies]
|
|
25
|
+
windows = { version = "0.58", features = [
|
|
26
|
+
"Win32_Graphics_Printing",
|
|
27
|
+
"Win32_Graphics_Gdi",
|
|
28
|
+
"Win32_Foundation",
|
|
29
|
+
"Win32_Security",
|
|
30
|
+
] }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-get-printer-status"
|
|
7
|
+
description = "Enables the get_printer_status command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["get_printer_status"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-get-printer-status"
|
|
12
|
+
description = "Denies the get_printer_status command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["get_printer_status"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-list-printers"
|
|
7
|
+
description = "Enables the list_printers command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["list_printers"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-list-printers"
|
|
12
|
+
description = "Denies the list_printers command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["list_printers"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Automatically generated - DO NOT EDIT!
|
|
2
|
+
|
|
3
|
+
"$schema" = "../../schemas/schema.json"
|
|
4
|
+
|
|
5
|
+
[[permission]]
|
|
6
|
+
identifier = "allow-print-raw"
|
|
7
|
+
description = "Enables the print_raw command without any pre-configured scope."
|
|
8
|
+
commands.allow = ["print_raw"]
|
|
9
|
+
|
|
10
|
+
[[permission]]
|
|
11
|
+
identifier = "deny-print-raw"
|
|
12
|
+
description = "Denies the print_raw command without any pre-configured scope."
|
|
13
|
+
commands.deny = ["print_raw"]
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
## Default Permission
|
|
2
|
+
|
|
3
|
+
Default permissions for the skalfa-printer plugin
|
|
4
|
+
|
|
5
|
+
#### This default permission set includes the following:
|
|
6
|
+
|
|
7
|
+
- `allow-list-printers`
|
|
8
|
+
- `allow-print-raw`
|
|
9
|
+
- `allow-get-printer-status`
|
|
10
|
+
|
|
11
|
+
## Permission Table
|
|
12
|
+
|
|
13
|
+
<table>
|
|
14
|
+
<tr>
|
|
15
|
+
<th>Identifier</th>
|
|
16
|
+
<th>Description</th>
|
|
17
|
+
</tr>
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
<tr>
|
|
21
|
+
<td>
|
|
22
|
+
|
|
23
|
+
`skalfa-printer:allow-get-printer-status`
|
|
24
|
+
|
|
25
|
+
</td>
|
|
26
|
+
<td>
|
|
27
|
+
|
|
28
|
+
Enables the get_printer_status command without any pre-configured scope.
|
|
29
|
+
|
|
30
|
+
</td>
|
|
31
|
+
</tr>
|
|
32
|
+
|
|
33
|
+
<tr>
|
|
34
|
+
<td>
|
|
35
|
+
|
|
36
|
+
`skalfa-printer:deny-get-printer-status`
|
|
37
|
+
|
|
38
|
+
</td>
|
|
39
|
+
<td>
|
|
40
|
+
|
|
41
|
+
Denies the get_printer_status command without any pre-configured scope.
|
|
42
|
+
|
|
43
|
+
</td>
|
|
44
|
+
</tr>
|
|
45
|
+
|
|
46
|
+
<tr>
|
|
47
|
+
<td>
|
|
48
|
+
|
|
49
|
+
`skalfa-printer:allow-list-printers`
|
|
50
|
+
|
|
51
|
+
</td>
|
|
52
|
+
<td>
|
|
53
|
+
|
|
54
|
+
Enables the list_printers command without any pre-configured scope.
|
|
55
|
+
|
|
56
|
+
</td>
|
|
57
|
+
</tr>
|
|
58
|
+
|
|
59
|
+
<tr>
|
|
60
|
+
<td>
|
|
61
|
+
|
|
62
|
+
`skalfa-printer:deny-list-printers`
|
|
63
|
+
|
|
64
|
+
</td>
|
|
65
|
+
<td>
|
|
66
|
+
|
|
67
|
+
Denies the list_printers command without any pre-configured scope.
|
|
68
|
+
|
|
69
|
+
</td>
|
|
70
|
+
</tr>
|
|
71
|
+
|
|
72
|
+
<tr>
|
|
73
|
+
<td>
|
|
74
|
+
|
|
75
|
+
`skalfa-printer:allow-print-raw`
|
|
76
|
+
|
|
77
|
+
</td>
|
|
78
|
+
<td>
|
|
79
|
+
|
|
80
|
+
Enables the print_raw command without any pre-configured scope.
|
|
81
|
+
|
|
82
|
+
</td>
|
|
83
|
+
</tr>
|
|
84
|
+
|
|
85
|
+
<tr>
|
|
86
|
+
<td>
|
|
87
|
+
|
|
88
|
+
`skalfa-printer:deny-print-raw`
|
|
89
|
+
|
|
90
|
+
</td>
|
|
91
|
+
<td>
|
|
92
|
+
|
|
93
|
+
Denies the print_raw command without any pre-configured scope.
|
|
94
|
+
|
|
95
|
+
</td>
|
|
96
|
+
</tr>
|
|
97
|
+
</table>
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "PermissionFile",
|
|
4
|
+
"description": "Permission file that can define a default permission, a set of permissions or a list of inlined permissions.",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"default": {
|
|
8
|
+
"description": "The default permission set for the plugin",
|
|
9
|
+
"anyOf": [
|
|
10
|
+
{
|
|
11
|
+
"$ref": "#/definitions/DefaultPermission"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "null"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"set": {
|
|
19
|
+
"description": "A list of permissions sets defined",
|
|
20
|
+
"type": "array",
|
|
21
|
+
"items": {
|
|
22
|
+
"$ref": "#/definitions/PermissionSet"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"permission": {
|
|
26
|
+
"description": "A list of inlined permissions",
|
|
27
|
+
"default": [],
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": {
|
|
30
|
+
"$ref": "#/definitions/Permission"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"definitions": {
|
|
35
|
+
"DefaultPermission": {
|
|
36
|
+
"description": "The default permission set of the plugin.\n\nWorks similarly to a permission with the \"default\" identifier.",
|
|
37
|
+
"type": "object",
|
|
38
|
+
"required": [
|
|
39
|
+
"permissions"
|
|
40
|
+
],
|
|
41
|
+
"properties": {
|
|
42
|
+
"version": {
|
|
43
|
+
"description": "The version of the permission.",
|
|
44
|
+
"type": [
|
|
45
|
+
"integer",
|
|
46
|
+
"null"
|
|
47
|
+
],
|
|
48
|
+
"format": "uint64",
|
|
49
|
+
"minimum": 1.0
|
|
50
|
+
},
|
|
51
|
+
"description": {
|
|
52
|
+
"description": "Human-readable description of what the permission does. Tauri convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
|
53
|
+
"type": [
|
|
54
|
+
"string",
|
|
55
|
+
"null"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"permissions": {
|
|
59
|
+
"description": "All permissions this set contains.",
|
|
60
|
+
"type": "array",
|
|
61
|
+
"items": {
|
|
62
|
+
"type": "string"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"PermissionSet": {
|
|
68
|
+
"description": "A set of direct permissions grouped together under a new name.",
|
|
69
|
+
"type": "object",
|
|
70
|
+
"required": [
|
|
71
|
+
"description",
|
|
72
|
+
"identifier",
|
|
73
|
+
"permissions"
|
|
74
|
+
],
|
|
75
|
+
"properties": {
|
|
76
|
+
"identifier": {
|
|
77
|
+
"description": "A unique identifier for the permission.",
|
|
78
|
+
"type": "string"
|
|
79
|
+
},
|
|
80
|
+
"description": {
|
|
81
|
+
"description": "Human-readable description of what the permission does.",
|
|
82
|
+
"type": "string"
|
|
83
|
+
},
|
|
84
|
+
"permissions": {
|
|
85
|
+
"description": "All permissions this set contains.",
|
|
86
|
+
"type": "array",
|
|
87
|
+
"items": {
|
|
88
|
+
"$ref": "#/definitions/PermissionKind"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"Permission": {
|
|
94
|
+
"description": "Descriptions of explicit privileges of commands.\n\nIt can enable commands to be accessible in the frontend of the application.\n\nIf the scope is defined it can be used to fine grain control the access of individual or multiple commands.",
|
|
95
|
+
"type": "object",
|
|
96
|
+
"required": [
|
|
97
|
+
"identifier"
|
|
98
|
+
],
|
|
99
|
+
"properties": {
|
|
100
|
+
"version": {
|
|
101
|
+
"description": "The version of the permission.",
|
|
102
|
+
"type": [
|
|
103
|
+
"integer",
|
|
104
|
+
"null"
|
|
105
|
+
],
|
|
106
|
+
"format": "uint64",
|
|
107
|
+
"minimum": 1.0
|
|
108
|
+
},
|
|
109
|
+
"identifier": {
|
|
110
|
+
"description": "A unique identifier for the permission.",
|
|
111
|
+
"type": "string"
|
|
112
|
+
},
|
|
113
|
+
"description": {
|
|
114
|
+
"description": "Human-readable description of what the permission does. Tauri internal convention is to use `<h4>` headings in markdown content for Tauri documentation generation purposes.",
|
|
115
|
+
"type": [
|
|
116
|
+
"string",
|
|
117
|
+
"null"
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
"commands": {
|
|
121
|
+
"description": "Allowed or denied commands when using this permission.",
|
|
122
|
+
"default": {
|
|
123
|
+
"allow": [],
|
|
124
|
+
"deny": []
|
|
125
|
+
},
|
|
126
|
+
"allOf": [
|
|
127
|
+
{
|
|
128
|
+
"$ref": "#/definitions/Commands"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
"scope": {
|
|
133
|
+
"description": "Allowed or denied scoped when using this permission.",
|
|
134
|
+
"allOf": [
|
|
135
|
+
{
|
|
136
|
+
"$ref": "#/definitions/Scopes"
|
|
137
|
+
}
|
|
138
|
+
]
|
|
139
|
+
},
|
|
140
|
+
"platforms": {
|
|
141
|
+
"description": "Target platforms this permission applies. By default all platforms are affected by this permission.",
|
|
142
|
+
"type": [
|
|
143
|
+
"array",
|
|
144
|
+
"null"
|
|
145
|
+
],
|
|
146
|
+
"items": {
|
|
147
|
+
"$ref": "#/definitions/Target"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"Commands": {
|
|
153
|
+
"description": "Allowed and denied commands inside a permission.\n\nIf two commands clash inside of `allow` and `deny`, it should be denied by default.",
|
|
154
|
+
"type": "object",
|
|
155
|
+
"properties": {
|
|
156
|
+
"allow": {
|
|
157
|
+
"description": "Allowed command.",
|
|
158
|
+
"default": [],
|
|
159
|
+
"type": "array",
|
|
160
|
+
"items": {
|
|
161
|
+
"type": "string"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
"deny": {
|
|
165
|
+
"description": "Denied command, which takes priority.",
|
|
166
|
+
"default": [],
|
|
167
|
+
"type": "array",
|
|
168
|
+
"items": {
|
|
169
|
+
"type": "string"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
"Scopes": {
|
|
175
|
+
"description": "An argument for fine grained behavior control of Tauri commands.\n\nIt can be of any serde serializable type and is used to allow or prevent certain actions inside a Tauri command. The configured scope is passed to the command and will be enforced by the command implementation.\n\n## Example\n\n```json { \"allow\": [{ \"path\": \"$HOME/**\" }], \"deny\": [{ \"path\": \"$HOME/secret.txt\" }] } ```",
|
|
176
|
+
"type": "object",
|
|
177
|
+
"properties": {
|
|
178
|
+
"allow": {
|
|
179
|
+
"description": "Data that defines what is allowed by the scope.",
|
|
180
|
+
"type": [
|
|
181
|
+
"array",
|
|
182
|
+
"null"
|
|
183
|
+
],
|
|
184
|
+
"items": {
|
|
185
|
+
"$ref": "#/definitions/Value"
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
"deny": {
|
|
189
|
+
"description": "Data that defines what is denied by the scope. This should be prioritized by validation logic.",
|
|
190
|
+
"type": [
|
|
191
|
+
"array",
|
|
192
|
+
"null"
|
|
193
|
+
],
|
|
194
|
+
"items": {
|
|
195
|
+
"$ref": "#/definitions/Value"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
"Value": {
|
|
201
|
+
"description": "All supported ACL values.",
|
|
202
|
+
"anyOf": [
|
|
203
|
+
{
|
|
204
|
+
"description": "Represents a null JSON value.",
|
|
205
|
+
"type": "null"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"description": "Represents a [`bool`].",
|
|
209
|
+
"type": "boolean"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"description": "Represents a valid ACL [`Number`].",
|
|
213
|
+
"allOf": [
|
|
214
|
+
{
|
|
215
|
+
"$ref": "#/definitions/Number"
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"description": "Represents a [`String`].",
|
|
221
|
+
"type": "string"
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"description": "Represents a list of other [`Value`]s.",
|
|
225
|
+
"type": "array",
|
|
226
|
+
"items": {
|
|
227
|
+
"$ref": "#/definitions/Value"
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
"description": "Represents a map of [`String`] keys to [`Value`]s.",
|
|
232
|
+
"type": "object",
|
|
233
|
+
"additionalProperties": {
|
|
234
|
+
"$ref": "#/definitions/Value"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
]
|
|
238
|
+
},
|
|
239
|
+
"Number": {
|
|
240
|
+
"description": "A valid ACL number.",
|
|
241
|
+
"anyOf": [
|
|
242
|
+
{
|
|
243
|
+
"description": "Represents an [`i64`].",
|
|
244
|
+
"type": "integer",
|
|
245
|
+
"format": "int64"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"description": "Represents a [`f64`].",
|
|
249
|
+
"type": "number",
|
|
250
|
+
"format": "double"
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
},
|
|
254
|
+
"Target": {
|
|
255
|
+
"description": "Platform target.",
|
|
256
|
+
"oneOf": [
|
|
257
|
+
{
|
|
258
|
+
"description": "MacOS.",
|
|
259
|
+
"type": "string",
|
|
260
|
+
"enum": [
|
|
261
|
+
"macOS"
|
|
262
|
+
]
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"description": "Windows.",
|
|
266
|
+
"type": "string",
|
|
267
|
+
"enum": [
|
|
268
|
+
"windows"
|
|
269
|
+
]
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"description": "Linux.",
|
|
273
|
+
"type": "string",
|
|
274
|
+
"enum": [
|
|
275
|
+
"linux"
|
|
276
|
+
]
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
"description": "Android.",
|
|
280
|
+
"type": "string",
|
|
281
|
+
"enum": [
|
|
282
|
+
"android"
|
|
283
|
+
]
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"description": "iOS.",
|
|
287
|
+
"type": "string",
|
|
288
|
+
"enum": [
|
|
289
|
+
"iOS"
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
]
|
|
293
|
+
},
|
|
294
|
+
"PermissionKind": {
|
|
295
|
+
"type": "string",
|
|
296
|
+
"oneOf": [
|
|
297
|
+
{
|
|
298
|
+
"description": "Enables the get_printer_status command without any pre-configured scope.",
|
|
299
|
+
"type": "string",
|
|
300
|
+
"const": "allow-get-printer-status",
|
|
301
|
+
"markdownDescription": "Enables the get_printer_status command without any pre-configured scope."
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"description": "Denies the get_printer_status command without any pre-configured scope.",
|
|
305
|
+
"type": "string",
|
|
306
|
+
"const": "deny-get-printer-status",
|
|
307
|
+
"markdownDescription": "Denies the get_printer_status command without any pre-configured scope."
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"description": "Enables the list_printers command without any pre-configured scope.",
|
|
311
|
+
"type": "string",
|
|
312
|
+
"const": "allow-list-printers",
|
|
313
|
+
"markdownDescription": "Enables the list_printers command without any pre-configured scope."
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"description": "Denies the list_printers command without any pre-configured scope.",
|
|
317
|
+
"type": "string",
|
|
318
|
+
"const": "deny-list-printers",
|
|
319
|
+
"markdownDescription": "Denies the list_printers command without any pre-configured scope."
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"description": "Enables the print_raw command without any pre-configured scope.",
|
|
323
|
+
"type": "string",
|
|
324
|
+
"const": "allow-print-raw",
|
|
325
|
+
"markdownDescription": "Enables the print_raw command without any pre-configured scope."
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"description": "Denies the print_raw command without any pre-configured scope.",
|
|
329
|
+
"type": "string",
|
|
330
|
+
"const": "deny-print-raw",
|
|
331
|
+
"markdownDescription": "Denies the print_raw command without any pre-configured scope."
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
"description": "Default permissions for the skalfa-printer plugin\n#### This default permission set includes:\n\n- `allow-list-printers`\n- `allow-print-raw`\n- `allow-get-printer-status`",
|
|
335
|
+
"type": "string",
|
|
336
|
+
"const": "default",
|
|
337
|
+
"markdownDescription": "Default permissions for the skalfa-printer plugin\n#### This default permission set includes:\n\n- `allow-list-printers`\n- `allow-print-raw`\n- `allow-get-printer-status`"
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
use crate::error::Error;
|
|
2
|
+
|
|
3
|
+
#[cfg(windows)]
|
|
4
|
+
use crate::printer_windows;
|
|
5
|
+
|
|
6
|
+
#[cfg(windows)]
|
|
7
|
+
use crate::printer_windows::PrinterInfo;
|
|
8
|
+
|
|
9
|
+
#[cfg(not(windows))]
|
|
10
|
+
use serde::Serialize;
|
|
11
|
+
|
|
12
|
+
#[cfg(not(windows))]
|
|
13
|
+
#[derive(Debug, Clone, Serialize)]
|
|
14
|
+
pub struct PrinterInfo {
|
|
15
|
+
pub name: String,
|
|
16
|
+
pub port: String,
|
|
17
|
+
pub driver: String,
|
|
18
|
+
pub is_default: bool,
|
|
19
|
+
pub status: u32,
|
|
20
|
+
pub status_text: String,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#[tauri::command]
|
|
24
|
+
pub fn list_printers() -> Result<Vec<PrinterInfo>, Error> {
|
|
25
|
+
#[cfg(windows)]
|
|
26
|
+
{
|
|
27
|
+
printer_windows::enum_printers()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[cfg(not(windows))]
|
|
31
|
+
{
|
|
32
|
+
Err(Error::UnsupportedPlatform)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#[tauri::command]
|
|
37
|
+
pub fn print_raw(printer: String, content: String) -> Result<(), Error> {
|
|
38
|
+
#[cfg(windows)]
|
|
39
|
+
{
|
|
40
|
+
printer_windows::print_raw(&printer, &content)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[cfg(not(windows))]
|
|
44
|
+
{
|
|
45
|
+
let _ = (printer, content);
|
|
46
|
+
Err(Error::UnsupportedPlatform)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#[tauri::command]
|
|
51
|
+
pub fn get_printer_status(printer: String) -> Result<PrinterInfo, Error> {
|
|
52
|
+
#[cfg(windows)]
|
|
53
|
+
{
|
|
54
|
+
printer_windows::get_printer_status(&printer)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[cfg(not(windows))]
|
|
58
|
+
{
|
|
59
|
+
let _ = printer;
|
|
60
|
+
Err(Error::UnsupportedPlatform)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
use serde::Serialize;
|
|
2
|
+
|
|
3
|
+
#[derive(Debug, thiserror::Error)]
|
|
4
|
+
pub enum Error {
|
|
5
|
+
#[error("Failed to enumerate printers: {0}")]
|
|
6
|
+
EnumPrinters(String),
|
|
7
|
+
|
|
8
|
+
#[error("Failed to open printer '{0}': {1}")]
|
|
9
|
+
OpenPrinter(String, String),
|
|
10
|
+
|
|
11
|
+
#[error("Failed to start print job: {0}")]
|
|
12
|
+
StartDoc(String),
|
|
13
|
+
|
|
14
|
+
#[error("Failed to write to printer: {0}")]
|
|
15
|
+
WritePrinter(String),
|
|
16
|
+
|
|
17
|
+
#[error("Printer not found: {0}")]
|
|
18
|
+
PrinterNotFound(String),
|
|
19
|
+
|
|
20
|
+
#[error("Platform not supported")]
|
|
21
|
+
UnsupportedPlatform,
|
|
22
|
+
|
|
23
|
+
#[error("{0}")]
|
|
24
|
+
Other(String),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
impl Serialize for Error {
|
|
28
|
+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
29
|
+
where
|
|
30
|
+
S: serde::Serializer,
|
|
31
|
+
{
|
|
32
|
+
serializer.serialize_str(&self.to_string())
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
mod commands;
|
|
2
|
+
mod error;
|
|
3
|
+
|
|
4
|
+
#[cfg(windows)]
|
|
5
|
+
mod printer_windows;
|
|
6
|
+
|
|
7
|
+
use tauri::{
|
|
8
|
+
plugin::{Builder, TauriPlugin},
|
|
9
|
+
Runtime,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|
13
|
+
Builder::new("skalfa-printer")
|
|
14
|
+
.invoke_handler(tauri::generate_handler![
|
|
15
|
+
commands::list_printers,
|
|
16
|
+
commands::print_raw,
|
|
17
|
+
commands::get_printer_status,
|
|
18
|
+
])
|
|
19
|
+
.build()
|
|
20
|
+
}
|