Skip to content

Commit

Permalink
fix: fix read image from clipboard not working on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed Jul 25, 2024
1 parent 9f72cfb commit cb99d2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ignore-workspace-root-check=true
node-linker=hoisted
package-manager-strict=false
20 changes: 10 additions & 10 deletions src/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const getClipboardImageAsBase64Url = async (): Promise<string | null> => {

switch (osPlatform) {
case 'win32':
fileExtension = '.bmp'
mimeType = 'image/bmp'
fileExtension = '.png'
mimeType = 'image/png'
filePath = path.win32.join(
tempDir,
`clipboard_image_${randomString}${fileExtension}`
Expand All @@ -30,14 +30,14 @@ const getClipboardImageAsBase64Url = async (): Promise<string | null> => {
args = [
'-command',
`Add-Type -AssemblyName System.Windows.Forms;
Add-Type -AssemblyName System.Drawing;
$img = [System.Windows.Forms.Clipboard]::GetImage();
if ($img -ne $null) {
$img.Save('${filePath}', [System.Drawing.Imaging.ImageFormat]::Bmp);
$img.Dispose();
} else {
Write-Error "No image found in clipboard"
}`
Add-Type -AssemblyName System.Drawing;
$img = [System.Windows.Forms.Clipboard]::GetImage();
if ($img -ne $null) {
$img.Save('${filePath}', [System.Drawing.Imaging.ImageFormat]::Png);
$img.Dispose();
} else {
Write-Error "No image found in clipboard"
}`
]
break
case 'darwin':
Expand Down

0 comments on commit cb99d2d

Please sign in to comment.