1
0
Fork 0
mirror of synced 2024-06-20 19:40:25 +12:00

Fix offline mode

This commit is contained in:
lennard 2022-10-29 12:23:50 +02:00
parent e208daf545
commit ca45c62414
No known key found for this signature in database
GPG key ID: AB6010FE63C7C2B1
3 changed files with 29 additions and 30 deletions

View file

@ -279,7 +279,7 @@ class LaunchDialog(QDialog):
def finish(self):
self.completed += 1
if self.completed == 2:
if self.completed >= 2:
logger.info("App starting")
ApiResultsSingleton(self.api_results)
self.completed += 1

View file

@ -1,5 +1,5 @@
from PyQt5.QtCore import QSize, pyqtSignal
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut
from PyQt5.QtWidgets import QMenu, QTabWidget, QWidget, QWidgetAction, QShortcut, QMessageBox
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton, ArgumentsSingleton
from rare.components.tabs.account import AccountWidget
@ -57,8 +57,9 @@ class TabWidget(QTabWidget):
self.addTab(self.account, "")
self.setTabEnabled(disabled_tab + 1, False)
self.account_widget = AccountWidget(self, self.downloads_tab)
self.account_widget = AccountWidget(self)
self.account_widget.exit_app.connect(self.exit_app)
self.account_widget.logout.connect(self.logout)
account_action = QWidgetAction(self)
account_action.setDefaultWidget(self.account_widget)
account_button = TabButtonWidget("mdi.account-circle", "Account", fallback_icon="fa.user")
@ -113,3 +114,25 @@ class TabWidget(QTabWidget):
def resizeEvent(self, event):
self.tabBar().setMinimumWidth(self.width())
super(TabWidget, self).resizeEvent(event)
def logout(self):
# FIXME: Don't allow logging out if there are active downloads
if self.downloads_tab.is_download_active:
QMessageBox.warning(
self,
self.tr("Logout"),
self.tr("There are active downloads. Stop them before logging out."),
)
return
# FIXME: End of FIXME
reply = QMessageBox.question(
self,
self.tr("Logout"),
self.tr("Do you really want to logout <b>{}</b>?").format(self.core.lgd.userdata.get("display_name")),
buttons=(QMessageBox.Yes | QMessageBox.No),
defaultButton=QMessageBox.No,
)
if reply == QMessageBox.Yes:
self.core.lgd.invalidate_userdata()
self.exit_app(-133742) # restart exit code

View file

@ -10,14 +10,14 @@ from rare.utils.misc import icon
class AccountWidget(QWidget):
# int: exit code
exit_app: pyqtSignal = pyqtSignal(int)
logout = pyqtSignal()
def __init__(self, parent, downloads_tab):
def __init__(self, parent):
super(AccountWidget, self).__init__(parent=parent)
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
# FIXME: This is why widgets should be decoupled from procedures.
# FIXME: pass downloads tab as argument to check if there are active downloads
self.downloads_tab = downloads_tab
username = self.core.lgd.userdata.get("display_name")
if not username:
@ -30,34 +30,10 @@ class AccountWidget(QWidget):
)
)
self.logout_button = QPushButton(self.tr("Logout"))
self.logout_button.clicked.connect(self.logout)
self.logout_button.clicked.connect(lambda: self.logout.emit())
layout = QVBoxLayout(self)
layout.addWidget(QLabel(self.tr("Account")))
layout.addWidget(QLabel(self.tr("Logged in as <b>{}</b>").format(username)))
layout.addWidget(self.open_browser)
layout.addWidget(self.logout_button)
def logout(self):
# FIXME: Don't allow logging out if there are active downloads
if self.downloads_tab.is_download_active:
warning = QMessageBox.warning(
self,
self.tr("Logout"),
self.tr("There are active downloads. Stop them before logging out."),
buttons=(QMessageBox.Ok),
defaultButton=QMessageBox.Ok
)
return
# FIXME: End of FIXME
reply = QMessageBox.question(
self,
self.tr("Logout"),
self.tr("Do you really want to logout <b>{}</b>?").format(self.core.lgd.userdata.get("display_name")),
buttons=(QMessageBox.Yes | QMessageBox.No),
defaultButton=QMessageBox.No,
)
if reply == QMessageBox.Yes:
self.core.lgd.invalidate_userdata()
self.exit_app.emit(-133742) # restart exit code