Skip to content

Commit

Permalink
🐛 Fix(clipboard): clipboard image getter error in macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed May 12, 2019
1 parent 0da0e97 commit 8314604
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Binary file modified src/utils/clipboard/mac.applescript
Binary file not shown.
15 changes: 8 additions & 7 deletions src/utils/getClipboardImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import path from 'path'
import { spawn } from 'child_process'
import dayjs from 'dayjs'
import os from 'os'
import fs from 'fs-extra'
import { ClipboardImage } from '../utils/interfaces'

const getCurrentPlatform = (): string => {
let platform = process.platform
Expand All @@ -19,17 +21,17 @@ const getCurrentPlatform = (): string => {
}

// Thanks to vs-picgo: https://github.com/Spades-S/vs-picgo/blob/master/src/extension.ts
const getClipboardImage = (ctx: PicGo): Promise<any> => {
const getClipboardImage = (ctx: PicGo): Promise<ClipboardImage> => {
const imagePath = path.join(ctx.baseDir, `${dayjs().format('YYYYMMDDHHmmss')}.png`)
return new Promise((resolve: any, reject: any): any => {
return new Promise<ClipboardImage>((resolve: Function): void => {
let platform: string = getCurrentPlatform()
let execution = null
// for PicGo GUI
let env = ctx.config.PICGO_ENV === 'GUI'
const platformPaths: {
[index: string]: string
} = {
'darwin': env ? path.join(ctx.baseDir,'./mac.applescript') : './clipboard/mac.applescript',
'darwin': env ? path.join(ctx.baseDir,'mac.applescript') : './clipboard/mac.applescript',
'win32': env ? path.join(ctx.baseDir, 'windows.ps1') : './clipboard/windows.ps1',
'win10': env ? path.join(ctx.baseDir, 'windows10.ps1') : './clipboard/windows10.ps1',
'linux': env ? path.join(ctx.baseDir, 'linux.sh') : './clipboard/linux.sh'
Expand Down Expand Up @@ -65,16 +67,15 @@ const getClipboardImage = (ctx: PicGo): Promise<any> => {
let isExistFile = false
// in macOS if your copy the file in system, it's basename will not equal to our default basename
if (path.basename(imgPath) !== path.basename(imagePath)) {
isExistFile = true
if (fs.existsSync(imgPath)) {
isExistFile = true
}
}
resolve({
imgPath,
isExistFile
})
})
execution.stderr.on('data', (err: any) => {
reject(err)
})
})
}

Expand Down

0 comments on commit 8314604

Please sign in to comment.