mirror of
https://github.com/Kuingsmile/PicList.git
synced 2025-03-13 00:18:13 -04:00
Added: clipboard image handler for picgo-core
This commit is contained in:
parent
8ff7d15f8d
commit
405548426a
@ -5,6 +5,13 @@ import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
import { remote, app } from 'electron'
|
||||
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
global.__static = path.join(__dirname, '/static').replace(/\\/g, '\\\\')
|
||||
}
|
||||
if (process.env.DEBUG_ENV === 'debug') {
|
||||
global.__static = path.join(__dirname, '../../static').replace(/\\/g, '\\\\')
|
||||
}
|
||||
|
||||
const APP = process.type === 'renderer' ? remote.app : app
|
||||
const STORE_PATH = APP.getPath('userData')
|
||||
|
||||
@ -35,4 +42,11 @@ if (!db.has('settings.shortKey').value()) {
|
||||
}).write()
|
||||
}
|
||||
|
||||
// init generate clipboard image files
|
||||
if (!fs.pathExistsSync(path.join(STORE_PATH, 'windows.ps1'))) {
|
||||
fs.copySync(path.join(__static, '/linux.sh'), path.join(STORE_PATH, '/linux.sh'))
|
||||
fs.copySync(path.join(__static, '/mac.applescript'), path.join(STORE_PATH, '/mac.applescript'))
|
||||
fs.copySync(path.join(__static, '/windows.ps1'), path.join(STORE_PATH, '/windows.ps1'))
|
||||
}
|
||||
|
||||
export default db
|
||||
|
@ -84,8 +84,9 @@ class Uploader {
|
||||
upload () {
|
||||
const win = BrowserWindow.fromWebContents(this.webContents)
|
||||
const picgo = new PicGo(CONFIG_PATH)
|
||||
console.log(picgo.pluginLoader.getList())
|
||||
picgo.config.debug = true
|
||||
// for picgo-core
|
||||
picgo.config.PICGO_ENV = 'GUI'
|
||||
let input = this.img
|
||||
|
||||
picgo.helper.beforeUploadPlugins.register('renameFn', {
|
||||
|
16
static/linux.sh
Normal file
16
static/linux.sh
Normal file
@ -0,0 +1,16 @@
|
||||
# from https://github.com/favers/vscode-qiniu-upload-image/blob/master/lib/linux.sh
|
||||
|
||||
#!/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)
|
||||
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
|
38
static/mac.applescript
Normal file
38
static/mac.applescript
Normal file
@ -0,0 +1,38 @@
|
||||
-- From https://github.com/mushanshitiancai/vscode-paste-image
|
||||
property fileTypes : {{«class PNGf», ".png"}}
|
||||
|
||||
on run argv
|
||||
if argv is {} then
|
||||
return ""
|
||||
end if
|
||||
|
||||
set imagePath to (item 1 of argv)
|
||||
set theType to getType()
|
||||
|
||||
if theType is not missing value then
|
||||
try
|
||||
set myFile to (open for access imagePath with write permission)
|
||||
set eof myFile to 0
|
||||
write (the clipboard as (first item of theType)) to myFile
|
||||
close access myFile
|
||||
return (POSIX path of imagePath)
|
||||
on error
|
||||
try
|
||||
close access myFile
|
||||
end try
|
||||
return ""
|
||||
end try
|
||||
else
|
||||
return "no image"
|
||||
end if
|
||||
end run
|
||||
|
||||
on getType()
|
||||
repeat with aType in fileTypes
|
||||
repeat with theInfo in (clipboard info)
|
||||
if (first item of theInfo) is equal to (first item of aType) then return aType
|
||||
end repeat
|
||||
end repeat
|
||||
return missing value
|
||||
end getType
|
||||
|
26
static/windows.ps1
Normal file
26
static/windows.ps1
Normal file
@ -0,0 +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
|
Loading…
Reference in New Issue
Block a user