Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
724 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { UniversalPicGo } from "./core/UniversalPicGo" | ||
import { win, hasNodeEnv } from "universal-picgo-store" | ||
|
||
export { UniversalPicGo } | ||
export { win, hasNodeEnv } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
import { IClipboardImage, IPicGo } from "../../types" | ||
|
||
const getClipboardImageBrowser = async (ctx: IPicGo): Promise<IClipboardImage> => { | ||
throw new Error("getClipboardImage is not supported in browser") | ||
} | ||
|
||
export { getClipboardImageBrowser } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
import { IClipboardImage, IPicGo } from "../../types" | ||
import { win } from "universal-picgo-store" | ||
import { CLIPBOARD_IMAGE_FOLDER } from "../constants" | ||
import { ensureFolderSync } from "../nodeUtils" | ||
import dayjs from "dayjs" | ||
import { getCurrentPlatform, Platform } from "../os" | ||
import macClipboardScript from "./script/mac.applescript?raw" | ||
import windowsClipboardScript from "./script/windows.ps1?raw" | ||
import windows10ClipboardScript from "./script/windows10.ps1?raw" | ||
import linuxClipboardScript from "./script/linux.sh?raw" | ||
import wslClipboardScript from "./script/wsl.sh?raw" | ||
|
||
const platform2ScriptContent: { | ||
[key in Platform]: string | ||
} = { | ||
darwin: macClipboardScript, | ||
win32: windowsClipboardScript, | ||
win10: windows10ClipboardScript, | ||
linux: linuxClipboardScript, | ||
wsl: wslClipboardScript, | ||
} | ||
|
||
/** | ||
* powershell will report error if file does not have a '.ps1' extension, | ||
* so we should keep the extension name consistent with corresponding shell | ||
*/ | ||
const platform2ScriptFilename: { | ||
[key in Platform]: string | ||
} = { | ||
darwin: "mac.applescript", | ||
win32: "windows.ps1", | ||
win10: "windows10.ps1", | ||
linux: "linux.sh", | ||
wsl: "wsl.sh", | ||
} | ||
|
||
const createImageFolder = (ctx: IPicGo): void => { | ||
const fs = win.fs | ||
const path = win.require("path") | ||
const imagePath = path.join(ctx.baseDir, CLIPBOARD_IMAGE_FOLDER) | ||
ensureFolderSync(fs, imagePath) | ||
} | ||
|
||
const getClipboardImageElectron = async (ctx: IPicGo): Promise<IClipboardImage> => { | ||
const fs = win.fs | ||
const path = win.require("path") | ||
|
||
createImageFolder(ctx) | ||
// add an clipboard image folder to control the image cache file | ||
const imagePath = path.join(ctx.baseDir, CLIPBOARD_IMAGE_FOLDER, `${dayjs().format("YYYYMMDDHHmmss")}.png`) | ||
return await new Promise<IClipboardImage>((resolve: Function, reject: Function): void => { | ||
const platform = getCurrentPlatform() | ||
const scriptPath = path.join(ctx.baseDir, platform2ScriptFilename[platform]) | ||
// If the script does not exist yet, we need to write the content to the script file | ||
if (!fs.existsSync(scriptPath)) { | ||
fs.writeFileSync(scriptPath, platform2ScriptContent[platform], "utf8") | ||
} | ||
|
||
throw new Error("开发中...") | ||
}) | ||
} | ||
|
||
export { getClipboardImageElectron } |
49 changes: 49 additions & 0 deletions
49
libs/Universal-PicGo-Core/src/utils/clipboard/script/linux.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/sh | ||
|
||
if [ -z "$DISPLAY" ]; then | ||
echo "no support" >&2 | ||
exit 1 | ||
fi | ||
|
||
case "$XDG_SESSION_TYPE" in | ||
wayland) | ||
command -v wl-copy >/dev/null 2>&1 || { | ||
echo >&2 "no wl-clipboard" | ||
exit 1 | ||
} | ||
filePath=$(wl-copy -o 2>/dev/null | grep ^file:// | cut -c8-) | ||
if [ -z "$filePath" ]; then | ||
if | ||
wl-copy -t image/png image/png -o >"$1" 2>/dev/null | ||
then | ||
echo "$1" | ||
else | ||
rm -f "$1" | ||
echo "no image" | ||
fi | ||
else | ||
echo "$filePath" | ||
fi | ||
;; | ||
x11 | tty) | ||
# 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 >&2 "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 [ -z "$filePath" ]; then | ||
if | ||
xclip -selection clipboard -target image/png -o >"$1" 2>/dev/null | ||
then | ||
echo "$1" | ||
else | ||
rm -f "$1" | ||
echo "no image" | ||
fi | ||
else | ||
echo "$filePath" | ||
fi | ||
;; | ||
esac |
41 changes: 41 additions & 0 deletions
41
libs/Universal-PicGo-Core/src/utils/clipboard/script/mac.applescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
-- From https://github.com/mushanshitiancai/vscode-paste-image | ||
property fileTypes : {{«class PNGf», ".png"}} | ||
|
||
on run argv | ||
if argv is {} then | ||
return "" | ||
end if | ||
|
||
if ((clipboard info) as string) contains "«class furl»" then | ||
return POSIX path of (the clipboard as «class furl») | ||
else | ||
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 "no image" | ||
end try | ||
else | ||
return "no image" | ||
end if | ||
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 |
Oops, something went wrong.