Skip to content

Commit 8314604

Browse files
committed
🐛 Fix(clipboard): clipboard image getter error in macOS
1 parent 0da0e97 commit 8314604

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed
14 Bytes
Binary file not shown.

src/utils/getClipboardImage.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import path from 'path'
33
import { spawn } from 'child_process'
44
import dayjs from 'dayjs'
55
import os from 'os'
6+
import fs from 'fs-extra'
7+
import { ClipboardImage } from '../utils/interfaces'
68

79
const getCurrentPlatform = (): string => {
810
let platform = process.platform
@@ -19,17 +21,17 @@ const getCurrentPlatform = (): string => {
1921
}
2022

2123
// Thanks to vs-picgo: https://github.com/Spades-S/vs-picgo/blob/master/src/extension.ts
22-
const getClipboardImage = (ctx: PicGo): Promise<any> => {
24+
const getClipboardImage = (ctx: PicGo): Promise<ClipboardImage> => {
2325
const imagePath = path.join(ctx.baseDir, `${dayjs().format('YYYYMMDDHHmmss')}.png`)
24-
return new Promise((resolve: any, reject: any): any => {
26+
return new Promise<ClipboardImage>((resolve: Function): void => {
2527
let platform: string = getCurrentPlatform()
2628
let execution = null
2729
// for PicGo GUI
2830
let env = ctx.config.PICGO_ENV === 'GUI'
2931
const platformPaths: {
3032
[index: string]: string
3133
} = {
32-
'darwin': env ? path.join(ctx.baseDir,'./mac.applescript') : './clipboard/mac.applescript',
34+
'darwin': env ? path.join(ctx.baseDir,'mac.applescript') : './clipboard/mac.applescript',
3335
'win32': env ? path.join(ctx.baseDir, 'windows.ps1') : './clipboard/windows.ps1',
3436
'win10': env ? path.join(ctx.baseDir, 'windows10.ps1') : './clipboard/windows10.ps1',
3537
'linux': env ? path.join(ctx.baseDir, 'linux.sh') : './clipboard/linux.sh'
@@ -65,16 +67,15 @@ const getClipboardImage = (ctx: PicGo): Promise<any> => {
6567
let isExistFile = false
6668
// in macOS if your copy the file in system, it's basename will not equal to our default basename
6769
if (path.basename(imgPath) !== path.basename(imagePath)) {
68-
isExistFile = true
70+
if (fs.existsSync(imgPath)) {
71+
isExistFile = true
72+
}
6973
}
7074
resolve({
7175
imgPath,
7276
isExistFile
7377
})
7478
})
75-
execution.stderr.on('data', (err: any) => {
76-
reject(err)
77-
})
7879
})
7980
}
8081

0 commit comments

Comments
 (0)