electron launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

4 years ago
  1. // All of the Node.js APIs are available in the preload process.
  2. // It has the same sandbox as a Chrome extension.
  3. const {ipcRenderer} = require('electron')
  4. window.api = [
  5. "showSuspensionWindow",
  6. "resizeWindow",
  7. "setUnReadMessage",
  8. "getUnReadMessage",
  9. "windowMoveHandle",
  10. "exitSystem",
  11. "openDevTools",
  12. "hideMainWindow",
  13. "showMainWindow",
  14. "minimize",
  15. "hideSuspensionWindow"
  16. ].reduce((acc, apiName) => {
  17. acc[apiName] = (...params) => {
  18. return ipcRenderer.send(apiName, ...params)
  19. }
  20. return acc
  21. }, {
  22. on: ipcRenderer.on.bind(ipcRenderer),
  23. removeListener: ipcRenderer.removeListener.bind(ipcRenderer)
  24. });
  25. ipcRenderer.on('getUnReadMessage', (e, args) => {
  26. window.getUnReadMessage(args[0]);
  27. });
  28. window.addEventListener("keydown", e => {
  29. const {altKey, ctrlKey, keyCode} = e;
  30. if (altKey && ctrlKey && keyCode === 70) {
  31. const currentWindow = require('electron').remote.getCurrentWindow();
  32. currentWindow && currentWindow.toggleDevTools();
  33. e.preventDefault();
  34. }
  35. })