This repository was archived by the owner on Jun 15, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathipc-promise.min.js
6 lines (6 loc) · 1.49 KB
/
ipc-promise.min.js
1
2
3
4
5
6
/*!
* @license ipc-promise Copyright(c) 2015 sasa+1
* https://github.com/sasaplus1/ipc-promise
* Released under the MIT license.
*/
!function(e,n){"use strict";"function"==typeof define&&define.amd?define(["electron","events"],n):"object"==typeof exports?module.exports=n(require("electron"),require("events")):e.ipcPromise=n(global.require("electron"),global.require("events"))}((this||0).self||global,function(e,n){"use strict";function t(e,n){return e+n.toString()+s}function i(e,n){return e+n.toString()+u}function r(e,n){var r=t(n.eventName,n.id),o=i(n.eventName,n.id),a=function(t){e.sender.send(f,{data:t,eventName:n.eventName,id:n.id}),l.removeListener(r,a),l.removeListener(o,d)},d=function(t){e.sender.send(v,{data:t,eventName:n.eventName,id:n.id}),l.removeListener(r,a),l.removeListener(o,d)};l.on(r,a),l.on(o,d),l.emit(n.eventName,n.id,n.data,e)}function o(e,n){return new Promise(function(t,i){var r=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),o=function(n,i){i.id===r&&i.eventName===e&&(c.removeListener(f,o),c.removeListener(v,a),t(i.data))},a=function(n,t){t.id===r&&t.eventName===e&&(c.removeListener(f,o),c.removeListener(v,a),i(t.data))};c.on(f,o),c.on(v,a),c.send(m,{data:n,eventName:e,id:r})})}function a(e,n){l.on(e,function(r,o,a){n(o,a).then(function(n){l.emit(t(e,r),n)}).catch(function(n){l.emit(i(e,r),n)})})}var d=e.ipcMain,c=e.ipcRenderer,m="ipc-promise-common-event",s="-success",u="-failure",f=m+s,v=m+u,l=new n.EventEmitter;return"undefined"==typeof window&&d.on(m,r),{on:a,send:o}});