Rare: refactor timer names
This commit is contained in:
parent
456050c91c
commit
fd22d831eb
|
@ -51,7 +51,7 @@ class Rare(RareApp):
|
||||||
# set Application name for settings
|
# set Application name for settings
|
||||||
self.main_window: Optional[MainWindow] = None
|
self.main_window: Optional[MainWindow] = None
|
||||||
self.launch_dialog: Optional[LaunchDialog] = None
|
self.launch_dialog: Optional[LaunchDialog] = None
|
||||||
self.timer: Optional[QTimer] = None
|
self.relogin_timer: Optional[QTimer] = None
|
||||||
|
|
||||||
# This launches the application after it has been instantiated.
|
# This launches the application after it has been instantiated.
|
||||||
# The timer's signal will be serviced once we call `exec()` on the application
|
# The timer's signal will be serviced once we call `exec()` on the application
|
||||||
|
@ -61,15 +61,15 @@ class Rare(RareApp):
|
||||||
dt_exp = datetime.fromisoformat(self.core.lgd.userdata['expires_at'][:-1]).replace(tzinfo=timezone.utc)
|
dt_exp = datetime.fromisoformat(self.core.lgd.userdata['expires_at'][:-1]).replace(tzinfo=timezone.utc)
|
||||||
dt_now = datetime.utcnow().replace(tzinfo=timezone.utc)
|
dt_now = datetime.utcnow().replace(tzinfo=timezone.utc)
|
||||||
td = abs(dt_exp - dt_now)
|
td = abs(dt_exp - dt_now)
|
||||||
self.timer.start(int(td.total_seconds() - 60) * 1000)
|
self.relogin_timer.start(int(td.total_seconds() - 60) * 1000)
|
||||||
self.logger.info(f"Renewed session expires at {self.core.lgd.userdata['expires_at']}")
|
self.logger.info(f"Renewed session expires at {self.core.lgd.userdata['expires_at']}")
|
||||||
|
|
||||||
def re_login(self):
|
def relogin(self):
|
||||||
self.logger.info("Session expires shortly. Renew session")
|
self.logger.info("Session expires shortly. Renew session")
|
||||||
try:
|
try:
|
||||||
self.core.login()
|
self.core.login(force_refresh=True)
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self.timer.start(3000) # try again if no connection
|
self.relogin_timer.start(3000) # try again if no connection
|
||||||
return
|
return
|
||||||
self.poke_timer()
|
self.poke_timer()
|
||||||
|
|
||||||
|
@ -85,8 +85,9 @@ class Rare(RareApp):
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def __on_start_app(self):
|
def __on_start_app(self):
|
||||||
self.timer = QTimer()
|
self.relogin_timer = QTimer(self)
|
||||||
self.timer.timeout.connect(self.re_login)
|
self.relogin_timer.setTimerType(Qt.VeryCoarseTimer)
|
||||||
|
self.relogin_timer.timeout.connect(self.relogin)
|
||||||
self.poke_timer()
|
self.poke_timer()
|
||||||
|
|
||||||
self.main_window = MainWindow()
|
self.main_window = MainWindow()
|
||||||
|
@ -105,10 +106,10 @@ class Rare(RareApp):
|
||||||
def __on_exit_app(self, exit_code=0):
|
def __on_exit_app(self, exit_code=0):
|
||||||
threadpool = QThreadPool.globalInstance()
|
threadpool = QThreadPool.globalInstance()
|
||||||
threadpool.waitForDone()
|
threadpool.waitForDone()
|
||||||
if self.timer is not None:
|
if self.relogin_timer is not None:
|
||||||
self.timer.stop()
|
self.relogin_timer.stop()
|
||||||
self.timer.deleteLater()
|
self.relogin_timer.deleteLater()
|
||||||
self.timer = None
|
self.relogin_timer = None
|
||||||
self.rcore.deleteLater()
|
self.rcore.deleteLater()
|
||||||
del self.rcore
|
del self.rcore
|
||||||
self.processEvents()
|
self.processEvents()
|
||||||
|
|
|
@ -106,10 +106,10 @@ class MainWindow(QMainWindow):
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
logger.warning("Discord RPC module not found")
|
logger.warning("Discord RPC module not found")
|
||||||
|
|
||||||
self.timer = QTimer()
|
self.singleton_timer = QTimer(self)
|
||||||
self.timer.setInterval(1000)
|
self.singleton_timer.setInterval(1000)
|
||||||
self.timer.timeout.connect(self.timer_finished)
|
self.singleton_timer.timeout.connect(self.timer_finished)
|
||||||
self.timer.start()
|
self.singleton_timer.start()
|
||||||
|
|
||||||
self.tray_icon: TrayIcon = TrayIcon(self)
|
self.tray_icon: TrayIcon = TrayIcon(self)
|
||||||
self.tray_icon.exit_app.connect(self.__on_exit_app)
|
self.tray_icon.exit_app.connect(self.__on_exit_app)
|
||||||
|
@ -199,7 +199,7 @@ class MainWindow(QMainWindow):
|
||||||
if action.startswith("show"):
|
if action.startswith("show"):
|
||||||
self.show()
|
self.show()
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
self.timer.start()
|
self.singleton_timer.start()
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
|
@ -258,7 +258,7 @@ class MainWindow(QMainWindow):
|
||||||
e.ignore()
|
e.ignore()
|
||||||
return
|
return
|
||||||
# FIXME: End of FIXME
|
# FIXME: End of FIXME
|
||||||
self.timer.stop()
|
self.singleton_timer.stop()
|
||||||
self.tray_icon.deleteLater()
|
self.tray_icon.deleteLater()
|
||||||
self.hide()
|
self.hide()
|
||||||
self.exit_app.emit(self.__exit_code)
|
self.exit_app.emit(self.__exit_code)
|
||||||
|
|
|
@ -2,7 +2,7 @@ import json
|
||||||
import logging
|
import logging
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSignal, QTimer, pyqtSlot
|
from PyQt5.QtCore import QObject, pyqtSignal, QTimer, pyqtSlot, Qt
|
||||||
from PyQt5.QtNetwork import QLocalSocket
|
from PyQt5.QtNetwork import QLocalSocket
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
from legendary.models.game import Game
|
from legendary.models.game import Game
|
||||||
|
|
Loading…
Reference in a new issue