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()