notif.js 902 B

1234567891011121314151617181920212223242526272829303132
  1. const {ipcMain} = require('electron');
  2. const path = require('path');
  3. const window = require('../../../helper/window');
  4. const notif = {};
  5. let hiddenWindow = null;
  6. notif.create = function (title, content) {
  7. // If a notification is already displayed
  8. if (hiddenWindow) {
  9. return;
  10. }
  11. // Notification data
  12. const data = {
  13. title: title,
  14. body: content,
  15. icon: path.join(__dirname, '../asset/icon.png')
  16. }
  17. // Wait close information
  18. ipcMain.once('notif-close', (event, arg) => {
  19. hiddenWindow.close();
  20. hiddenWindow = null;
  21. })
  22. // Create new invisible window to show notif
  23. hiddenWindow = window.hidden(path.join(__dirname, '../../renderer/page/notif/notif.html'));
  24. // Send information
  25. hiddenWindow.on('ready-to-show', () => {
  26. hiddenWindow.webContents.send('new-notif', data);
  27. });
  28. }
  29. module.exports = notif;