11import { $ } from "bun"
2- import { platform } from "os"
2+ import { platform , release } from "os"
33import clipboardy from "clipboardy"
44import { lazy } from "../../../../util/lazy.js"
55import { tmpdir } from "os"
@@ -29,6 +29,18 @@ export namespace Clipboard {
2929 }
3030 }
3131
32+ if ( os === "win32" || release ( ) . includes ( "WSL" ) ) {
33+ const script =
34+ "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
35+ const base64 = await $ `powershell.exe -command "${ script } "` . nothrow ( ) . text ( )
36+ if ( base64 ) {
37+ const imageBuffer = Buffer . from ( base64 . trim ( ) , "base64" )
38+ if ( imageBuffer . length > 0 ) {
39+ return { data : imageBuffer . toString ( "base64" ) , mime : "image/png" }
40+ }
41+ }
42+ }
43+
3244 if ( os === "linux" ) {
3345 const wayland = await $ `wl-paste -t image/png` . nothrow ( ) . arrayBuffer ( )
3446 if ( wayland && wayland . byteLength > 0 ) {
@@ -40,18 +52,6 @@ export namespace Clipboard {
4052 }
4153 }
4254
43- if ( os === "win32" ) {
44- const script =
45- "Add-Type -AssemblyName System.Windows.Forms; $img = [System.Windows.Forms.Clipboard]::GetImage(); if ($img) { $ms = New-Object System.IO.MemoryStream; $img.Save($ms, [System.Drawing.Imaging.ImageFormat]::Png); [System.Convert]::ToBase64String($ms.ToArray()) }"
46- const base64 = await $ `powershell -command "${ script } "` . nothrow ( ) . text ( )
47- if ( base64 ) {
48- const imageBuffer = Buffer . from ( base64 . trim ( ) , "base64" )
49- if ( imageBuffer . length > 0 ) {
50- return { data : imageBuffer . toString ( "base64" ) , mime : "image/png" }
51- }
52- }
53- }
54-
5555 const text = await clipboardy . read ( ) . catch ( ( ) => { } )
5656 if ( text ) {
5757 return { data : text , mime : "text/plain" }
0 commit comments