From 96bfead4a0a602e514a6b8f5bd290e298b95d5ec Mon Sep 17 00:00:00 2001 From: Zzaphkiel <1278228162@qq.com> Date: Tue, 31 Oct 2023 00:03:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E9=80=80=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lol/listener.py | 9 +++++++++ app/view/main_window.py | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/lol/listener.py b/app/lol/listener.py index 1c393cd2..35d0f998 100644 --- a/app/lol/listener.py +++ b/app/lol/listener.py @@ -100,3 +100,12 @@ async def main(): asyncio.run(main()) except: return + + +class StoppableThread(QThread): + def __init__(self, target, parent) -> None: + self.target = target + super().__init__(parent) + + def run(self): + self.target() diff --git a/app/view/main_window.py b/app/view/main_window.py index a6a9e5c6..18592be1 100644 --- a/app/view/main_window.py +++ b/app/view/main_window.py @@ -29,7 +29,7 @@ from ..components.update_message_box import UpdateMessageBox from ..lol.entries import Summoner from ..lol.exceptions import SummonerGamesNotFound, RetryMaximumAttempts, SummonerNotFound, SummonerNotInGame -from ..lol.listener import (LolProcessExistenceListener, LolClientEventListener, +from ..lol.listener import (LolProcessExistenceListener, LolClientEventListener, StoppableThread, getLolProcessPid) from ..lol.connector import connector from ..lol.tools import (processGameData, translateTier, getRecentChampions, @@ -66,6 +66,11 @@ def __init__(self): self.processListener = LolProcessExistenceListener(self) self.eventListener = LolClientEventListener(self) + self.checkUpdateThread = StoppableThread( + target=self.checkUpdate, parent=self) + self.pollingConnectTimeoutThread = StoppableThread( + self.pollingConnectTimeout, parent=self) + self.currentSummoner: Summoner = None self.isGaming = False @@ -78,9 +83,6 @@ def __init__(self): self.__conncetSignalToSlot() self.splashScreen.finish() - threading.Thread(target=self.checkUpdate).start() - threading.Thread(target=self.pollingConnectTimeout, - daemon=True).start() def __initInterface(self): self.__lockInterface() @@ -312,6 +314,8 @@ def quit(): def __initListener(self): self.processListener.start() + self.checkUpdateThread.start() + self.pollingConnectTimeoutThread.start() def __changeCareerToCurrentSummoner(self): self.careerInterface.showLoadingPage.emit() @@ -562,6 +566,9 @@ def closeEvent(self, a0) -> None: if not cfg.get(cfg.enableCloseToTray) or self.isTrayExit: self.processListener.terminate() self.eventListener.terminate() + self.checkUpdateThread.terminate() + self.pollingConnectTimeoutThread.terminate() + return super().closeEvent(a0) else: a0.ignore() @@ -822,7 +829,8 @@ def __onGameStatusChanged(self, status): # 在标题添加所处队伍 mapSide = connector.getMapSide() if mapSide: - mapSide = self.tr("Blue Team") if mapSide == "blue" else self.tr("Red Team") + mapSide = self.tr( + "Blue Team") if mapSide == "blue" else self.tr("Red Team") title = title + " - " + mapSide self.__onChampionSelectBegin()