tray.js 846 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const electron = require('electron');
  2. const path = require('path');
  3. const app = electron.app;
  4. let tray = null;
  5. exports.create = function(mainWindow) {
  6. if (process.platform === 'darwin' || tray) {
  7. return;
  8. }
  9. const iconPath = path.join(__dirname, '/public/images/preserver_small.png');
  10. const toggleWin = function(){
  11. if (mainWindow.isVisible()) {
  12. mainWindow.hide();
  13. } else {
  14. mainWindow.show();
  15. }
  16. };
  17. const contextMenu = electron.Menu.buildFromTemplate([
  18. {
  19. label: 'Restore Preserver',
  20. click() {
  21. toggleWin();
  22. }
  23. },
  24. {
  25. type: 'separator'
  26. },
  27. {
  28. label: 'Quit',
  29. click() {
  30. app.quit();
  31. }
  32. }
  33. ]);
  34. tray = new electron.Tray(iconPath);
  35. tray.setToolTip('Preserver');
  36. tray.setContextMenu(contextMenu);
  37. tray.on('click', toggleWin);
  38. };