This commit is contained in:
恍兮惚兮 2024-12-04 20:57:20 +08:00
parent 6e8ef2bd0d
commit 9a21a91714
3 changed files with 14 additions and 22 deletions

View File

@ -1,6 +1,6 @@
from translator.basetranslator import basetrans from translator.basetranslator import basetrans
import json, requests, threading, hashlib import json, requests, threading, hashlib
from myutils.config import globalconfig, _TR from myutils.config import _TR
from myutils.wrapper import threader from myutils.wrapper import threader
from myutils.utils import checkportavailable from myutils.utils import checkportavailable
from myutils.subproc import subproc_w from myutils.subproc import subproc_w
@ -12,8 +12,8 @@ class Commonloadchromium:
self.task = queue.Queue() self.task = queue.Queue()
self.waittaskthread() self.waittaskthread()
def maybeload(self): def maybeload(self, config):
self.task.put(0) self.task.put(config)
@threader @threader
def waittaskthread(self): def waittaskthread(self):
@ -21,15 +21,15 @@ class Commonloadchromium:
self.__waittaskthread() self.__waittaskthread()
def __waittaskthread(self): def __waittaskthread(self):
_ = self.task.get() config = self.task.get()
if not self.task.empty(): if not self.task.empty():
return return
time.sleep(0.2) time.sleep(0.2)
if not self.task.empty(): if not self.task.empty():
return return
port = globalconfig["debugport"] port = config["debugport"]
_path = self.getpath() _path = self.getpath(config)
if not _path: if not _path:
print("No Chromium Found") print("No Chromium Found")
return return
@ -51,9 +51,9 @@ class Commonloadchromium:
call = fmt % (path, port, cache) call = fmt % (path, port, cache)
return call return call
def getpath(self): def getpath(self, config):
for syspath in [ for syspath in [
globalconfig["chromepath"], config["chromepath"],
r"C:\Program Files\Google\Chrome\Application\chrome.exe", r"C:\Program Files\Google\Chrome\Application\chrome.exe",
r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe", r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
]: ]:
@ -97,8 +97,10 @@ class cdp_helper:
time.sleep(0.1) 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._id = 1
self.sendrecvlock = threading.Lock() self.sendrecvlock = threading.Lock()
self._createtarget() self._createtarget()
@ -117,7 +119,7 @@ class cdp_helper:
) )
res = ws.recv() res = ws.recv()
except requests.RequestException: except requests.RequestException:
cdp_helper.commonloadchromium.maybeload() cdp_helper.commonloadchromium.maybeload(self.ref.config)
raise Exception(_TR("连接失败")) raise Exception(_TR("连接失败"))
res = json.loads(res) res = json.loads(res)
@ -130,7 +132,7 @@ class cdp_helper:
def _createtarget(self): def _createtarget(self):
if self.using == False: if self.using == False:
return return
port = globalconfig["debugport"] port = self.ref.config["debugport"]
url = self.target_url url = self.target_url
try: try:
infos = requests.get("http://127.0.0.1:{}/json/list".format(port)).json() infos = requests.get("http://127.0.0.1:{}/json/list".format(port)).json()
@ -255,10 +257,6 @@ class cdp_helperllm(cdp_helper):
function1 = ... function1 = ...
function2 = ... function2 = ...
def __init__(self, ref: basetrans) -> None:
self.ref = ref
super().__init__()
@property @property
def config(self): def config(self):
return self.ref.config return self.ref.config

View File

@ -58,10 +58,6 @@ def initDeepLXData(sourceLang: str, targetLang: str):
class cdp_deepl(cdp_helper): class cdp_deepl(cdp_helper):
target_url = "https://www.deepl.com/en/translator" target_url = "https://www.deepl.com/en/translator"
def __init__(self, ref: basetrans) -> None:
self.ref = ref
super().__init__()
@property @property
def using(self): def using(self):
return self.ref.using and self.ref.config["usewhich"] == 2 return self.ref.using and self.ref.config["usewhich"] == 2

View File

@ -877,8 +877,6 @@
"記号": "coral", "記号": "coral",
"空白": "white" "空白": "white"
}, },
"chromepath": "",
"debugport": 9222,
"cixingcolorshow": { "cixingcolorshow": {
"形容詞": true, "形容詞": true,
"形状詞": true, "形状詞": true,