@@ -3,6 +3,8 @@ import path from 'path'
3
3
import { spawn } from 'child_process'
4
4
import dayjs from 'dayjs'
5
5
import os from 'os'
6
+ import fs from 'fs-extra'
7
+ import { ClipboardImage } from '../utils/interfaces'
6
8
7
9
const getCurrentPlatform = ( ) : string => {
8
10
let platform = process . platform
@@ -19,17 +21,17 @@ const getCurrentPlatform = (): string => {
19
21
}
20
22
21
23
// 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 > => {
23
25
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 => {
25
27
let platform : string = getCurrentPlatform ( )
26
28
let execution = null
27
29
// for PicGo GUI
28
30
let env = ctx . config . PICGO_ENV === 'GUI'
29
31
const platformPaths : {
30
32
[ index : string ] : string
31
33
} = {
32
- 'darwin' : env ? path . join ( ctx . baseDir , './ mac.applescript' ) : './clipboard/mac.applescript' ,
34
+ 'darwin' : env ? path . join ( ctx . baseDir , 'mac.applescript' ) : './clipboard/mac.applescript' ,
33
35
'win32' : env ? path . join ( ctx . baseDir , 'windows.ps1' ) : './clipboard/windows.ps1' ,
34
36
'win10' : env ? path . join ( ctx . baseDir , 'windows10.ps1' ) : './clipboard/windows10.ps1' ,
35
37
'linux' : env ? path . join ( ctx . baseDir , 'linux.sh' ) : './clipboard/linux.sh'
@@ -65,16 +67,15 @@ const getClipboardImage = (ctx: PicGo): Promise<any> => {
65
67
let isExistFile = false
66
68
// in macOS if your copy the file in system, it's basename will not equal to our default basename
67
69
if ( path . basename ( imgPath ) !== path . basename ( imagePath ) ) {
68
- isExistFile = true
70
+ if ( fs . existsSync ( imgPath ) ) {
71
+ isExistFile = true
72
+ }
69
73
}
70
74
resolve ( {
71
75
imgPath,
72
76
isExistFile
73
77
} )
74
78
} )
75
- execution . stderr . on ( 'data' , ( err : any ) => {
76
- reject ( err )
77
- } )
78
79
} )
79
80
}
80
81
0 commit comments