@crosscopy/clipboard 0.1.9 → 0.2.3
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/.yarnrc.yml +1 -0
- package/Cargo.toml +23 -0
- package/build.rs +5 -0
- package/exp.ts +16 -0
- package/index.d.ts +12 -0
- package/index.js +306 -0
- package/package.json +44 -37
- package/src/lib.rs +53 -0
- package/README.md +0 -94
- package/dist/demo.d.ts +0 -1
- package/dist/demo.js +0 -244
- package/dist/demo.js.map +0 -1
- package/dist/demo.mjs +0 -234
- package/dist/demo.mjs.map +0 -1
- package/dist/index.d.ts +0 -34
- package/dist/index.js +0 -184
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -171
- package/dist/index.mjs.map +0 -1
- package/go-clipboard/binaries/go-clipboard-darwin-arm64 +0 -0
- package/go-clipboard/binaries/go-clipboard-darwin-x64 +0 -0
- package/go-clipboard/binaries/go-clipboard-linux-arm +0 -0
- package/go-clipboard/binaries/go-clipboard-linux-x64 +0 -0
- package/go-clipboard/binaries/go-clipboard-win32-x64.exe +0 -0
- package/go-clipboard/scripts/win/read_image.ps1 +0 -23
- package/go-clipboard/scripts/win/read_text.ps1 +0 -1
- package/go-clipboard/scripts/win/write_image.ps1 +0 -15
- package/go-clipboard/scripts/win/write_text.ps1 +0 -7
package/.yarnrc.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
nodeLinker: node-modules
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
edition = "2021"
|
|
3
|
+
name = "crosscopy_clipboard"
|
|
4
|
+
version = "0.0.0"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
base64 = "0.22.0"
|
|
11
|
+
clipboard-rs = "0.1.4"
|
|
12
|
+
futures = "0.3.30"
|
|
13
|
+
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
|
|
14
|
+
napi = { version = "2.12.2", default-features = false, features = ["napi4", "tokio_rt"] }
|
|
15
|
+
napi-derive = "2.12.2"
|
|
16
|
+
tokio = "1.36.0"
|
|
17
|
+
|
|
18
|
+
[build-dependencies]
|
|
19
|
+
napi-build = "2.0.1"
|
|
20
|
+
|
|
21
|
+
[profile.release]
|
|
22
|
+
lto = true
|
|
23
|
+
strip = "symbols"
|
package/build.rs
ADDED
package/exp.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getText, getImageBase64, Animal, asyncGetText } from "./index.js";
|
|
2
|
+
import Clipboard from "./index.js";
|
|
3
|
+
|
|
4
|
+
// const text = getText();
|
|
5
|
+
|
|
6
|
+
// console.log(text);
|
|
7
|
+
|
|
8
|
+
// const dog = new Animal("dog", 5);
|
|
9
|
+
// console.log(dog.name);
|
|
10
|
+
// dog.changeName("dog 2");
|
|
11
|
+
// console.log(dog.name);
|
|
12
|
+
|
|
13
|
+
// console.log(Animal.getText());
|
|
14
|
+
|
|
15
|
+
console.log(Clipboard.getText());
|
|
16
|
+
asyncGetText().then(console.log);
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
export function sum(a: number, b: number): number
|
|
7
|
+
export function availableFormats(): Array<string>
|
|
8
|
+
export function getText(): string
|
|
9
|
+
export function getTextAsync(): Promise<string>
|
|
10
|
+
export function setText(text: string): void
|
|
11
|
+
export function getImageBase64(): string
|
|
12
|
+
export function setImageBase64(base64Str: string): void
|
package/index.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/* prettier-ignore */
|
|
4
|
+
|
|
5
|
+
/* auto-generated by NAPI-RS */
|
|
6
|
+
|
|
7
|
+
const { existsSync, readFileSync } = require('fs')
|
|
8
|
+
const { join } = require('path')
|
|
9
|
+
|
|
10
|
+
const { platform, arch } = process
|
|
11
|
+
|
|
12
|
+
let nativeBinding = null
|
|
13
|
+
let localFileExisted = false
|
|
14
|
+
let loadError = null
|
|
15
|
+
|
|
16
|
+
function isMusl() {
|
|
17
|
+
// For Node 10
|
|
18
|
+
if (!process.report || typeof process.report.getReport !== 'function') {
|
|
19
|
+
try {
|
|
20
|
+
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
|
21
|
+
return readFileSync(lddPath, 'utf8').includes('musl')
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return true
|
|
24
|
+
}
|
|
25
|
+
} else {
|
|
26
|
+
const { glibcVersionRuntime } = process.report.getReport().header
|
|
27
|
+
return !glibcVersionRuntime
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
switch (platform) {
|
|
32
|
+
case 'android':
|
|
33
|
+
switch (arch) {
|
|
34
|
+
case 'arm64':
|
|
35
|
+
localFileExisted = existsSync(join(__dirname, 'clipboard.android-arm64.node'))
|
|
36
|
+
try {
|
|
37
|
+
if (localFileExisted) {
|
|
38
|
+
nativeBinding = require('./clipboard.android-arm64.node')
|
|
39
|
+
} else {
|
|
40
|
+
nativeBinding = require('@crosscopy/clipboard-android-arm64')
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
loadError = e
|
|
44
|
+
}
|
|
45
|
+
break
|
|
46
|
+
case 'arm':
|
|
47
|
+
localFileExisted = existsSync(join(__dirname, 'clipboard.android-arm-eabi.node'))
|
|
48
|
+
try {
|
|
49
|
+
if (localFileExisted) {
|
|
50
|
+
nativeBinding = require('./clipboard.android-arm-eabi.node')
|
|
51
|
+
} else {
|
|
52
|
+
nativeBinding = require('@crosscopy/clipboard-android-arm-eabi')
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
loadError = e
|
|
56
|
+
}
|
|
57
|
+
break
|
|
58
|
+
default:
|
|
59
|
+
throw new Error(`Unsupported architecture on Android ${arch}`)
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
case 'win32':
|
|
63
|
+
switch (arch) {
|
|
64
|
+
case 'x64':
|
|
65
|
+
localFileExisted = existsSync(
|
|
66
|
+
join(__dirname, 'clipboard.win32-x64-msvc.node')
|
|
67
|
+
)
|
|
68
|
+
try {
|
|
69
|
+
if (localFileExisted) {
|
|
70
|
+
nativeBinding = require('./clipboard.win32-x64-msvc.node')
|
|
71
|
+
} else {
|
|
72
|
+
nativeBinding = require('@crosscopy/clipboard-win32-x64-msvc')
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
loadError = e
|
|
76
|
+
}
|
|
77
|
+
break
|
|
78
|
+
case 'ia32':
|
|
79
|
+
localFileExisted = existsSync(
|
|
80
|
+
join(__dirname, 'clipboard.win32-ia32-msvc.node')
|
|
81
|
+
)
|
|
82
|
+
try {
|
|
83
|
+
if (localFileExisted) {
|
|
84
|
+
nativeBinding = require('./clipboard.win32-ia32-msvc.node')
|
|
85
|
+
} else {
|
|
86
|
+
nativeBinding = require('@crosscopy/clipboard-win32-ia32-msvc')
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
loadError = e
|
|
90
|
+
}
|
|
91
|
+
break
|
|
92
|
+
case 'arm64':
|
|
93
|
+
localFileExisted = existsSync(
|
|
94
|
+
join(__dirname, 'clipboard.win32-arm64-msvc.node')
|
|
95
|
+
)
|
|
96
|
+
try {
|
|
97
|
+
if (localFileExisted) {
|
|
98
|
+
nativeBinding = require('./clipboard.win32-arm64-msvc.node')
|
|
99
|
+
} else {
|
|
100
|
+
nativeBinding = require('@crosscopy/clipboard-win32-arm64-msvc')
|
|
101
|
+
}
|
|
102
|
+
} catch (e) {
|
|
103
|
+
loadError = e
|
|
104
|
+
}
|
|
105
|
+
break
|
|
106
|
+
default:
|
|
107
|
+
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
|
108
|
+
}
|
|
109
|
+
break
|
|
110
|
+
case 'darwin':
|
|
111
|
+
localFileExisted = existsSync(join(__dirname, 'clipboard.darwin-universal.node'))
|
|
112
|
+
try {
|
|
113
|
+
if (localFileExisted) {
|
|
114
|
+
nativeBinding = require('./clipboard.darwin-universal.node')
|
|
115
|
+
} else {
|
|
116
|
+
nativeBinding = require('@crosscopy/clipboard-darwin-universal')
|
|
117
|
+
}
|
|
118
|
+
break
|
|
119
|
+
} catch {}
|
|
120
|
+
switch (arch) {
|
|
121
|
+
case 'x64':
|
|
122
|
+
localFileExisted = existsSync(join(__dirname, 'clipboard.darwin-x64.node'))
|
|
123
|
+
try {
|
|
124
|
+
if (localFileExisted) {
|
|
125
|
+
nativeBinding = require('./clipboard.darwin-x64.node')
|
|
126
|
+
} else {
|
|
127
|
+
nativeBinding = require('@crosscopy/clipboard-darwin-x64')
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
loadError = e
|
|
131
|
+
}
|
|
132
|
+
break
|
|
133
|
+
case 'arm64':
|
|
134
|
+
localFileExisted = existsSync(
|
|
135
|
+
join(__dirname, 'clipboard.darwin-arm64.node')
|
|
136
|
+
)
|
|
137
|
+
try {
|
|
138
|
+
if (localFileExisted) {
|
|
139
|
+
nativeBinding = require('./clipboard.darwin-arm64.node')
|
|
140
|
+
} else {
|
|
141
|
+
nativeBinding = require('@crosscopy/clipboard-darwin-arm64')
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
loadError = e
|
|
145
|
+
}
|
|
146
|
+
break
|
|
147
|
+
default:
|
|
148
|
+
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
|
149
|
+
}
|
|
150
|
+
break
|
|
151
|
+
case 'freebsd':
|
|
152
|
+
if (arch !== 'x64') {
|
|
153
|
+
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
|
154
|
+
}
|
|
155
|
+
localFileExisted = existsSync(join(__dirname, 'clipboard.freebsd-x64.node'))
|
|
156
|
+
try {
|
|
157
|
+
if (localFileExisted) {
|
|
158
|
+
nativeBinding = require('./clipboard.freebsd-x64.node')
|
|
159
|
+
} else {
|
|
160
|
+
nativeBinding = require('@crosscopy/clipboard-freebsd-x64')
|
|
161
|
+
}
|
|
162
|
+
} catch (e) {
|
|
163
|
+
loadError = e
|
|
164
|
+
}
|
|
165
|
+
break
|
|
166
|
+
case 'linux':
|
|
167
|
+
switch (arch) {
|
|
168
|
+
case 'x64':
|
|
169
|
+
if (isMusl()) {
|
|
170
|
+
localFileExisted = existsSync(
|
|
171
|
+
join(__dirname, 'clipboard.linux-x64-musl.node')
|
|
172
|
+
)
|
|
173
|
+
try {
|
|
174
|
+
if (localFileExisted) {
|
|
175
|
+
nativeBinding = require('./clipboard.linux-x64-musl.node')
|
|
176
|
+
} else {
|
|
177
|
+
nativeBinding = require('@crosscopy/clipboard-linux-x64-musl')
|
|
178
|
+
}
|
|
179
|
+
} catch (e) {
|
|
180
|
+
loadError = e
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
localFileExisted = existsSync(
|
|
184
|
+
join(__dirname, 'clipboard.linux-x64-gnu.node')
|
|
185
|
+
)
|
|
186
|
+
try {
|
|
187
|
+
if (localFileExisted) {
|
|
188
|
+
nativeBinding = require('./clipboard.linux-x64-gnu.node')
|
|
189
|
+
} else {
|
|
190
|
+
nativeBinding = require('@crosscopy/clipboard-linux-x64-gnu')
|
|
191
|
+
}
|
|
192
|
+
} catch (e) {
|
|
193
|
+
loadError = e
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
break
|
|
197
|
+
case 'arm64':
|
|
198
|
+
if (isMusl()) {
|
|
199
|
+
localFileExisted = existsSync(
|
|
200
|
+
join(__dirname, 'clipboard.linux-arm64-musl.node')
|
|
201
|
+
)
|
|
202
|
+
try {
|
|
203
|
+
if (localFileExisted) {
|
|
204
|
+
nativeBinding = require('./clipboard.linux-arm64-musl.node')
|
|
205
|
+
} else {
|
|
206
|
+
nativeBinding = require('@crosscopy/clipboard-linux-arm64-musl')
|
|
207
|
+
}
|
|
208
|
+
} catch (e) {
|
|
209
|
+
loadError = e
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
localFileExisted = existsSync(
|
|
213
|
+
join(__dirname, 'clipboard.linux-arm64-gnu.node')
|
|
214
|
+
)
|
|
215
|
+
try {
|
|
216
|
+
if (localFileExisted) {
|
|
217
|
+
nativeBinding = require('./clipboard.linux-arm64-gnu.node')
|
|
218
|
+
} else {
|
|
219
|
+
nativeBinding = require('@crosscopy/clipboard-linux-arm64-gnu')
|
|
220
|
+
}
|
|
221
|
+
} catch (e) {
|
|
222
|
+
loadError = e
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
break
|
|
226
|
+
case 'arm':
|
|
227
|
+
localFileExisted = existsSync(
|
|
228
|
+
join(__dirname, 'clipboard.linux-arm-gnueabihf.node')
|
|
229
|
+
)
|
|
230
|
+
try {
|
|
231
|
+
if (localFileExisted) {
|
|
232
|
+
nativeBinding = require('./clipboard.linux-arm-gnueabihf.node')
|
|
233
|
+
} else {
|
|
234
|
+
nativeBinding = require('@crosscopy/clipboard-linux-arm-gnueabihf')
|
|
235
|
+
}
|
|
236
|
+
} catch (e) {
|
|
237
|
+
loadError = e
|
|
238
|
+
}
|
|
239
|
+
break
|
|
240
|
+
case 'riscv64':
|
|
241
|
+
if (isMusl()) {
|
|
242
|
+
localFileExisted = existsSync(
|
|
243
|
+
join(__dirname, 'clipboard.linux-riscv64-musl.node')
|
|
244
|
+
)
|
|
245
|
+
try {
|
|
246
|
+
if (localFileExisted) {
|
|
247
|
+
nativeBinding = require('./clipboard.linux-riscv64-musl.node')
|
|
248
|
+
} else {
|
|
249
|
+
nativeBinding = require('@crosscopy/clipboard-linux-riscv64-musl')
|
|
250
|
+
}
|
|
251
|
+
} catch (e) {
|
|
252
|
+
loadError = e
|
|
253
|
+
}
|
|
254
|
+
} else {
|
|
255
|
+
localFileExisted = existsSync(
|
|
256
|
+
join(__dirname, 'clipboard.linux-riscv64-gnu.node')
|
|
257
|
+
)
|
|
258
|
+
try {
|
|
259
|
+
if (localFileExisted) {
|
|
260
|
+
nativeBinding = require('./clipboard.linux-riscv64-gnu.node')
|
|
261
|
+
} else {
|
|
262
|
+
nativeBinding = require('@crosscopy/clipboard-linux-riscv64-gnu')
|
|
263
|
+
}
|
|
264
|
+
} catch (e) {
|
|
265
|
+
loadError = e
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
break
|
|
269
|
+
case 's390x':
|
|
270
|
+
localFileExisted = existsSync(
|
|
271
|
+
join(__dirname, 'clipboard.linux-s390x-gnu.node')
|
|
272
|
+
)
|
|
273
|
+
try {
|
|
274
|
+
if (localFileExisted) {
|
|
275
|
+
nativeBinding = require('./clipboard.linux-s390x-gnu.node')
|
|
276
|
+
} else {
|
|
277
|
+
nativeBinding = require('@crosscopy/clipboard-linux-s390x-gnu')
|
|
278
|
+
}
|
|
279
|
+
} catch (e) {
|
|
280
|
+
loadError = e
|
|
281
|
+
}
|
|
282
|
+
break
|
|
283
|
+
default:
|
|
284
|
+
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
|
285
|
+
}
|
|
286
|
+
break
|
|
287
|
+
default:
|
|
288
|
+
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!nativeBinding) {
|
|
292
|
+
if (loadError) {
|
|
293
|
+
throw loadError
|
|
294
|
+
}
|
|
295
|
+
throw new Error(`Failed to load native binding`)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const { sum, availableFormats, getText, getTextAsync, setText, getImageBase64, setImageBase64 } = nativeBinding
|
|
299
|
+
|
|
300
|
+
module.exports.sum = sum
|
|
301
|
+
module.exports.availableFormats = availableFormats
|
|
302
|
+
module.exports.getText = getText
|
|
303
|
+
module.exports.getTextAsync = getTextAsync
|
|
304
|
+
module.exports.setText = setText
|
|
305
|
+
module.exports.getImageBase64 = getImageBase64
|
|
306
|
+
module.exports.setImageBase64 = setImageBase64
|
package/package.json
CHANGED
|
@@ -1,45 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crosscopy/clipboard",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"types": "index.d.ts",
|
|
6
|
+
"napi": {
|
|
7
|
+
"name": "clipboard",
|
|
8
|
+
"triples": {
|
|
9
|
+
"additional": [
|
|
10
|
+
"aarch64-apple-darwin",
|
|
11
|
+
"aarch64-unknown-linux-gnu",
|
|
12
|
+
"aarch64-pc-windows-msvc",
|
|
13
|
+
"universal-apple-darwin",
|
|
14
|
+
"riscv64gc-unknown-linux-gnu"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
14
17
|
},
|
|
18
|
+
"license": "MIT",
|
|
15
19
|
"repository": {
|
|
16
20
|
"type": "git",
|
|
17
|
-
"url": "
|
|
18
|
-
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"clipboard"
|
|
21
|
-
],
|
|
22
|
-
"author": "Huakun Shen",
|
|
23
|
-
"license": "ISC",
|
|
24
|
-
"bugs": {
|
|
25
|
-
"url": "https://github.com/CrossCopy/clipboard/issues"
|
|
21
|
+
"url": "https://github.com/CrossCopy/clipboard.git"
|
|
26
22
|
},
|
|
27
|
-
"homepage": "https://github.com/CrossCopy/clipboard#readme",
|
|
28
|
-
"dependencies": {},
|
|
29
23
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
24
|
+
"@napi-rs/cli": "^2.18.0",
|
|
25
|
+
"ava": "^6.0.1"
|
|
26
|
+
},
|
|
27
|
+
"ava": {
|
|
28
|
+
"timeout": "3m"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">= 10"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"artifacts": "napi artifacts",
|
|
35
|
+
"build": "napi build --platform --release",
|
|
36
|
+
"build:debug": "napi build --platform",
|
|
37
|
+
"prepublishOnly": "napi prepublish -t npm",
|
|
38
|
+
"test": "ava",
|
|
39
|
+
"universal": "napi universal",
|
|
40
|
+
"version": "napi version"
|
|
38
41
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
"optionalDependencies": {
|
|
43
|
+
"@crosscopy/clipboard-win32-x64-msvc": "0.2.3",
|
|
44
|
+
"@crosscopy/clipboard-darwin-x64": "0.2.3",
|
|
45
|
+
"@crosscopy/clipboard-linux-x64-gnu": "0.2.3",
|
|
46
|
+
"@crosscopy/clipboard-darwin-arm64": "0.2.3",
|
|
47
|
+
"@crosscopy/clipboard-linux-arm64-gnu": "0.2.3",
|
|
48
|
+
"@crosscopy/clipboard-win32-arm64-msvc": "0.2.3",
|
|
49
|
+
"@crosscopy/clipboard-darwin-universal": "0.2.3",
|
|
50
|
+
"@crosscopy/clipboard-linux-riscv64-gnu": "0.2.3"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/lib.rs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#![deny(clippy::all)]
|
|
2
|
+
use base64::{engine::general_purpose, Engine as _};
|
|
3
|
+
use clipboard_rs::{common::RustImage, Clipboard, ClipboardContext, ContentFormat, RustImageData};
|
|
4
|
+
|
|
5
|
+
#[macro_use]
|
|
6
|
+
extern crate napi_derive;
|
|
7
|
+
|
|
8
|
+
#[napi]
|
|
9
|
+
pub fn sum(a: i32, b: i32) -> i32 {
|
|
10
|
+
a + b
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#[napi]
|
|
14
|
+
pub fn available_formats() -> Vec<String> {
|
|
15
|
+
let ctx = ClipboardContext::new().unwrap();
|
|
16
|
+
let types = ctx.available_formats().unwrap();
|
|
17
|
+
types
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#[napi]
|
|
21
|
+
pub fn get_text() -> String {
|
|
22
|
+
let ctx = ClipboardContext::new().unwrap();
|
|
23
|
+
ctx.get_text().unwrap()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
#[napi]
|
|
27
|
+
async fn get_text_async() -> String {
|
|
28
|
+
let ctx = ClipboardContext::new().unwrap();
|
|
29
|
+
ctx.get_text().unwrap()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#[napi]
|
|
33
|
+
pub fn set_text(text: String) {
|
|
34
|
+
let ctx = ClipboardContext::new().unwrap();
|
|
35
|
+
ctx.set_text(text).unwrap()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[napi]
|
|
39
|
+
pub fn get_image_base64() -> String {
|
|
40
|
+
let ctx = ClipboardContext::new().unwrap();
|
|
41
|
+
let image = ctx.get_image().unwrap();
|
|
42
|
+
let image_bytes = image.to_png().unwrap().get_bytes().to_vec();
|
|
43
|
+
let base64_str = general_purpose::STANDARD_NO_PAD.encode(&image_bytes);
|
|
44
|
+
base64_str
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#[napi]
|
|
48
|
+
pub fn set_image_base64(base64_str: String) {
|
|
49
|
+
let ctx = ClipboardContext::new().unwrap();
|
|
50
|
+
let decoded: Vec<u8> = general_purpose::STANDARD_NO_PAD.decode(base64_str).unwrap();
|
|
51
|
+
let img = RustImageData::from_bytes(&decoded).unwrap();
|
|
52
|
+
ctx.set_image(img).unwrap()
|
|
53
|
+
}
|
package/README.md
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# General Clipboard Listener
|
|
2
|
-
|
|
3
|
-
> A Cross-Platform clipboard listener that listens for both text and image (screenshots).
|
|
4
|
-
> Designed for NodeJS, not for web.
|
|
5
|
-
> Provides API to read and write text/image from/to clipboard.
|
|
6
|
-
|
|
7
|
-
npm package: https://www.npmjs.com/package/@crosscopy/clipboard
|
|
8
|
-
|
|
9
|
-
## Installation
|
|
10
|
-
|
|
11
|
-
`npm i @crosscopy/clipboard`
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
It has a very easy to use event-based system.
|
|
16
|
-
|
|
17
|
-
See [demo.ts](./demo.ts) for a demo.
|
|
18
|
-
|
|
19
|
-
Run `ts-node demo.ts`.
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
import clipboardEventListener from "./@crosscopy/clipboard";
|
|
23
|
-
|
|
24
|
-
console.log(clipboard.readTextSync());
|
|
25
|
-
console.log(await clipboard.readText());
|
|
26
|
-
const imgBuf = clipboard.readImageSync();
|
|
27
|
-
// console.log(imgBuf.toString("base64"));
|
|
28
|
-
// console.log(clipboard.readImageBase64Sync());
|
|
29
|
-
// await clipboard.writeImage(base64img); // add fake image to clipboard
|
|
30
|
-
clipboard.writeImageSync(base64img); // add fake image to clipboard
|
|
31
|
-
console.log(""); // give some time
|
|
32
|
-
console.assert(clipboard.readImageBase64Sync() === base64img);
|
|
33
|
-
|
|
34
|
-
// * test readimage
|
|
35
|
-
clipboard.writeImageSync(base64img);
|
|
36
|
-
console.log();
|
|
37
|
-
console.assert(
|
|
38
|
-
(await clipboard.readImage()).toString("base64") === base64img
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
await clipboard.writeImage(base64img);
|
|
42
|
-
console.log();
|
|
43
|
-
console.assert((await clipboard.readImageBase64()) === base64img);
|
|
44
|
-
clipboard.on("text", (text) => {
|
|
45
|
-
console.log(text);
|
|
46
|
-
});
|
|
47
|
-
clipboard.on("image", (data) => {
|
|
48
|
-
fs.writeFileSync("test.png", data);
|
|
49
|
-
});
|
|
50
|
-
clipboard.listen();
|
|
51
|
-
setTimeout(() => {
|
|
52
|
-
clipboard.close();
|
|
53
|
-
}, 10000);
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Explanation
|
|
57
|
-
|
|
58
|
-
It's achieved using child process + `stdout`.
|
|
59
|
-
|
|
60
|
-
I took a golang version of the listener from [golang-design/clipboard](https://github.com/golang-design/clipboard).
|
|
61
|
-
|
|
62
|
-
When a change is detected, `IMAGE_CHANGED` or `TEXT_CHANGED` is printed to `stdout`.
|
|
63
|
-
|
|
64
|
-
This library runs compiled go-version clipboard listener using child process and listen to the `stdout`.
|
|
65
|
-
|
|
66
|
-
If it sees the keywords in child process's `stdout`, an event will be emitted.
|
|
67
|
-
|
|
68
|
-
Run `npm run demo` to see a demo for 10 sec. Once started, copy some text and screenshot and check the terminal.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## Supported Platforms
|
|
72
|
-
|
|
73
|
-
Format: `process.platform/process.arch`
|
|
74
|
-
|
|
75
|
-
The process here is from nodejs.
|
|
76
|
-
|
|
77
|
-
Supported platforms can be found in `go-clipboard/binaries`.
|
|
78
|
-
|
|
79
|
-
If your nodejs gives different platform or arch, it may not work.
|
|
80
|
-
|
|
81
|
-
## Release
|
|
82
|
-
|
|
83
|
-
Cross Compile doesn't work due to some CGO problem. Have to build on different platforms manually.
|
|
84
|
-
|
|
85
|
-
Within `go-clipboard` folder.
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
go build -o binaries/go-clipboard-darwin-arm64
|
|
89
|
-
go build -o binaries/go-clipboard-darwin-x64
|
|
90
|
-
go build -o binaries/go-clipboard-win32-x64.exe
|
|
91
|
-
go build -o binaries/go-clipboard-linux-x64
|
|
92
|
-
go build -o binaries/go-clipboard-linux-arm
|
|
93
|
-
go build -o binaries/go-clipboard-linux-arm64
|
|
94
|
-
```
|
package/dist/demo.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|