Skip to content

Commit

Permalink
修复了程序无法退出的问题 (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzaphkiel committed Oct 30, 2023
1 parent ab3ac47 commit 96bfead
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
9 changes: 9 additions & 0 deletions app/lol/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
18 changes: 13 additions & 5 deletions app/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 96bfead

Please sign in to comment.