demo-application-menu.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const {ipcMain} = require('electron');
  2. const path = require('path');
  3. const tray = require('./tray');
  4. const notif = require('./notif');
  5. const dialog = require('./dialog');
  6. const window = require('../../../helper/window');
  7. const demoMenu = {};
  8. let hiddenWindow = null;
  9. demoMenu.primeNumberPopup = function () {
  10. };
  11. demoMenu.primeNumber = function () {
  12. // demand number to the user
  13. dialog.custom(path.join(__dirname, '../../renderer/page/dialog/dialog.html'), number => {
  14. //number = 409291;
  15. //number = 12000000003;
  16. // If no answer
  17. if (!number) {
  18. return;
  19. }
  20. // Only one calc at the same time
  21. if (hiddenWindow) {
  22. dialog.error('Un calcul est déjà en cours', 'Impossible de calculer plusieurs nombre premier en même temps');
  23. return;
  24. }
  25. // Wait prime number is calculated
  26. ipcMain.once('prime-number-result', (event, result) => {
  27. let message = `Le nombre ${number} ` + (result ? 'est premier' : 'n\'est pas premier');
  28. dialog.message('Résultat du test de primalité', message);
  29. hiddenWindow.close();
  30. hiddenWindow = null;
  31. });
  32. //Create hidden window to calc prime number
  33. hiddenWindow = window.hidden(path.join(__dirname, '../../renderer/page/prime-number/prime-number.html'));
  34. // Send number to test when window is ready
  35. hiddenWindow.on('ready-to-show', () => {
  36. hiddenWindow.webContents.send('calc-prime-number', number);
  37. });
  38. });
  39. };
  40. demoMenu.primeNumberResult = function () {
  41. };
  42. demoMenu.tray = function () {
  43. // Show notif
  44. notif.create('Application minimisé', 'Cliquer sur l\'icone dans la barre des notifications pour réouvrir l\'application');
  45. // Add tray
  46. tray.active();
  47. }
  48. module.exports = demoMenu;