event.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const {ipcMain} = require('electron');
  2. const path = require('path');
  3. const dialog = require('./function/dialog');
  4. const file = require('../../helper/file');
  5. ipcMain.on('load-file-data', (event, arg) => {
  6. const data = {};
  7. const filepath = path.join(__dirname, '../data/');
  8. // Scan data folder
  9. const dataFiles = file.list(filepath);
  10. // Read all scanned files
  11. for (const elt of dataFiles) {
  12. const fileContent = file.read(filepath + elt);
  13. data[elt.replace('.json', '')] = JSON.parse(fileContent);
  14. }
  15. // Send data
  16. event.sender.send('file-data-loaded', data);
  17. });
  18. ipcMain.on('refresh-card', (event, arg) => {
  19. mainWindow.webContents.send('refresh-card');
  20. });
  21. ipcMain.on('confirm-delete', (event, arg) => {
  22. dialog.message(
  23. 'Confirmation',
  24. `Voulez vous vraiment supprimer la note ${arg}`,
  25. 'question',
  26. ['Non', 'Oui'],
  27. 0,
  28. false,
  29. (index, btn) => {
  30. event.sender.send('delete-card', index === 1);
  31. }
  32. );
  33. });
  34. ipcMain.on('card-already-exist', (event, arg) => {
  35. dialog.error('Note éxistante', `Une note avec l'id ${arg} existe déjà, pour importer votre note veuillez d'abord la supprimer`);
  36. });