diff --git a/appcast.json b/appcast.json index c12fb27..1fcb595 100644 --- a/appcast.json +++ b/appcast.json @@ -2,10 +2,10 @@ "identifier": "me.vacuity.chat.gptranslate", "versions": [ { - "version": "1.2.0", - "desc": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/tag/1.2.0", - "sha256": "d6c7b0ed99922910b5f06b6ed8d5c1d94b4b2dbc027e48f91fa5c9131e54cba5", - "url": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/download/1.2.0/bob-plugin-vac-gptranslate.bobplugin", + "version": "1.3.0", + "desc": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/tag/1.3.0", + "sha256": "4cc790362cb9b13cca8ce50100ad4bb4c5cddc3ed914fa72d428ea5161ae7a58", + "url": "https://github.com/vacuityv/bob-plugin-vac-gptranslate/releases/download/1.3.0/bob-plugin-vac-gptranslate.bobplugin", "minBobVersion": "0.5.0" } ] diff --git a/info.json b/info.json index 4e5512e..2328506 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "identifier": "me.vacuity.chat.gptranslate", - "version": "1.2.0", + "version": "1.3.0", "category": "translate", "name": "GPTranslate", "summary": "调用chatgpt/gemini/claude实现翻译功能", diff --git a/main.js b/main.js index 0f0e7ce..8adc676 100644 --- a/main.js +++ b/main.js @@ -106,19 +106,18 @@ function oldTranslate(query, completion) { } - var websocket = null; var count = 0; var timerId = 0; var signal = $signal.new() -function initWebsocket() { +function initWebsocket(msg) { vacUrl = usaWss; if (websocket == null) { - $log.info(`initWebsocket`+ vacUrl); + $log.info(`initWebsocket` + vacUrl); websocket = $websocket.new({ url: vacUrl, allowSelfSignedSSLCertificates: true, @@ -131,6 +130,7 @@ function initWebsocket() { websocket.open(); websocket.listenOpen(function (socket) { $log.info(`did open`); + websocket.sendString(msg); websocket.listenError(function (socket, error) { $log.info(`did error: code=${error.code}; message=${error.message}; type=${error.type}`); @@ -151,27 +151,6 @@ function initWebsocket() { }) count = 0; - - if (timerId != 0) { - $timer.invalidate(timerId); - } - - timerId = $timer.schedule({ - interval: 10, - repeats: true, - handler: function () { - websocket.ping() - count += 1; - $log.info(`count=${count}`) - // 空闲 1h 后关闭 - if (count > 60 * 6) { - $timer.invalidate(timerId); - if (websocket != null) { - websocket.close(); - } - } - } - }); } } @@ -180,23 +159,24 @@ function sendSocketMsg(msg) { count = 0; if (websocket == null || websocket.readyState == 2 || websocket.readyState == 3) { websocket = null; - initWebsocket(); - } - if (websocket.readyState == 1) { - $log.info('readyState == 1' + msg) - websocket.sendString(msg); + initWebsocket(msg); } else { - var stateTimerId = $timer.schedule({ - interval: 1, - repeats: true, - handler: function () { - $log.info(`checkready...state=${websocket.readyState}`) - if (websocket.readyState == 1) { - $timer.invalidate(stateTimerId); - websocket.sendString(msg); + if (websocket.readyState == 1) { + $log.info('readyState == 1' + msg) + websocket.sendString(msg); + } else { + var stateTimerId = $timer.schedule({ + interval: 1, + repeats: true, + handler: function () { + $log.info(`checkready...state=${websocket.readyState}`) + if (websocket.readyState == 1) { + $timer.invalidate(stateTimerId); + websocket.sendString(msg); + } } - } - }); + }); + } } }