dragdrop.js 619 B

1234567891011121314151617
  1. const { ipcMain } = require('electron');
  2. const path = require('path');
  3. const file = require('../../helper/file');
  4. ipcMain.on('ondragstart', (event, data) => {
  5. const ext = exportToMd ? 'md' : 'json';
  6. const filepath = `./data/dragdrop/${data.id}/${data.title}.${ext}`;
  7. const content = exportToMd ? data.content : JSON.stringify(data, undefined, 4);
  8. // Create file
  9. file.makedir(filepath, true);
  10. file.put(filepath, content);
  11. // Send drag event
  12. event.sender.startDrag({
  13. file: path.join(__dirname, '../.' + filepath),
  14. icon: path.join(__dirname, '/asset/file.png')
  15. });
  16. });