1
0
Fork 0
mirror of synced 2024-06-22 16:20:32 +12:00
Rare/rare/components/tabs/account/__init__.py
loathingKernel 28b2b7ea9b MainWindow: Handle active downloads when exiting through WM's close button.
When the closed through the WM's close button, `closeEvent()` is
 used directly. In this case the dialog in the `on_exit_app`
slot was skipped.

There is a mishandled case. If coming from logout while there
is an active download (Yes to logout -> No to stop download)
we end up in a weird state which I haven't investigated yet.

Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com>
2022-10-23 00:01:30 +03:00

46 lines
1.6 KiB
Python

import webbrowser
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QMessageBox, QLabel, QPushButton
from rare.shared import LegendaryCoreSingleton, GlobalSignalsSingleton
from rare.utils.misc import icon
class AccountWidget(QWidget):
def __init__(self):
super(AccountWidget, self).__init__()
self.core = LegendaryCoreSingleton()
self.signals = GlobalSignalsSingleton()
username = self.core.lgd.userdata.get("display_name")
if not username:
username = "Offline"
self.open_browser = QPushButton(icon("fa.external-link"), self.tr("Account settings"))
self.open_browser.clicked.connect(
lambda: webbrowser.open(
"https://www.epicgames.com/account/personal?productName=epicgames"
)
)
self.logout_button = QPushButton(self.tr("Logout"))
self.logout_button.clicked.connect(self.logout)
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):
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.signals.exit_app.emit(-133742) # restart exit code