hyper/lib/utils/paste.ts

29 lines
774 B
TypeScript
Raw Normal View History

import {clipboard} from 'electron';
2023-07-25 09:30:19 -08:00
2019-01-06 05:55:16 -09:00
import plist from 'plist';
2019-10-12 02:16:45 -08:00
const getPath = (platform: string) => {
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;
}
}
case 'win32': {
const filepath = clipboard.read('FileNameW');
return filepath.replace(new RegExp(String.fromCharCode(0), 'g'), '');
}
// Linux already pastes full path
default:
return null;
}
};
export default function processClipboard() {
return getPath(process.platform);
}