marktext/src/renderer/util/clipboard.js
Felix Häusler bdaca98876
Update Electron to v15 (#2772)
* Prepare Electron >=14 upgrade

* Replace spectron with playwright

* Upgrade Electron to v15

* Fix unit test issue with @electron/remote

* Use per day cache directory for E2E tests

* Fix code style
2021-12-18 21:52:24 +08:00

27 lines
842 B
JavaScript

import { isLinux, isOsx, isWindows } from './index'
import plist from 'plist'
import { clipboard as remoteClipboard } from '@electron/remote'
const hasClipboardFiles = () => {
return remoteClipboard.has('NSFilenamesPboardType')
}
const getClipboardFiles = () => {
if (!hasClipboardFiles()) { return [] }
return plist.parse(remoteClipboard.read('NSFilenamesPboardType'))
}
export const guessClipboardFilePath = () => {
if (isLinux) return ''
if (isOsx) {
const result = getClipboardFiles()
return Array.isArray(result) && result.length ? result[0] : ''
} else if (isWindows) {
const rawFilePath = remoteClipboard.read('FileNameW')
const filePath = rawFilePath.replace(new RegExp(String.fromCharCode(0), 'g'), '')
return filePath && typeof filePath === 'string' ? filePath : ''
} else {
return ''
}
}