1
0

minimal.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const { app, Tray, Menu, shell, nativeImage } = require('electron');
  2. const path = require('path')
  3. const Pinokiod = require("pinokiod")
  4. const config = require('./config')
  5. const pinokiod = new Pinokiod(config)
  6. let tray
  7. app.whenReady().then(async () => {
  8. await pinokiod.start({
  9. onquit: () => {
  10. app.quit()
  11. },
  12. onrestart: () => {
  13. app.relaunch();
  14. app.exit()
  15. },
  16. browser: {
  17. clearCache: async () => {
  18. console.log('clear cache', session.defaultSession)
  19. await session.defaultSession.clearStorageData()
  20. console.log("cleared")
  21. }
  22. }
  23. })
  24. if (process.platform === 'darwin') app.dock.hide();
  25. let icon = nativeImage.createFromPath(path.resolve(process.resourcesPath, "assets/icon_small.png"))
  26. icon = icon.resize({
  27. height: 24,
  28. width: 24
  29. });
  30. console.log('isEmpty:', icon.isEmpty()); // if true, image failed to load
  31. tray = new Tray(icon)
  32. const contextMenu = Menu.buildFromTemplate([
  33. { label: 'Open in Browser', click: () => shell.openExternal("http://localhost:42000") },
  34. { label: 'Restart', click: () => { app.relaunch(); app.exit(); } },
  35. { label: 'Quit', click: () => app.quit() }
  36. ]);
  37. tray.setToolTip('Pinokio');
  38. tray.setContextMenu(contextMenu);
  39. tray.on('click', () => {
  40. tray.popUpContextMenu(contextMenu);
  41. });
  42. shell.openExternal("http://localhost:42000");
  43. });