2017-10-22 13:16:52 -08:00
|
|
|
import {clipboard} from 'electron';
|
2023-07-25 09:30:19 -08:00
|
|
|
|
2019-01-06 05:55:16 -09:00
|
|
|
import plist from 'plist';
|
2017-10-22 13:16:52 -08:00
|
|
|
|
2019-10-12 02:16:45 -08:00
|
|
|
const getPath = (platform: string) => {
|
2017-10-22 13:16:52 -08:00
|
|
|
switch (platform) {
|
|
|
|
|
case 'darwin': {
|
2019-01-06 05:55:16 -09:00
|
|
|
if (clipboard.has('NSFilenamesPboardType')) {
|
|
|
|
|
// Parse plist file containing the path list of copied files
|
2019-10-12 02:16:45 -08:00
|
|
|
const list = plist.parse(clipboard.read('NSFilenamesPboardType')) as plist.PlistArray;
|
2019-01-06 05:55:16 -09:00
|
|
|
return "'" + list.join("' '") + "'";
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2017-10-22 13:16:52 -08:00
|
|
|
}
|
|
|
|
|
case 'win32': {
|
|
|
|
|
const filepath = clipboard.read('FileNameW');
|
|
|
|
|
return filepath.replace(new RegExp(String.fromCharCode(0), 'g'), '');
|
|
|
|
|
}
|
2017-11-04 14:19:02 -08:00
|
|
|
// Linux already pastes full path
|
2017-10-22 13:16:52 -08:00
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function processClipboard() {
|
|
|
|
|
return getPath(process.platform);
|
|
|
|
|
}
|