11import { spawn } from 'node:child_process' ;
22
3- const TIMEOUT = 2000 ;
3+ const TIMEOUT = 3000 ;
44
55function checkUnixCommandExists ( command : string ) : Promise < boolean > {
66 return new Promise ( ( resolve ) => {
@@ -12,17 +12,26 @@ function checkUnixCommandExists(command: string): Promise<boolean> {
1212
1313type Command = [ string , Array < string > ] ;
1414
15+ const WINDOWS_READ_COMMAND : Command = [
16+ 'powershell' ,
17+ [
18+ '-NoProfile' ,
19+ '-Command' ,
20+ '[Console]::OutputEncoding = [Text.UTF8Encoding]::new($false); Get-Clipboard'
21+ ]
22+ ] ;
23+
1524async function getReadCommand ( ) : Promise < Command | undefined > {
1625 switch ( process . platform ) {
1726 case 'darwin' :
1827 return [ 'pbpaste' , [ ] ] ;
1928 case 'win32' :
20- return [ 'powershell' , [ 'Get-Clipboard' ] ] ;
29+ return WINDOWS_READ_COMMAND ;
2130 case 'linux' :
2231 case 'freebsd' :
2332 case 'openbsd' :
2433 if ( process . env . WSL_DISTRO_NAME ) {
25- return [ 'powershell.exe' , [ '-noprofile' , '-command' , 'Get-Clipboard' ] ] ;
34+ return WINDOWS_READ_COMMAND ;
2635 }
2736 if ( process . env . WAYLAND_DISPLAY ) {
2837 return [ 'wl-paste' , [ ] ] ;
@@ -69,17 +78,26 @@ export function readText(): Promise<string> {
6978 } ) ;
7079}
7180
81+ const WINDOWS_WRITE_COMMAND : Command = [
82+ 'powershell' ,
83+ [
84+ '-NoProfile' ,
85+ '-Command' ,
86+ '[Console]::InputEncoding = [Text.UTF8Encoding]::new($false); [Console]::In.ReadToEnd() | Set-Clipboard'
87+ ]
88+ ] ;
89+
7290async function getWriteCommand ( ) : Promise < Command | undefined > {
7391 switch ( process . platform ) {
7492 case 'darwin' :
7593 return [ 'pbcopy' , [ ] ] ;
7694 case 'win32' :
77- return [ 'clip' , [ ] ] ;
95+ return WINDOWS_WRITE_COMMAND ;
7896 case 'linux' :
7997 case 'freebsd' :
8098 case 'openbsd' :
8199 if ( process . env . WSL_DISTRO_NAME ) {
82- return [ 'clip.exe' , [ ] ] ;
100+ return WINDOWS_WRITE_COMMAND ;
83101 }
84102 if ( process . env . WAYLAND_DISPLAY ) {
85103 return [ 'wl-copy' , [ ] ] ;
0 commit comments