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 9a21a91 commit 8cd51aa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions py/LunaTranslator/translator/cdp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ def getpath(self, config):
class cdp_helper:
target_url = None

@property
def config(self):
return self.ref.config

@property
def using(self):
return True
return self.ref.using

def check_url_is_translator_url(self, url: str):
return url.startswith(self.target_url)
Expand Down Expand Up @@ -100,7 +104,7 @@ def wait_for_result(self, expression, badresult="", multi=False):

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

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

@property
def config(self):
return self.ref.config

@property
def using(self):
return self.ref.using

def injectjs(self):
with open(
os.path.join(os.path.dirname(__file__), self.jsfile),
Expand Down Expand Up @@ -304,7 +300,7 @@ def translate(self, content):
self.Runtime_evaluate(
"document.querySelector({}).click()".format(repr(self.button_selector))
)
if self.ref.config["usingstream"]:
if self.config["usingstream"]:
__ = [""]

def ___(__):
Expand Down
2 changes: 1 addition & 1 deletion py/LunaTranslator/translator/deepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class cdp_deepl(cdp_helper):

@property
def using(self):
return self.ref.using and self.ref.config["usewhich"] == 2
return self.ref.using and self.config["usewhich"] == 2

@property
def srclang(self):
Expand Down

0 comments on commit 8cd51aa

Please sign in to comment.