Server.js 470 B

123456789101112131415161718192021222324
  1. /**
  2. * @author oldj
  3. * @blog https://oldj.net
  4. */
  5. 'use strict'
  6. const {ipcMain} = require('electron')
  7. const actions = require('./actions')
  8. ipcMain.on('x', (e, d) => {
  9. let sender = e.sender
  10. let action = d.action
  11. if (typeof actions[action] === 'function') {
  12. actions[action](...(d.args || []))
  13. .then(v => {
  14. sender.send(d.callback, [null, v])
  15. })
  16. .catch(e => {
  17. console.log(e)
  18. sender.send(d.callback, [e])
  19. })
  20. }
  21. })