From ef82fb3d0490c6fa4f443d3cf501b73194821a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Thu, 8 Aug 2024 19:47:06 +0800 Subject: [PATCH] fix --- .../LunaTranslator/LunaTranslator.py | 83 +++++++++++-------- .../LunaTranslator/LunaTranslator_main.py | 23 +++++ .../LunaTranslator/gui/setting_about.py | 10 ++- .../gui/setting_display_text.py | 3 +- .../LunaTranslator/gui/translatorUI.py | 52 +++++++----- .../LunaTranslator/ocrengines/local.py | 9 +- .../scalemethod/magpie_builtin.py | 22 ++--- .../LunaTranslator/translator/claude.py | 2 + LunaTranslator/LunaTranslator/windows.py | 4 +- .../LunaTranslator/winsharedutils.py | 11 +-- LunaTranslator/files/lang/ar.json | 4 +- LunaTranslator/files/lang/cht.json | 4 +- LunaTranslator/files/lang/cs.json | 4 +- LunaTranslator/files/lang/de.json | 4 +- LunaTranslator/files/lang/en.json | 4 +- LunaTranslator/files/lang/es.json | 4 +- LunaTranslator/files/lang/fr.json | 4 +- LunaTranslator/files/lang/it.json | 4 +- LunaTranslator/files/lang/ja.json | 4 +- LunaTranslator/files/lang/ko.json | 4 +- LunaTranslator/files/lang/nl.json | 4 +- LunaTranslator/files/lang/pl.json | 4 +- LunaTranslator/files/lang/pt.json | 4 +- LunaTranslator/files/lang/ru.json | 4 +- LunaTranslator/files/lang/sv.json | 4 +- LunaTranslator/files/lang/th.json | 4 +- LunaTranslator/files/lang/tr.json | 4 +- LunaTranslator/files/lang/uk.json | 4 +- LunaTranslator/files/lang/vi.json | 4 +- LunaTranslator/files/lang/zh.json | 4 +- plugins/CMakeLists.txt | 2 +- plugins/winsharedutils/CMakeLists.txt | 2 +- plugins/winsharedutils/darklistener.cpp | 42 ---------- plugins/winsharedutils/define.h | 1 - .../winsharedutils/globalmessagelistener.cpp | 63 ++++++++++++++ plugins/winsharedutils/maglistener.cpp | 61 -------------- 36 files changed, 255 insertions(+), 215 deletions(-) delete mode 100644 plugins/winsharedutils/darklistener.cpp create mode 100644 plugins/winsharedutils/globalmessagelistener.cpp delete mode 100644 plugins/winsharedutils/maglistener.cpp diff --git a/LunaTranslator/LunaTranslator/LunaTranslator.py b/LunaTranslator/LunaTranslator/LunaTranslator.py index dc7be4b4..4dbcfe06 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator.py @@ -1,5 +1,5 @@ import time, uuid -import os, threading, sys, re, codecs +import os, threading, re, codecs, winreg from qtsymbols import * from traceback import print_exc from myutils.config import ( @@ -10,10 +10,10 @@ from myutils.config import ( findgameuidofpath, savehook_new_data, static_data, - tryreadconfig, getlanguse, set_font_default, ) +from ctypes import c_int, CFUNCTYPE, c_void_p import sqlite3 from myutils.utils import ( minmaxmoveobservefunc, @@ -26,7 +26,7 @@ from myutils.utils import ( targetmod, translate_exits, ) -from myutils.wrapper import threader +from myutils.wrapper import threader, tryprint from gui.showword import searchwordW from myutils.hwnd import getpidexe, ListProcess, getExeIcon, getcurrexe from textsource.copyboard import copyboard @@ -1106,40 +1106,34 @@ class MAINUI: ) def inittray(self): - + self.tray = QSystemTrayIcon() + self.tray.setIcon(getExeIcon(getcurrexe())) trayMenu = LMenu(self.commonstylebase) - showAction = LAction( - ("&显示"), - trayMenu, - triggered=self.translation_ui.show_, - ) - settingAction = LAction( - qtawesome.icon("fa.gear"), - ("&设置"), - trayMenu, - triggered=lambda: self.settin_ui.showsignal.emit(), - ) - quitAction = LAction( - qtawesome.icon("fa.times"), - ("&退出"), - trayMenu, - triggered=self.translation_ui.close, - ) + showAction = LAction("&显示", trayMenu) + showAction.triggered.connect(self.translation_ui.show_) + settingAction = LAction(qtawesome.icon("fa.gear"), "&设置", trayMenu) + settingAction.triggered.connect(self.settin_ui.showsignal) + quitAction = LAction(qtawesome.icon("fa.times"), "&退出", trayMenu) + quitAction.triggered.connect(self.translation_ui.close) + trayMenu.addAction(showAction) + trayMenu.addAction(settingAction) + trayMenu.addSeparator() + trayMenu.addAction(quitAction) trayMenu.addAction(showAction) trayMenu.addAction(settingAction) trayMenu.addSeparator() trayMenu.addAction(quitAction) - self.tray = QSystemTrayIcon() - - icon = getExeIcon(getcurrexe()) #'./LunaTranslator.exe')# QIcon() - self.tray.setIcon(icon) - - self.tray.activated.connect(self.translation_ui.leftclicktray) - self.tray.show() self.tray.setContextMenu(trayMenu) + self.tray.activated.connect(self.leftclicktray) + self.tray.messageClicked.connect(winsharedutils.dispatchcloseevent) + self.tray.show() + + def leftclicktray(self, reason): + if reason == QSystemTrayIcon.ActivationReason.Trigger: + self.translation_ui.showhideui() def showtraymessage(self, title, message): - self.tray.showMessage(_TR(title), _TR(message), QSystemTrayIcon.MessageIcon()) + self.tray.showMessage(_TR(title), _TR(message), getExeIcon(getcurrexe())) def destroytray(self): self.tray.hide() @@ -1234,7 +1228,8 @@ class MAINUI: target=minmaxmoveobservefunc, args=(self.translation_ui,) ).start() threading.Thread(target=self.checkgameplayingthread).start() - threading.Thread(target=self.darklistener).start() + self.messagecallback__ = CFUNCTYPE(None, c_int, c_void_p)(self.messagecallback) + winsharedutils.globalmessagelistener(self.messagecallback__) self.inittray() self.createsavegamedb() @@ -1244,14 +1239,15 @@ class MAINUI: return return os.startfile(file) - def darklistener(self): - sema = winsharedutils.startdarklistener() - while True: - # 会触发两次 - windows.WaitForSingleObject(sema, windows.INFINITE) + def messagecallback(self, msg, param): + if msg == 0: if globalconfig["darklight2"] == 0: self.commonstylebase.setstylesheetsignal.emit() - windows.WaitForSingleObject(sema, windows.INFINITE) + elif msg == 1: + if bool(param): + windows.BringWindowToTop(int(self.translation_ui.winid)) + elif msg == 2: + self.translation_ui.closesignal.emit() def installeventfillter(self): class WindowEventFilter(QObject): @@ -1284,3 +1280,18 @@ class MAINUI: targetmod[k] = importlib.import_module(f"metadata.{k}").searcher(k) except: print_exc() + + @tryprint + def urlprotocol(self): + + key = winreg.CreateKey( + winreg.HKEY_CURRENT_USER, r"Software\Classes\lunatranslator" + ) + winreg.SetValue(key, None, winreg.REG_SZ, "URL:lunatranslator") + winreg.SetValueEx(key, r"URL Protocol", 0, winreg.REG_SZ, "") + keysub = winreg.CreateKey( + winreg.HKEY_CURRENT_USER, + r"Software\Classes\lunatranslator\shell\open\command", + ) + command = f'"{getcurrexe()}" --URLProtocol "%1"' + winreg.SetValue(keysub, r"", winreg.REG_SZ, command) diff --git a/LunaTranslator/LunaTranslator/LunaTranslator_main.py b/LunaTranslator/LunaTranslator/LunaTranslator_main.py index 280e988c..803ba152 100644 --- a/LunaTranslator/LunaTranslator/LunaTranslator_main.py +++ b/LunaTranslator/LunaTranslator/LunaTranslator_main.py @@ -45,6 +45,7 @@ def loadmainui(): gobject.baseobject = MAINUI() gobject.baseobject.loadui() + # gobject.baseobject.urlprotocol() def checklang(): @@ -211,6 +212,27 @@ def savelogs(): sys.stdout = debugoutput(sys.stdout) +def urlprotocol(): + import argparse + from urllib.parse import urlsplit + from traceback import print_exc + + parser = argparse.ArgumentParser() + parser.add_argument("--URLProtocol", required=False) + args = parser.parse_args() + URLProtocol: str = args.URLProtocol + try: + if URLProtocol: + print(URLProtocol) + result = urlsplit(URLProtocol) + netloc = result.netloc.lower() + if netloc == "oauthtoken": + token = result.path[1:] + + except: + print() + + if __name__ == "__main__": switchdir() prepareqtenv() @@ -222,5 +244,6 @@ if __name__ == "__main__": checkintegrity() checkpermission() savelogs() + # urlprotocol() loadmainui() app.exit(app.exec()) diff --git a/LunaTranslator/LunaTranslator/gui/setting_about.py b/LunaTranslator/LunaTranslator/gui/setting_about.py index 32c20f0d..ca3b40be 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_about.py +++ b/LunaTranslator/LunaTranslator/gui/setting_about.py @@ -1,5 +1,5 @@ from qtsymbols import * -import platform, functools, sys +import platform, functools import winsharedutils, queue from myutils.config import globalconfig, static_data, _TR from myutils.wrapper import threader, tryprint @@ -8,7 +8,6 @@ from myutils.utils import makehtml, getlanguse, dynamiclink import requests import shutil, gobject from myutils.proxy import getproxy -from traceback import print_exc import zipfile, os import subprocess from gui.usefulwidget import D_getsimpleswitch, makescrollgrid, makesubtab_lazy @@ -148,7 +147,7 @@ def versioncheckthread(self): while True: x = versionchecktask.get() gobject.baseobject.update_avalable = False - self.progresssignal.emit("……", 0) + self.progresssignal.emit("", 0) if not x: continue self.versiontextsignal.emit("获取中") # ,'',url,url)) @@ -167,6 +166,7 @@ def versioncheckthread(self): ) if not (need and globalconfig["autoupdate"]): continue + self.progresssignal.emit("……", 0) savep = updatemethod(_version[1], self) if not savep: self.progresssignal.emit(_TR("自动更新失败,请手动更新"), 0) @@ -175,7 +175,9 @@ def versioncheckthread(self): uncompress(self, savep) gobject.baseobject.update_avalable = True self.progresssignal.emit(_TR("准备完毕,等待更新"), 10000) - gobject.baseobject.showtraymessage(sversion, "准备完毕,等待更新") + gobject.baseobject.showtraymessage( + sversion, "准备完毕,等待更新_\n_点击消息后退出并开始更新" + ) def updateprogress(self, text, val): diff --git a/LunaTranslator/LunaTranslator/gui/setting_display_text.py b/LunaTranslator/LunaTranslator/gui/setting_display_text.py index 27905c9e..1b6c206b 100644 --- a/LunaTranslator/LunaTranslator/gui/setting_display_text.py +++ b/LunaTranslator/LunaTranslator/gui/setting_display_text.py @@ -167,8 +167,7 @@ def doinstallqweb(self, dd, base): zipf.extractall(target) bit = ["x86", "x64"][platform.architecture()[0] == "64bit"] copytree(f"{target}/{bit}/PyQt5", "LunaTranslator/runtime/PyQt5") - - gobject.baseobject.showtraymessage("", "安装成功") + getQMessageBox(self, "成功", "安装成功") def installqwebdialog(self, link): diff --git a/LunaTranslator/LunaTranslator/gui/translatorUI.py b/LunaTranslator/LunaTranslator/gui/translatorUI.py index cdd985e2..3edc7065 100644 --- a/LunaTranslator/LunaTranslator/gui/translatorUI.py +++ b/LunaTranslator/LunaTranslator/gui/translatorUI.py @@ -1,5 +1,5 @@ from qtsymbols import * -import time, functools, threading, os, sys, importlib, shutil, uuid +import time, functools, threading, os, importlib, shutil, uuid from traceback import print_exc import windows, qtawesome, gobject, winsharedutils from myutils.wrapper import threader, trypass @@ -18,7 +18,13 @@ from myutils.utils import ( makehtml, loadpostsettingwindowmethod_maybe, ) -from myutils.hwnd import mouseselectwindow, grabwindow, getExeIcon, getpidexe, getcurrexe +from myutils.hwnd import ( + mouseselectwindow, + grabwindow, + getExeIcon, + getpidexe, + getcurrexe, +) from gui.setting_about import doupdate from gui.dialog_memory import dialog_memory from gui.textbrowser import Textbrowser @@ -236,6 +242,7 @@ class QUnFrameWindow(resizableframeless): ocr_once_signal = pyqtSignal() resizesignal = pyqtSignal(QSize) move_signal = pyqtSignal(QPoint) + closesignal = pyqtSignal() @threader def tracewindowposthread(self): @@ -436,11 +443,6 @@ class QUnFrameWindow(resizableframeless): else: self.hide_() - def leftclicktray(self, reason): - # 鼠标左键点击 - if reason == QSystemTrayIcon.Trigger: - self.showhideui() - def refreshtoolicon(self): self.titlebar.setFixedHeight(int(globalconfig["buttonsize"] * 1.5)) self.titlebar.adjustminwidth() @@ -837,6 +839,7 @@ class QUnFrameWindow(resizableframeless): self.toolbarhidedelaysignal.connect(self.toolbarhidedelay) self.resizesignal.connect(self.resize) self.move_signal.connect(self.move) + self.closesignal.connect(self.close) def __init__(self): @@ -1226,19 +1229,28 @@ class QUnFrameWindow(resizableframeless): pass def closeEvent(self, a0) -> None: - if self.fullscreenmanager: - self.fullscreenmanager.endX() - gobject.baseobject.isrunning = False - self.hide() + try: + if self.fullscreenmanager: + self.fullscreenmanager.endX() + gobject.baseobject.isrunning = False + self.hide() - if gobject.baseobject.textsource: + if gobject.baseobject.textsource: - gobject.baseobject.textsource = None + gobject.baseobject.textsource = None + endsubprocs() + try: + saveallconfig() + self.tryremoveuseless() + except: + print_exc() + gobject.baseobject.destroytray() + handle = windows.CreateMutex(False, "LUNASAVECONFIG") + if windows.GetLastError() != windows.ERROR_ALREADY_EXISTS: + doupdate() + else: + windows.CloseHandle(handle) + os._exit(0) - saveallconfig() - - endsubprocs() - self.tryremoveuseless() - gobject.baseobject.destroytray() - doupdate() - os._exit(0) + except: + print_exc() diff --git a/LunaTranslator/LunaTranslator/ocrengines/local.py b/LunaTranslator/LunaTranslator/ocrengines/local.py index 9b9abaef..826fbf0b 100644 --- a/LunaTranslator/LunaTranslator/ocrengines/local.py +++ b/LunaTranslator/LunaTranslator/ocrengines/local.py @@ -17,7 +17,7 @@ import os import gobject, functools from traceback import print_exc from qtsymbols import * -from gui.usefulwidget import LFocusCombo, getboxlayout +from gui.usefulwidget import LFocusCombo, getboxlayout, getQMessageBox from gui.dynalang import LPushButton, LFormLayout, LLabel @@ -140,7 +140,7 @@ def dodownload(combo: QComboBox, allsupports: list): ) -def doinstall(combo: QComboBox, allsupports: list, parent, callback): +def doinstall(self, combo: QComboBox, allsupports: list, parent, callback): lang = allsupports[combo.currentIndex()] f = QFileDialog.getOpenFileName(parent, filter=lang + ".zip") fn = f[0] @@ -149,8 +149,7 @@ def doinstall(combo: QComboBox, allsupports: list, parent, callback): try: with zipfile.ZipFile(fn) as zipf: zipf.extractall("files/ocr") - - gobject.baseobject.showtraymessage("", "安装成功") + getQMessageBox(self, "成功", "安装成功") callback() except: print_exc() @@ -181,7 +180,7 @@ def question(dialog: QDialog): btndownload.clicked.connect(functools.partial(dodownload, combo, allsupports)) btninstall = LPushButton("添加") btninstall.clicked.connect( - functools.partial(doinstall, combo, allsupports, dialog, callback) + functools.partial(doinstall, dialog, combo, allsupports, dialog, callback) ) formLayout.addRow( "添加语言包", diff --git a/LunaTranslator/LunaTranslator/scalemethod/magpie_builtin.py b/LunaTranslator/LunaTranslator/scalemethod/magpie_builtin.py index 1c788802..c1f494b0 100644 --- a/LunaTranslator/LunaTranslator/scalemethod/magpie_builtin.py +++ b/LunaTranslator/LunaTranslator/scalemethod/magpie_builtin.py @@ -1,11 +1,10 @@ from scalemethod.base import scalebase -import os, json +import json import windows, gobject from myutils.config import globalconfig, magpie_config from myutils.subproc import subproc_w -from myutils.wrapper import threader -from winsharedutils import startmaglistener, endmaglistener - +from ctypes import c_int, CFUNCTYPE, c_void_p +import winsharedutils class Method(scalebase): def saveconfig(self): @@ -14,17 +13,14 @@ class Method(scalebase): json.dumps(magpie_config, ensure_ascii=False, sort_keys=False, indent=4) ) - @threader - def statuslistener(self): - listener = windows.AutoHandle(startmaglistener()) - while not self.hasend: - status = windows.c_int.from_buffer_copy(windows.ReadFile(listener, 4)).value - self.setuistatus(status) - - endmaglistener(listener) + + def messagecallback(self ,msg, status): + if msg==1: + self.setuistatus(int(bool(status))) def init(self): - self.statuslistener() + self.messagecallback__ = CFUNCTYPE(None, c_int, c_void_p)(self.messagecallback) + winsharedutils.globalmessagelistener(self.messagecallback__) self.jspath = gobject.gettempdir("magpie.config.json") self.engine = subproc_w( './files/plugins/Magpie/Magpie.Core.exe "{}"'.format(self.jspath), diff --git a/LunaTranslator/LunaTranslator/translator/claude.py b/LunaTranslator/LunaTranslator/translator/claude.py index dfd764a9..f4e759ee 100644 --- a/LunaTranslator/LunaTranslator/translator/claude.py +++ b/LunaTranslator/LunaTranslator/translator/claude.py @@ -116,6 +116,8 @@ class TS(basetrans): elif json_data["type"] == "content_block_start": msg = json_data["content_block"]["text"] message += msg + else: + continue except: print_exc() raise Exception(response_data) diff --git a/LunaTranslator/LunaTranslator/windows.py b/LunaTranslator/LunaTranslator/windows.py index 4c1370e6..92bb3a38 100644 --- a/LunaTranslator/LunaTranslator/windows.py +++ b/LunaTranslator/LunaTranslator/windows.py @@ -205,7 +205,8 @@ _GetWindowLong.argtypes = c_int, c_int _SetWindowLongW = _user32.SetWindowLongW _SetWindowLongW.argtypes = c_int, c_int, c_int - +BringWindowToTop = _user32.BringWindowToTop +BringWindowToTop.argtypes = (HWND,) _GetDC = _user32.GetDC _GetDC.restype = c_void_p _ReleaseDC = _user32.ReleaseDC @@ -423,7 +424,6 @@ def GetClientRect(hwnd): return (_rect.left, _rect.top, _rect.right, _rect.bottom) - def ShowWindow(hwnd, nCmdShow): return _ShowWindow(hwnd, nCmdShow) diff --git a/LunaTranslator/LunaTranslator/winsharedutils.py b/LunaTranslator/LunaTranslator/winsharedutils.py index 4bc95519..40cde7c3 100644 --- a/LunaTranslator/LunaTranslator/winsharedutils.py +++ b/LunaTranslator/LunaTranslator/winsharedutils.py @@ -239,8 +239,10 @@ def queryversion(exe): return None -startdarklistener = utilsdll.startdarklistener -startdarklistener.restype = HANDLE +globalmessagelistener = utilsdll.globalmessagelistener +globalmessagelistener.argtypes = (c_void_p,) +dispatchcloseevent = utilsdll.dispatchcloseevent + _SetTheme = utilsdll._SetTheme _SetTheme.argtypes = HWND, c_bool, c_int @@ -302,11 +304,6 @@ Is64bit.restype = c_bool isDark = utilsdll.isDark isDark.restype = c_bool -startmaglistener = utilsdll.startmaglistener -startmaglistener.restype = HANDLE -endmaglistener = utilsdll.endmaglistener -endmaglistener.argtypes = (HANDLE,) - PlayAudioInMem = utilsdll.PlayAudioInMem PlayAudioInMem.argtypes = ( c_void_p, diff --git a/LunaTranslator/files/lang/ar.json b/LunaTranslator/files/lang/ar.json index 14c03270..909c4ee2 100644 --- a/LunaTranslator/files/lang/ar.json +++ b/LunaTranslator/files/lang/ar.json @@ -853,5 +853,7 @@ "字符串替换": "سلسلة استبدال", "转义": "هروب", "不推荐使用": "لا ينصح باستخدام", - "游戏已存在,是否重复添加?": "اللعبة موجودة بالفعل ، هل تريد تكرار ذلك ؟" + "游戏已存在,是否重复添加?": "اللعبة موجودة بالفعل ، هل تريد تكرار ذلك ؟", + "点击消息后重新启动以生效": "اضغط على الرسالة إلى إعادة تشغيل نافذة المفعول", + "点击消息后退出并开始更新": "انقر على رسالة الخروج والبدء في تحديث" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cht.json b/LunaTranslator/files/lang/cht.json index e8f83c96..c4c19941 100644 --- a/LunaTranslator/files/lang/cht.json +++ b/LunaTranslator/files/lang/cht.json @@ -853,5 +853,7 @@ "字符串替换": "字串取代", "转义": "跳脫", "不推荐使用": "不推薦使用", - "游戏已存在,是否重复添加?": "遊戲已存在,是否重複新增?" + "游戏已存在,是否重复添加?": "遊戲已存在,是否重複新增?", + "点击消息后重新启动以生效": "點擊消息後重新啟動以生效", + "点击消息后退出并开始更新": "點擊消息後退出並開始更新" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/cs.json b/LunaTranslator/files/lang/cs.json index a13dd52b..c6004b3e 100644 --- a/LunaTranslator/files/lang/cs.json +++ b/LunaTranslator/files/lang/cs.json @@ -853,5 +853,7 @@ "字符串替换": "Náhrada řetězce", "转义": "Útěk", "不推荐使用": "Nedoporučuje se k použití", - "游戏已存在,是否重复添加?": "Hra již existuje, chtěli byste ji znovu přidat?" + "游戏已存在,是否重复添加?": "Hra již existuje, chtěli byste ji znovu přidat?", + "点击消息后重新启动以生效": "Klikněte na zprávu a restartujte ji.", + "点击消息后退出并开始更新": "Klikněte na zprávu pro ukončení a spuštění aktualizace" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/de.json b/LunaTranslator/files/lang/de.json index 5d5a6561..7afe2aae 100644 --- a/LunaTranslator/files/lang/de.json +++ b/LunaTranslator/files/lang/de.json @@ -853,5 +853,7 @@ "字符串替换": "Zeichenfolgenersatz", "转义": "Flucht", "不推荐使用": "Nicht empfohlen für die Anwendung", - "游戏已存在,是否重复添加?": "Das Spiel existiert bereits, möchtest du es noch einmal hinzufügen?" + "游戏已存在,是否重复添加?": "Das Spiel existiert bereits, möchtest du es noch einmal hinzufügen?", + "点击消息后重新启动以生效": "Klicken Sie auf die Nachricht und starten Sie neu, um wirksam zu werden", + "点击消息后退出并开始更新": "Klicken Sie auf die Nachricht, um zu beenden und mit der Aktualisierung zu beginnen" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/en.json b/LunaTranslator/files/lang/en.json index 96471f0d..c1f54ee3 100644 --- a/LunaTranslator/files/lang/en.json +++ b/LunaTranslator/files/lang/en.json @@ -853,5 +853,7 @@ "字符串替换": "String replacement", "转义": "Escaping", "不推荐使用": "Not recommended for use", - "游戏已存在,是否重复添加?": "The game already exists, would you like to add it again?" + "游戏已存在,是否重复添加?": "The game already exists, would you like to add it again?", + "点击消息后重新启动以生效": "Click on the message and restart to take effect", + "点击消息后退出并开始更新": "Click on the message to exit and start updating" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/es.json b/LunaTranslator/files/lang/es.json index 3041d6ce..6b385d39 100644 --- a/LunaTranslator/files/lang/es.json +++ b/LunaTranslator/files/lang/es.json @@ -853,5 +853,7 @@ "字符串替换": "Reemplazo de cadenas", "转义": "Transliteración", "不推荐使用": "No se recomienda usar", - "游戏已存在,是否重复添加?": "¿El juego ya existe, ¿ se repite la adición?" + "游戏已存在,是否重复添加?": "¿El juego ya existe, ¿ se repite la adición?", + "点击消息后重新启动以生效": "Reiniciar para entrar en vigor después de hacer clic en el mensaje", + "点击消息后退出并开始更新": "Haga clic en el mensaje para salir y comenzar la actualización" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/fr.json b/LunaTranslator/files/lang/fr.json index 64109aa7..00ab11a2 100644 --- a/LunaTranslator/files/lang/fr.json +++ b/LunaTranslator/files/lang/fr.json @@ -853,5 +853,7 @@ "字符串替换": "Remplacement de chaîne", "转义": "échappement", "不推荐使用": "Utilisation non recommandée", - "游戏已存在,是否重复添加?": "Le jeu existe déjà, y a - t - il des ajouts répétés?" + "游戏已存在,是否重复添加?": "Le jeu existe déjà, y a - t - il des ajouts répétés?", + "点击消息后重新启动以生效": "Redémarrer après avoir cliqué sur le message pour prendre effet", + "点击消息后退出并开始更新": "Quitter et commencer la mise à jour après avoir cliqué sur le message" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/it.json b/LunaTranslator/files/lang/it.json index 22d00fed..7f84cd6f 100644 --- a/LunaTranslator/files/lang/it.json +++ b/LunaTranslator/files/lang/it.json @@ -853,5 +853,7 @@ "字符串替换": "Sostituzione stringa", "转义": "Scappare", "不推荐使用": "Non raccomandato per l'uso", - "游戏已存在,是否重复添加?": "Il gioco esiste già, vuoi aggiungerlo di nuovo?" + "游戏已存在,是否重复添加?": "Il gioco esiste già, vuoi aggiungerlo di nuovo?", + "点击消息后重新启动以生效": "Fare clic sul messaggio e riavviare per avere effetto", + "点击消息后退出并开始更新": "Clicca sul messaggio per uscire e iniziare l'aggiornamento" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ja.json b/LunaTranslator/files/lang/ja.json index c477ae9e..89920722 100644 --- a/LunaTranslator/files/lang/ja.json +++ b/LunaTranslator/files/lang/ja.json @@ -853,5 +853,7 @@ "字符串替换": "文字列置換", "转义": "エスケープ", "不推荐使用": "使用を推奨しない", - "游戏已存在,是否重复添加?": "ゲームは既に存在します。追加を繰り返しますか?" + "游戏已存在,是否重复添加?": "ゲームは既に存在します。追加を繰り返しますか?", + "点击消息后重新启动以生效": "メッセージをクリックして再起動して有効にする", + "点击消息后退出并开始更新": "メッセージをクリックして終了し、更新を開始" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ko.json b/LunaTranslator/files/lang/ko.json index d40fd60c..766d1013 100644 --- a/LunaTranslator/files/lang/ko.json +++ b/LunaTranslator/files/lang/ko.json @@ -853,5 +853,7 @@ "字符串替换": "문자열 대체", "转义": "전의", "不推荐使用": "권장하지 않음", - "游戏已存在,是否重复添加?": "게임이 이미 존재합니다. 다시 추가하시겠습니까?" + "游戏已存在,是否重复添加?": "게임이 이미 존재합니다. 다시 추가하시겠습니까?", + "点击消息后重新启动以生效": "메시지를 클릭한 후 다시 시작하여 적용", + "点击消息后退出并开始更新": "메시지 클릭 후 종료 및 업데이트 시작" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/nl.json b/LunaTranslator/files/lang/nl.json index 11269f65..e012cc69 100644 --- a/LunaTranslator/files/lang/nl.json +++ b/LunaTranslator/files/lang/nl.json @@ -853,5 +853,7 @@ "字符串替换": "Vervanging van tekenreeks", "转义": "Ontsnappen", "不推荐使用": "Niet aanbevolen voor gebruik", - "游戏已存在,是否重复添加?": "Het spel bestaat al, wil je het opnieuw toevoegen?" + "游戏已存在,是否重复添加?": "Het spel bestaat al, wil je het opnieuw toevoegen?", + "点击消息后重新启动以生效": "Klik op het bericht en start opnieuw op om van kracht te worden", + "点击消息后退出并开始更新": "Klik op het bericht om te sluiten en te beginnen met updaten" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pl.json b/LunaTranslator/files/lang/pl.json index 5d1950f6..0d213011 100644 --- a/LunaTranslator/files/lang/pl.json +++ b/LunaTranslator/files/lang/pl.json @@ -853,5 +853,7 @@ "字符串替换": "Zastąpienie ciągu", "转义": "Ucieczka", "不推荐使用": "Nie zaleca się stosowania", - "游戏已存在,是否重复添加?": "Gra już istnieje, chcesz dodać ją ponownie?" + "游戏已存在,是否重复添加?": "Gra już istnieje, chcesz dodać ją ponownie?", + "点击消息后重新启动以生效": "Kliknij na wiadomość i uruchom ponownie, aby wejść w życie", + "点击消息后退出并开始更新": "Kliknij na wiadomość, aby wyjść i rozpocząć aktualizację" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/pt.json b/LunaTranslator/files/lang/pt.json index feac10f3..379b8960 100644 --- a/LunaTranslator/files/lang/pt.json +++ b/LunaTranslator/files/lang/pt.json @@ -853,5 +853,7 @@ "字符串替换": "Substituição de strings", "转义": "Escapar", "不推荐使用": "Não recomendado para utilização", - "游戏已存在,是否重复添加?": "O jogo já existe, você gostaria de adicioná-lo novamente?" + "游戏已存在,是否重复添加?": "O jogo já existe, você gostaria de adicioná-lo novamente?", + "点击消息后重新启动以生效": "Clique na mensagem e reinicie para entrar em vigor", + "点击消息后退出并开始更新": "Clique na mensagem para sair e iniciar a atualização" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/ru.json b/LunaTranslator/files/lang/ru.json index e29272d3..adb8a628 100644 --- a/LunaTranslator/files/lang/ru.json +++ b/LunaTranslator/files/lang/ru.json @@ -853,5 +853,7 @@ "字符串替换": "Замена строки", "转义": "Транслитерация", "不推荐使用": "Не рекомендуется использовать", - "游戏已存在,是否重复添加?": "Игра уже существует, добавляется ли повторно?" + "游戏已存在,是否重复添加?": "Игра уже существует, добавляется ли повторно?", + "点击消息后重新启动以生效": "После нажатия на сообщение перезапустить для вступления в силу", + "点击消息后退出并开始更新": "Выйти после нажатия на сообщение и начать обновление" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/sv.json b/LunaTranslator/files/lang/sv.json index 17913d67..d319fa0a 100644 --- a/LunaTranslator/files/lang/sv.json +++ b/LunaTranslator/files/lang/sv.json @@ -853,5 +853,7 @@ "字符串替换": "Strängersättning", "转义": "Flykt", "不推荐使用": "Rekommenderas inte för användning", - "游戏已存在,是否重复添加?": "Spelet finns redan, vill du lägga till det igen?" + "游戏已存在,是否重复添加?": "Spelet finns redan, vill du lägga till det igen?", + "点击消息后重新启动以生效": "Klicka på meddelandet och starta om för att träda i kraft", + "点击消息后退出并开始更新": "Klicka på meddelandet för att avsluta och börja uppdatera" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/th.json b/LunaTranslator/files/lang/th.json index 4a857a27..4f30715a 100644 --- a/LunaTranslator/files/lang/th.json +++ b/LunaTranslator/files/lang/th.json @@ -853,5 +853,7 @@ "字符串替换": "การแทนที่สตริง", "转义": "แปลความหมาย", "不推荐使用": "ไม่แนะนำให้ใช้", - "游戏已存在,是否重复添加?": "มีเกมอยู่แล้วคุณต้องการเพิ่มซ้ำหรือไม่?" + "游戏已存在,是否重复添加?": "มีเกมอยู่แล้วคุณต้องการเพิ่มซ้ำหรือไม่?", + "点击消息后重新启动以生效": "เริ่มใหม่หลังจากแตะข้อความเพื่อให้มีผล", + "点击消息后退出并开始更新": "ออกจากข้อความและเริ่มต้นการปรับปรุง" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/tr.json b/LunaTranslator/files/lang/tr.json index a9302cbe..05ebe082 100644 --- a/LunaTranslator/files/lang/tr.json +++ b/LunaTranslator/files/lang/tr.json @@ -853,5 +853,7 @@ "字符串替换": "String Replacement", "转义": "Kaçmak", "不推荐使用": "Kullanmak için önerilmez", - "游戏已存在,是否重复添加?": "Oyun zaten var, tekrar eklemek ister misiniz?" + "游戏已存在,是否重复添加?": "Oyun zaten var, tekrar eklemek ister misiniz?", + "点击消息后重新启动以生效": "Mesaj üzerine tıklayın ve etkisi yaratmak için yeniden başlatın", + "点击消息后退出并开始更新": "Çıkmak ve güncellenmeye başlamak için mesajı tıklayın" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/uk.json b/LunaTranslator/files/lang/uk.json index 90ea5a9b..ba2688fc 100644 --- a/LunaTranslator/files/lang/uk.json +++ b/LunaTranslator/files/lang/uk.json @@ -853,5 +853,7 @@ "字符串替换": "Заміна рядків", "转义": "Бег", "不推荐使用": "Не рекомендується використовувати", - "游戏已存在,是否重复添加?": "Гра вже існує, бажаєте додати її знову?" + "游戏已存在,是否重复添加?": "Гра вже існує, бажаєте додати її знову?", + "点击消息后重新启动以生效": "Натисніть лівою кнопкою миші на повідомлення і перезапускайте, щоб діяти", + "点击消息后退出并开始更新": "Натисніть повідомлення для виходу і запуску оновлення" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/vi.json b/LunaTranslator/files/lang/vi.json index f275a1b6..42e71e24 100644 --- a/LunaTranslator/files/lang/vi.json +++ b/LunaTranslator/files/lang/vi.json @@ -853,5 +853,7 @@ "字符串替换": "Thay thế chuỗi", "转义": "Thoát", "不推荐使用": "Không khuyến khích sử dụng", - "游戏已存在,是否重复添加?": "Trò chơi đã tồn tại, có được thêm nhiều lần không?" + "游戏已存在,是否重复添加?": "Trò chơi đã tồn tại, có được thêm nhiều lần không?", + "点击消息后重新启动以生效": "Khởi động lại sau khi nhấp vào tin nhắn để có hiệu lực", + "点击消息后退出并开始更新": "Thoát sau khi nhấp vào tin nhắn và bắt đầu cập nhật" } \ No newline at end of file diff --git a/LunaTranslator/files/lang/zh.json b/LunaTranslator/files/lang/zh.json index 44b2e824..c8167e76 100644 --- a/LunaTranslator/files/lang/zh.json +++ b/LunaTranslator/files/lang/zh.json @@ -853,5 +853,7 @@ "字符串替换": "", "转义": "", "不推荐使用": "", - "游戏已存在,是否重复添加?": "" + "游戏已存在,是否重复添加?": "", + "点击消息后重新启动以生效": "", + "点击消息后退出并开始更新": "" } \ No newline at end of file diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index a366e026..80142090 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -29,7 +29,7 @@ include(generate_product_version) set(VERSION_MAJOR 5) set(VERSION_MINOR 23) -set(VERSION_PATCH 3) +set(VERSION_PATCH 4) add_library(pch pch.cpp) target_precompile_headers(pch PUBLIC pch.h) diff --git a/plugins/winsharedutils/CMakeLists.txt b/plugins/winsharedutils/CMakeLists.txt index 8ca9a82b..eb6b112b 100644 --- a/plugins/winsharedutils/CMakeLists.txt +++ b/plugins/winsharedutils/CMakeLists.txt @@ -11,7 +11,7 @@ generate_product_version( VERSION_PATCH ${VERSION_PATCH} ) -add_library(winsharedutils MODULE webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp audio.cpp ../implsapi.cpp hwnd.cpp darklistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp maglistener.cpp ${versioninfo}) +add_library(winsharedutils MODULE webview2_extra.cpp AreoAcrylic.cpp screenshot.cpp audio.cpp ../implsapi.cpp hwnd.cpp globalmessagelistener.cpp theme.cpp version.cpp otsu.cpp clipboard.cpp lnk.cpp dllmain.cpp levenshtein.cpp muteprocess.cpp sapi_dll.cpp simplemecab.cpp SimpleBrowser.cpp MWebBrowser.cpp icon.cpp ${versioninfo}) target_precompile_headers(winsharedutils REUSE_FROM pch) if(${CMAKE_SIZEOF_VOID_P} EQUAL 8) set_target_properties(winsharedutils PROPERTIES OUTPUT_NAME "winsharedutils64") diff --git a/plugins/winsharedutils/darklistener.cpp b/plugins/winsharedutils/darklistener.cpp deleted file mode 100644 index 910cac74..00000000 --- a/plugins/winsharedutils/darklistener.cpp +++ /dev/null @@ -1,42 +0,0 @@ - -#include "define.h" -HANDLE hsema; -void IsColorSchemeChangeMessage(LPARAM lParam) -{ - if (lParam && CompareStringOrdinal(reinterpret_cast(lParam), -1, L"ImmersiveColorSet", -1, TRUE) == CSTR_EQUAL) - { - ReleaseSemaphore(hsema, 1, 0); - } -} -void startdarklistener_1() -{ - const wchar_t CLASS_NAME[] = L"LunaDarkListener"; - - WNDCLASS wc = {}; - wc.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) - { - if (WM_SETTINGCHANGE == message) - IsColorSchemeChangeMessage(lParam); - return DefWindowProc(hWnd, message, wParam, lParam); - }; - wc.hInstance = GetModuleHandle(0); - wc.lpszClassName = CLASS_NAME; - - static auto _ = RegisterClass(&wc); - HWND hWnd = CreateWindowEx( - WS_EX_CLIENTEDGE, CLASS_NAME, CLASS_NAME, WS_OVERLAPPEDWINDOW, - 0, 0, 0, 0, - NULL, NULL, GetModuleHandle(0), 0); - MSG msg = {}; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } -} -HANDLE startdarklistener() -{ - hsema = CreateSemaphoreW(0, 0, 10, 0); - std::thread(startdarklistener_1).detach(); - return hsema; -} \ No newline at end of file diff --git a/plugins/winsharedutils/define.h b/plugins/winsharedutils/define.h index 06b334f8..293c407f 100644 --- a/plugins/winsharedutils/define.h +++ b/plugins/winsharedutils/define.h @@ -3,7 +3,6 @@ extern "C" { - __declspec(dllexport) HANDLE startdarklistener(); __declspec(dllexport) bool queryversion(const wchar_t *exe, WORD *_1, WORD *_2, WORD *_3, WORD *_4); __declspec(dllexport) void SAPI_List(int version, void (*cb)(const wchar_t *)); diff --git a/plugins/winsharedutils/globalmessagelistener.cpp b/plugins/winsharedutils/globalmessagelistener.cpp new file mode 100644 index 00000000..989d6e7a --- /dev/null +++ b/plugins/winsharedutils/globalmessagelistener.cpp @@ -0,0 +1,63 @@ + +#include "define.h" +static auto LUNA_UPDATE_PREPARED_OK = RegisterWindowMessage(L"LUNA_UPDATE_PREPARED_OK"); +static auto WM_MAGPIE_SCALINGCHANGED = RegisterWindowMessage(L"MagpieScalingChanged"); +bool IsColorSchemeChangeMessage(LPARAM lParam) +{ + return lParam && CompareStringOrdinal(reinterpret_cast(lParam), -1, L"ImmersiveColorSet", -1, TRUE) == CSTR_EQUAL; +} +void globalmessagelistener_1(void *callback) +{ + + const wchar_t CLASS_NAME[] = L"globalmessagelistener"; + + WNDCLASS wc = {}; + wc.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + { + void (*callback)(int, void *); + callback = (decltype(callback))GetWindowLongPtrW(hWnd, GWLP_USERDATA); + if (callback) + { + if (WM_SETTINGCHANGE == message) + { + if (IsColorSchemeChangeMessage(lParam)) + callback(0, 0); + } + else if (message == WM_MAGPIE_SCALINGCHANGED) + { + callback(1, (void *)wParam); + } + else if (message == LUNA_UPDATE_PREPARED_OK) + { + callback(2, 0); + } + } + return DefWindowProc(hWnd, message, wParam, lParam); + }; + wc.hInstance = GetModuleHandle(0); + wc.lpszClassName = CLASS_NAME; + + static auto _ = RegisterClass(&wc); + HWND hWnd = CreateWindowEx( + WS_EX_CLIENTEDGE, CLASS_NAME, CLASS_NAME, WS_OVERLAPPEDWINDOW, + 0, 0, 0, 0, + NULL, NULL, GetModuleHandle(0), 0); + SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)callback); + ChangeWindowMessageFilterEx(hWnd, LUNA_UPDATE_PREPARED_OK, MSGFLT_ALLOW, nullptr); + ChangeWindowMessageFilterEx(hWnd, WM_MAGPIE_SCALINGCHANGED, MSGFLT_ALLOW, nullptr); + MSG msg = {}; + while (GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } +} +DECLARE void globalmessagelistener(void *callback) +{ + std::thread(std::bind(globalmessagelistener_1, callback)).detach(); +} + +DECLARE void dispatchcloseevent() +{ + PostMessage(HWND_BROADCAST, LUNA_UPDATE_PREPARED_OK, 0, 0); +} \ No newline at end of file diff --git a/plugins/winsharedutils/maglistener.cpp b/plugins/winsharedutils/maglistener.cpp deleted file mode 100644 index 60ce5610..00000000 --- a/plugins/winsharedutils/maglistener.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "define.h" - -static UINT WM_MAGPIE_SCALINGCHANGED = RegisterWindowMessage(L"MagpieScalingChanged"); -static HWND listener = 0; -static HANDLE hwrite = 0; - -DECLARE HANDLE startmaglistener() -{ - ChangeWindowMessageFilter(WM_MAGPIE_SCALINGCHANGED, MSGFLT_ADD); - auto CLASS_NAME = L"MagpieWatcher"; - WNDCLASS wc = {}; - wc.lpfnWndProc = [](HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) - { - if (message == WM_MAGPIE_SCALINGCHANGED && hwrite) - { - int send = wParam; - DWORD _; - WriteFile(hwrite, &send, 4, &_, 0); - } - switch (message) - { - - case WM_DESTROY: - { - CloseHandle(hwrite); - PostQuitMessage(0); - } - } - return DefWindowProc(hWnd, message, wParam, lParam); - }; - wc.hInstance = GetModuleHandle(0); - wc.lpszClassName = CLASS_NAME; - static auto _ = RegisterClass(&wc); - HANDLE hread; - CreatePipe(&hread, &hwrite, 0, 0); - - std::thread([=]() - { - listener = CreateWindowEx( - WS_EX_CLIENTEDGE, CLASS_NAME, CLASS_NAME, WS_OVERLAPPEDWINDOW, - 0, 0, 0, 0, - NULL, NULL, GetModuleHandle(0), hwrite);; - MSG msg = {}; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } }) - .detach(); - - return hread; -} -DECLARE void endmaglistener(HANDLE hread) -{ - if (listener) - { - DestroyWindow(listener); - listener = 0; - hwrite = 0; - } -} \ No newline at end of file