Skip to content

Commit

Permalink
fix: 更新 clipboard 文件位置以修复剪切板图片访问的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
rxliuli committed Oct 2, 2022
1 parent 8dc4f56 commit c113609
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 96 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/sh
# require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212)
command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; }

# write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file)
filePath=`xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-`
if [ ! -n "$filePath" ] ;then
if
xclip -selection clipboard -target image/png -o >/dev/null 2>&1
then
xclip -selection clipboard -target image/png -o >$1 2>/dev/null
echo $1
else
echo "no image"
fi
else
echo $filePath
fi
#!/bin/sh
# require xclip(see http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script/677212#677212)
command -v xclip >/dev/null 2>&1 || { echo >&1 "no xclip"; exit 1; }

# write image in clipboard to file (see http://unix.stackexchange.com/questions/145131/copy-image-from-clipboard-to-file)
filePath=`xclip -selection clipboard -o 2>/dev/null | grep ^file:// | cut -c8-`
if [ ! -n "$filePath" ] ;then
if
xclip -selection clipboard -target image/png -o >/dev/null 2>&1
then
xclip -selection clipboard -target image/png -o >$1 2>/dev/null
echo $1
else
echo "no image"
fi
else
echo $filePath
fi
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@

param($imagePath)

# Adapted from https://github.com/octan3/img-clipboard-dump/blob/master/dump-clipboard-png.ps1

Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()

if ($img -eq $null) {
"no image"
Exit 1
}

if (-not $imagePath) {
"no image"
Exit 1
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$stream = [IO.File]::Open($imagePath, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb)) | out-null
$encoder.Save($stream) | out-null
$stream.Dispose() | out-null

$imagePath

param($imagePath)

# Adapted from https://github.com/octan3/img-clipboard-dump/blob/master/dump-clipboard-png.ps1

Add-Type -Assembly PresentationCore
$img = [Windows.Clipboard]::GetImage()

if ($img -eq $null) {
"no image"
Exit 1
}

if (-not $imagePath) {
"no image"
Exit 1
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$stream = [IO.File]::Open($imagePath, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb)) | out-null
$encoder.Save($stream) | out-null
$stream.Dispose() | out-null

$imagePath
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
# Adapted from https://github.com/octan3/img-clipboard-dump/blob/master/dump-clipboard-png.ps1
param($imagePath)

# https://github.com/PowerShell/PowerShell/issues/7233
# fix the output encoding bug
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

Add-Type -Assembly PresentationCore
function main {
$img = [Windows.Clipboard]::GetImage()

if ($img -eq $null) {
"no image"
Exit 1
}

if (-not $imagePath) {
"no image"
Exit 1
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$stream = [IO.File]::Open($imagePath, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb)) | out-null
$encoder.Save($stream) | out-null
$stream.Dispose() | out-null

$imagePath
# fix windows 10 native cmd crash bug when "picgo upload"
# https://github.com/PicGo/PicGo-Core/issues/32
Exit 1
}

try {
# For WIN10
$file = Get-Clipboard -Format FileDropList
if ($file -ne $null) {
Convert-Path $file
Exit 1
}
} catch {
# For WIN7 WIN8 WIN10
main
}

# Adapted from https://github.com/octan3/img-clipboard-dump/blob/master/dump-clipboard-png.ps1
param($imagePath)

# https://github.com/PowerShell/PowerShell/issues/7233
# fix the output encoding bug
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

Add-Type -Assembly PresentationCore
function main {
$img = [Windows.Clipboard]::GetImage()

if ($img -eq $null) {
"no image"
Exit 1
}

if (-not $imagePath) {
"no image"
Exit 1
}

$fcb = new-object Windows.Media.Imaging.FormatConvertedBitmap($img, [Windows.Media.PixelFormats]::Rgb24, $null, 0)
$stream = [IO.File]::Open($imagePath, "OpenOrCreate")
$encoder = New-Object Windows.Media.Imaging.PngBitmapEncoder
$encoder.Frames.Add([Windows.Media.Imaging.BitmapFrame]::Create($fcb)) | out-null
$encoder.Save($stream) | out-null
$stream.Dispose() | out-null

$imagePath
# fix windows 10 native cmd crash bug when "picgo upload"
# https://github.com/PicGo/PicGo-Core/issues/32
Exit 1
}

try {
# For WIN10
$file = Get-Clipboard -Format FileDropList
if ($file -ne $null) {
Convert-Path $file
Exit 1
}
} catch {
# For WIN7 WIN8 WIN10
main
}

main
3 changes: 3 additions & 0 deletions apps/joplin-vscode-plugin/src/RootPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import path from 'path'

export const RootPath = path.resolve(__dirname, '..')
12 changes: 6 additions & 6 deletions apps/joplin-vscode-plugin/src/util/UploadResourceUtil.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { fileURLToPath } from 'url'
import * as os from 'os'
import * as path from 'path'
import { createReadStream, mkdirpSync } from '@liuli-util/fs-extra'
import { spawn } from 'child_process'
import * as fs from '@liuli-util/fs-extra'
import { resourceApi } from 'joplin-api'
import { RootPath } from '../RootPath'

/**
* for clipboard image
Expand Down Expand Up @@ -65,12 +65,12 @@ export class UploadResourceUtil {
const platformPaths: {
[index: string]: string
} = {
darwin: './clipboard/mac.applescript',
win32: './clipboard/windows.ps1',
win10: './clipboard/windows10.ps1',
linux: './clipboard/linux.sh',
darwin: 'mac.applescript',
win32: 'windows.ps1',
win10: 'windows10.ps1',
linux: 'linux.sh',
}
const scriptPath = path.join(__dirname, platformPaths[platform])
const scriptPath = path.join(RootPath, 'resources/clipboard', platformPaths[platform])
try {
if (platform === 'darwin') {
execution = spawn('osascript', [scriptPath, imagePath])
Expand Down

0 comments on commit c113609

Please sign in to comment.