Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support WSL (windows subsystem for linux) #45

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ImageClipboard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ function clipboard_img()
else
error("Please install wlclipboard or xclip to your system")
end
elseif Sys.iswindows() || Sys.islinux() && haskey(ENV, "WSLENV")
img = _powershell()
elseif Sys.islinux()
if _isavailable_xclip()
img = _xclip()
else
error("Please install xclip to your system")
end
elseif Sys.iswindows()
img = _powershell()
elseif Sys.isapple()
img = _osascript()
else
Expand All @@ -57,14 +57,14 @@ function clipboard_img(img::AbstractMatrix{<:Colorant})
else
error("Please install wlclipboard or xclip to your system")
end
elseif Sys.iswindows() || Sys.islinux() && haskey(ENV, "WSLENV")
_powershell(img)
elseif Sys.islinux()
if _isavailable_xclip()
_xclip(img)
else
error("Please install xclip to your system")
end
elseif Sys.iswindows()
_powershell(img)
elseif Sys.isapple()
_osascript(img)
else
Expand Down
10 changes: 5 additions & 5 deletions src/_powershell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function _powershell()
addtype = `Add-Type -AssemblyName System.Windows.Forms\;`
getimg = `\$img=\[Windows.Forms.Clipboard\]::GetImage\(\)\;`
saveimg = `if \(\$img -ne \$null\)\{\$img.Save\(\"$(path_png)\"\)\}`
cmd = `powershell -NoProfile $addtype $getimg $saveimg`
cmd = `powershell.exe -NoProfile $addtype $getimg $saveimg`
run(cmd)

# Paste from clipboard
Expand All @@ -33,18 +33,18 @@ Copy an image to clipboard using `powershell`
function _powershell(img::AbstractMatrix{<:Colorant})
mktempdir() do dir
# Define path
path_png = joinpath(dir, "clipboard.png")
filename = "clipboard.png"

# Save image
save(path_png, img)
save(joinpath(dir, filename), img)

# Compose command & run
addtype = `Add-Type -AssemblyName System.Windows.Forms\;`
adddrawing = `\[Reflection.Assembly\]::LoadWithPartialName\(\'System.Drawing\'\)\;`
getfile = `\$file = get-item\(\"$(path_png)\"\)\;`
getfile = `\$file = get-item\(\"$(filename)\"\)\;`
getimg = `\$img = \[System.Drawing.Image\]::Fromfile\(\$file\)\;`
copyimg = `\[System.Windows.Forms.Clipboard\]::SetImage\(\$img\)\;`
cmd = `powershell -NoProfile $addtype $adddrawing $getfile $getimg $copyimg`
cmd = Cmd(`powershell.exe -NoProfile $addtype $adddrawing $getfile $getimg $copyimg`; dir)
run(cmd)
end
end
Loading