From cfcab91df54dcbfb8afff42c5a6328f82e5b584d Mon Sep 17 00:00:00 2001 From: lyw Date: Tue, 20 Apr 2021 14:52:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9C=E7=A8=8BIPC=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=BC=82=E6=AD=A5=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/api.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/electron/api.js b/electron/api.js index 2664b23..559755c 100755 --- a/electron/api.js +++ b/electron/api.js @@ -61,17 +61,27 @@ exports.setup = async function () { socket.on('ipc', (message, callback) => { ELog.info('[ api ] [setup] socket id:' + socket.id + ' message cmd: ' + message.cmd); const data = apis[message.cmd](...message.params); - const result = { - err: null, - data: data, - }; - callback(result); + if (data && typeof data.then === 'function') { // 判断是否是异步 + data.then((data) => { + const result = { + err: null, + data: data, + }; + callback(result) + }); + } else { + const result = { + err: null, + data: data, + }; + callback(result); + } }); }); server.listen(port, listen, function() { ELog.info('[ api ] [setup] server is listening on', `${listen}:${port}`); - }); + }); }; function setApi() { @@ -88,7 +98,7 @@ function setApi() { }); } }); -}; +} /** * get api method name @@ -99,4 +109,4 @@ function setApi() { function getApiName (jsname, method) { return jsname + '.' + method; //return jsname + method.charAt(0).toUpperCase() + method.slice(1); -}; +}