🐛 Fix: macos clipboard image can't show on tray page

ISSUES CLOSED: #961
This commit is contained in:
PiEgg
2022-08-25 20:04:50 +08:00
parent b6b2eeae6b
commit 20e38f4eb9
4 changed files with 48 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
import fs from 'fs-extra'
import db from '~/main/apis/core/datastore'
import { clipboard, Notification, dialog } from 'electron'
@@ -69,3 +70,19 @@ export const calcDurationRange = (duration: number) => {
// max range
return 100000
}
/**
* macOS public.file-url will get encoded file path,
* so we need to decode it
*/
export const ensureFilePath = (filePath: string, prefix = 'file://'): string => {
filePath = filePath.replace(prefix, '')
if (fs.existsSync(filePath)) {
return `${prefix}${filePath}`
}
filePath = decodeURIComponent(filePath)
if (fs.existsSync(filePath)) {
return `${prefix}${filePath}`
}
return ''
}