Skip to content

Commit

Permalink
Merge pull request #352 from loathingKernel/next
Browse files Browse the repository at this point in the history
Preparation for future features
  • Loading branch information
loathingKernel authored Dec 24, 2023
2 parents 95d73ea + 600441a commit 826d38c
Show file tree
Hide file tree
Showing 18 changed files with 809 additions and 238 deletions.
11 changes: 6 additions & 5 deletions rare/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ def re_login(self):
@pyqtSlot()
def launch_app(self):
self.launch_dialog = LaunchDialog(parent=None)
self.launch_dialog.exit_app.connect(self.launch_dialog.close)
self.launch_dialog.exit_app.connect(self.__on_exit_app)
self.launch_dialog.start_app.connect(self.start_app)
self.launch_dialog.start_app.connect(self.launch_dialog.close)
self.launch_dialog.rejected.connect(self.__on_exit_app)
# lk: the reason we use the `start_app` signal here instead of accepted, is to keep the dialog
# until the main window has been created, then we call `accept()` to close the dialog
self.launch_dialog.start_app.connect(self.__on_start_app)
self.launch_dialog.start_app.connect(self.launch_dialog.accept)
self.launch_dialog.login()

@pyqtSlot()
def start_app(self):
def __on_start_app(self):
self.timer = QTimer()
self.timer.timeout.connect(self.re_login)
self.poke_timer()
Expand Down
44 changes: 21 additions & 23 deletions rare/components/dialogs/launch_dialog.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import platform
from logging import getLogger

from PyQt5.QtCore import Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QDialog, QApplication
from requests.exceptions import ConnectionError, HTTPError

from rare.components.dialogs.login import LoginDialog
from rare.shared import RareCore
from rare.ui.components.dialogs.launch_dialog import Ui_LaunchDialog
from rare.widgets.dialogs import BaseDialog
from rare.widgets.elide_label import ElideLabel

logger = getLogger("LaunchDialog")


class LaunchDialog(QDialog):
exit_app = pyqtSignal(int)
class LaunchDialog(BaseDialog):
# lk: the reason we use the `start_app` signal here instead of accepted, is to keep the dialog
# until the main window has been created, then we call `accept()` to close the dialog
start_app = pyqtSignal()

def __init__(self, parent=None):
super(LaunchDialog, self).__init__(parent=parent)
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.setWindowFlags(
Qt.Window
| Qt.Dialog
Expand All @@ -29,12 +28,10 @@ def __init__(self, parent=None):
| Qt.WindowMinimizeButtonHint
| Qt.MSWindowsFixedSizeDialogHint
)
self.setWindowModality(Qt.WindowModal)

self.ui = Ui_LaunchDialog()
self.ui.setupUi(self)

self.reject_close = True

self.progress_info = ElideLabel(parent=self)
self.progress_info.setFixedHeight(False)
self.ui.launch_layout.addWidget(self.progress_info)
Expand All @@ -46,35 +43,41 @@ def __init__(self, parent=None):
self.args = self.rcore.args()

self.login_dialog = LoginDialog(core=self.core, parent=parent)
self.login_dialog.rejected.connect(self.reject)
self.login_dialog.accepted.connect(self.do_launch)

def login(self):
do_launch = True
can_launch = True
try:
if self.args.offline:
pass
else:
# Force an update check and notice in case there are API changes
# self.core.check_for_updates(force=True)
# self.core.force_show_update = True
if self.core.login():
if self.core.login(force_refresh=True):
logger.info("You are logged in")
self.login_dialog.close()
else:
raise ValueError("You are not logged in. Open Login Window")
raise ValueError("You are not logged in. Opening login window.")
except ValueError as e:
logger.info(str(e))
# Do not set parent, because it won't show a task bar icon
# Update: Inherit the same parent as LaunchDialog
do_launch = self.login_dialog.login()
can_launch = False
self.login_dialog.open()
except (HTTPError, ConnectionError) as e:
logger.warning(e)
self.args.offline = True
finally:
if do_launch:
if not self.args.silent:
self.show()
self.launch()
else:
self.exit_app.emit(0)
if can_launch:
self.do_launch()

@pyqtSlot()
def do_launch(self):
if not self.args.silent:
self.open()
self.launch()

def launch(self):
self.progress_info.setText(self.tr("Preparing Rare"))
Expand All @@ -87,9 +90,4 @@ def __on_progress(self, i: int, m: str):

def __on_completed(self):
logger.info("App starting")
self.reject_close = False
self.start_app.emit()

def reject(self) -> None:
if not self.reject_close:
super(LaunchDialog, self).reject()
33 changes: 21 additions & 12 deletions rare/components/dialogs/login/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from logging import getLogger

from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtWidgets import QLayout, QDialog, QMessageBox, QFrame
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QLayout, QMessageBox, QFrame
from legendary.core import LegendaryCore

from rare.shared import ArgumentsSingleton
from rare.ui.components.dialogs.login.landing_page import Ui_LandingPage
from rare.ui.components.dialogs.login.login_dialog import Ui_LoginDialog
from rare.utils.misc import icon
from rare.widgets.dialogs import BaseDialog
from rare.widgets.sliding_stack import SlidingStackedWidget
from .browser_login import BrowserLogin
from .import_login import ImportLogin
Expand All @@ -22,12 +24,10 @@ def __init__(self, parent=None):
self.ui.setupUi(self)


class LoginDialog(QDialog):
exit_app: pyqtSignal = pyqtSignal(int)
class LoginDialog(BaseDialog):

def __init__(self, core: LegendaryCore, parent=None):
super(LoginDialog, self).__init__(parent=parent)
self.setAttribute(Qt.WA_DeleteOnClose, True)
self.setWindowFlags(
Qt.Window
| Qt.Dialog
Expand All @@ -38,7 +38,7 @@ def __init__(self, core: LegendaryCore, parent=None):
| Qt.WindowCloseButtonHint
| Qt.MSWindowsFixedSizeDialogHint
)
self.setWindowModality(Qt.WindowModal)

self.ui = Ui_LoginDialog()
self.ui.setupUi(self)

Expand Down Expand Up @@ -93,13 +93,22 @@ def __init__(self, core: LegendaryCore, parent=None):
self.landing_page.ui.login_import_radio.clicked.connect(lambda: self.ui.next_button.setEnabled(True))
self.landing_page.ui.login_import_radio.clicked.connect(self.import_radio_clicked)

self.ui.exit_button.clicked.connect(self.close)
self.ui.exit_button.clicked.connect(self.reject)
self.ui.back_button.clicked.connect(self.back_clicked)
self.ui.next_button.clicked.connect(self.next_clicked)

self.login_stack.setCurrentWidget(self.landing_page)

self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.ui.exit_button.setIcon(icon("fa.remove"))
self.ui.back_button.setIcon(icon("fa.chevron-left"))
self.ui.next_button.setIcon(icon("fa.chevron-right"))

# lk: Set next as the default button only to stop closing the dialog when pressing enter
self.ui.exit_button.setAutoDefault(False)
self.ui.back_button.setAutoDefault(False)
self.ui.next_button.setAutoDefault(True)

self.ui.main_layout.setSizeConstraint(QLayout.SetFixedSize)

def back_clicked(self):
self.ui.back_button.setEnabled(False)
Expand Down Expand Up @@ -129,15 +138,14 @@ def next_clicked(self):

def login(self):
if self.args.test_start:
return False
self.exec_()
return self.logged_in
self.reject()
self.open()

def login_successful(self):
try:
if self.core.login():
self.logged_in = True
self.close()
self.accept()
else:
raise ValueError("Login failed.")
except Exception as e:
Expand All @@ -146,3 +154,4 @@ def login_successful(self):
self.ui.next_button.setEnabled(False)
self.logged_in = False
QMessageBox.warning(None, self.tr("Login error"), str(e))

2 changes: 1 addition & 1 deletion rare/components/tabs/games/game_widgets/list_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def setupUi(self, widget: QWidget):

self.install_btn = QPushButton(parent=widget)
self.install_btn.setObjectName(f"{type(self).__name__}Button")
self.install_btn.setIcon(icon("ri.install-fill"))
self.install_btn.setIcon(icon("ri.install-line"))
self.install_btn.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.install_btn.setFixedWidth(120)

Expand Down
Loading

0 comments on commit 826d38c

Please sign in to comment.