Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Dec 4, 2024
1 parent 6e8ef2b commit 9a21a91
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
30 changes: 14 additions & 16 deletions py/LunaTranslator/translator/cdp_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from translator.basetranslator import basetrans
import json, requests, threading, hashlib
from myutils.config import globalconfig, _TR
from myutils.config import _TR
from myutils.wrapper import threader
from myutils.utils import checkportavailable
from myutils.subproc import subproc_w
Expand All @@ -12,24 +12,24 @@ def __init__(self) -> None:
self.task = queue.Queue()
self.waittaskthread()

def maybeload(self):
self.task.put(0)
def maybeload(self, config):
self.task.put(config)

@threader
def waittaskthread(self):
while True:
self.__waittaskthread()

def __waittaskthread(self):
_ = self.task.get()
config = self.task.get()
if not self.task.empty():
return
time.sleep(0.2)
if not self.task.empty():
return

port = globalconfig["debugport"]
_path = self.getpath()
port = config["debugport"]
_path = self.getpath(config)
if not _path:
print("No Chromium Found")
return
Expand All @@ -51,9 +51,9 @@ def gencmd(self, path, port):
call = fmt % (path, port, cache)
return call

def getpath(self):
def getpath(self, config):
for syspath in [
globalconfig["chromepath"],
config["chromepath"],
r"C:\Program Files\Google\Chrome\Application\chrome.exe",
r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
]:
Expand Down Expand Up @@ -97,8 +97,10 @@ def wait_for_result(self, expression, badresult="", multi=False):
time.sleep(0.1)

#########################################
def __init__(self):
cdp_helper.commonloadchromium.maybeload()

def __init__(self, ref: basetrans) -> None:
self.ref = ref
cdp_helper.commonloadchromium.maybeload(self.ref.config)
self._id = 1
self.sendrecvlock = threading.Lock()
self._createtarget()
Expand All @@ -117,7 +119,7 @@ def _SendRequest(self, method, params, ws=None):
)
res = ws.recv()
except requests.RequestException:
cdp_helper.commonloadchromium.maybeload()
cdp_helper.commonloadchromium.maybeload(self.ref.config)
raise Exception(_TR("连接失败"))

res = json.loads(res)
Expand All @@ -130,7 +132,7 @@ def _SendRequest(self, method, params, ws=None):
def _createtarget(self):
if self.using == False:
return
port = globalconfig["debugport"]
port = self.ref.config["debugport"]
url = self.target_url
try:
infos = requests.get("http://127.0.0.1:{}/json/list".format(port)).json()
Expand Down Expand Up @@ -255,10 +257,6 @@ class cdp_helperllm(cdp_helper):
function1 = ...
function2 = ...

def __init__(self, ref: basetrans) -> None:
self.ref = ref
super().__init__()

@property
def config(self):
return self.ref.config
Expand Down
4 changes: 0 additions & 4 deletions py/LunaTranslator/translator/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ def initDeepLXData(sourceLang: str, targetLang: str):
class cdp_deepl(cdp_helper):
target_url = "https://www.deepl.com/en/translator"

def __init__(self, ref: basetrans) -> None:
self.ref = ref
super().__init__()

@property
def using(self):
return self.ref.using and self.ref.config["usewhich"] == 2
Expand Down
2 changes: 0 additions & 2 deletions py/files/defaultconfig/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,6 @@
"記号": "coral",
"空白": "white"
},
"chromepath": "",
"debugport": 9222,
"cixingcolorshow": {
"形容詞": true,
"形状詞": true,
Expand Down

0 comments on commit 9a21a91

Please sign in to comment.