clipboardy 5.0.2 → 5.1.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/lib/windows.js +45 -24
- package/package.json +4 -3
package/lib/windows.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {Buffer} from 'node:buffer';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import {fileURLToPath} from 'node:url';
|
|
4
3
|
import {execa, execaSync} from 'execa';
|
|
5
4
|
import {is64bitSync} from 'is64bit';
|
|
5
|
+
import {powerShellPath, executePowerShell} from 'powershell-utils';
|
|
6
6
|
|
|
7
7
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
|
|
@@ -11,21 +11,6 @@ const binarySuffix = is64bitSync() ? 'x86_64' : 'i686';
|
|
|
11
11
|
// Binaries from: https://github.com/sindresorhus/win-clipboard
|
|
12
12
|
const windowBinaryPath = path.join(__dirname, `../fallbacks/windows/clipboard_${binarySuffix}.exe`);
|
|
13
13
|
|
|
14
|
-
const powershellPath = 'powershell.exe';
|
|
15
|
-
|
|
16
|
-
const psCommonArgs = [
|
|
17
|
-
'-NoProfile',
|
|
18
|
-
'-NonInteractive',
|
|
19
|
-
'-ExecutionPolicy',
|
|
20
|
-
'Bypass',
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
// Use -EncodedCommand for better safety and Unicode handling
|
|
24
|
-
const createEncodedCommand = script => {
|
|
25
|
-
const encodedCommand = Buffer.from(script, 'utf16le').toString('base64');
|
|
26
|
-
return [...psCommonArgs, '-EncodedCommand', encodedCommand];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
14
|
// Robust PowerShell commands with error handling
|
|
30
15
|
const psCopyScript = `
|
|
31
16
|
try {
|
|
@@ -67,28 +52,64 @@ const executeWithFallbackSync = (primaryCommand, fallbackCommand) => {
|
|
|
67
52
|
}
|
|
68
53
|
};
|
|
69
54
|
|
|
55
|
+
const runPowerShell = (script, options) => execa(
|
|
56
|
+
powerShellPath(),
|
|
57
|
+
executePowerShell.createArguments(script),
|
|
58
|
+
{
|
|
59
|
+
windowsHide: true,
|
|
60
|
+
...options,
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const runPowerShellSync = (script, options) => execaSync(
|
|
65
|
+
powerShellPath(),
|
|
66
|
+
executePowerShell.createArguments(script),
|
|
67
|
+
{
|
|
68
|
+
windowsHide: true,
|
|
69
|
+
...options,
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const runBinary = (arguments_, options) => execa(
|
|
74
|
+
windowBinaryPath,
|
|
75
|
+
arguments_,
|
|
76
|
+
{
|
|
77
|
+
windowsHide: true,
|
|
78
|
+
...options,
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const runBinarySync = (arguments_, options) => execaSync(
|
|
83
|
+
windowBinaryPath,
|
|
84
|
+
arguments_,
|
|
85
|
+
{
|
|
86
|
+
windowsHide: true,
|
|
87
|
+
...options,
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
|
|
70
91
|
const clipboard = {
|
|
71
92
|
copy: async options => executeWithFallback(
|
|
72
|
-
async () =>
|
|
73
|
-
async () =>
|
|
93
|
+
async () => runPowerShell(psCopyScript, options),
|
|
94
|
+
async () => runBinary(['--copy'], options),
|
|
74
95
|
),
|
|
75
96
|
|
|
76
97
|
async paste(options) {
|
|
77
98
|
const {stdout} = await executeWithFallback(
|
|
78
|
-
async () =>
|
|
79
|
-
async () =>
|
|
99
|
+
async () => runPowerShell(psPasteScript, options),
|
|
100
|
+
async () => runBinary(['--paste'], options),
|
|
80
101
|
);
|
|
81
102
|
return stdout;
|
|
82
103
|
},
|
|
83
104
|
|
|
84
105
|
copySync: options => executeWithFallbackSync(
|
|
85
|
-
() =>
|
|
86
|
-
() =>
|
|
106
|
+
() => runPowerShellSync(psCopyScript, options),
|
|
107
|
+
() => runBinarySync(['--copy'], options),
|
|
87
108
|
),
|
|
88
109
|
|
|
89
110
|
pasteSync: options => executeWithFallbackSync(
|
|
90
|
-
() =>
|
|
91
|
-
() =>
|
|
111
|
+
() => runPowerShellSync(psPasteScript, options),
|
|
112
|
+
() => runBinarySync(['--paste'], options),
|
|
92
113
|
).stdout,
|
|
93
114
|
};
|
|
94
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clipboardy",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Access the system clipboard (copy/paste)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/clipboardy",
|
|
@@ -45,10 +45,11 @@
|
|
|
45
45
|
"xsel"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"execa": "^9.6.
|
|
48
|
+
"execa": "^9.6.1",
|
|
49
49
|
"is-wayland": "^0.1.0",
|
|
50
50
|
"is-wsl": "^3.1.0",
|
|
51
|
-
"is64bit": "^2.0.0"
|
|
51
|
+
"is64bit": "^2.0.0",
|
|
52
|
+
"powershell-utils": "^0.2.0"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
55
|
"ava": "^6.4.1",
|