1
0
Fork 0
mirror of synced 2024-09-28 23:41:29 +12:00

Fix silent mode + refactoring: move window to center, when showing window

This commit is contained in:
Dummerle 2021-12-22 21:21:49 +01:00
parent 67003bb1b2
commit 5cd942b9e8
No known key found for this signature in database
GPG key ID: AB68CC59CA39F2F1
4 changed files with 38 additions and 24 deletions

View file

@ -49,9 +49,14 @@ def excepthook(exc_type, exc_value, exc_tb):
class App(QApplication): class App(QApplication):
mainwindow: MainWindow = None
tray_icon: QSystemTrayIcon = None
def __init__(self): def __init__(self):
super(App, self).__init__(sys.argv) super(App, self).__init__(sys.argv)
self.args = shared.args # add some options self.args = shared.args # add some options
self.window_launched = False
self.setQuitOnLastWindowClosed(False)
# init Legendary # init Legendary
try: try:
@ -81,8 +86,6 @@ class App(QApplication):
self.core.lgd.save_config() self.core.lgd.save_config()
# set Application name for settings # set Application name for settings
self.mainwindow = None
self.tray_icon = None
self.launch_dialog = None self.launch_dialog = None
self.setApplicationName("Rare") self.setApplicationName("Rare")
self.setOrganizationName("Rare") self.setOrganizationName("Rare")
@ -90,7 +93,7 @@ class App(QApplication):
self.signals = shared.init_signals() self.signals = shared.init_signals()
self.signals.exit_app.connect(self.exit) self.signals.exit_app.connect(self.exit_app)
self.signals.send_notification.connect( self.signals.send_notification.connect(
lambda title: lambda title:
self.tray_icon.showMessage( self.tray_icon.showMessage(
@ -142,16 +145,23 @@ class App(QApplication):
self.launch_dialog.login() self.launch_dialog.login()
def show_mainwindow(self):
if self.window_launched:
self.mainwindow.show()
else:
self.mainwindow.show_window_centralized()
def start_app(self): def start_app(self):
self.mainwindow = MainWindow() self.mainwindow = MainWindow()
self.launch_dialog.close() self.launch_dialog.close()
self.tray_icon = TrayIcon(self) self.tray_icon = TrayIcon(self)
self.tray_icon.exit_action.triggered.connect(self.exit_app) self.tray_icon.exit_action.triggered.connect(self.exit_app)
self.tray_icon.start_rare.triggered.connect(self.mainwindow.show) self.tray_icon.start_rare.triggered.connect(self.show_mainwindow)
self.tray_icon.activated.connect(self.tray) self.tray_icon.activated.connect(lambda r: self.show_mainwindow() if r == QSystemTrayIcon.DoubleClick else None)
if not self.args.silent: if not self.args.silent:
self.mainwindow.show() self.mainwindow.show_window_centralized()
self.window_launched = True
if shared.args.subparser == "launch": if shared.args.subparser == "launch":
if shared.args.app_name in [i.app_name for i in self.core.get_installed_list()]: if shared.args.app_name in [i.app_name for i in self.core.get_installed_list()]:
@ -176,7 +186,7 @@ class App(QApplication):
def exit_app(self, exit_code=0): def exit_app(self, exit_code=0):
# FIXME: Fix this with the downlaod tab redesign # FIXME: Fix this with the downlaod tab redesign
if self.mainwindow is not None: if self.mainwindow is not None:
if self.mainwindow.tab_widget.downloadTab.active_game is not None: if self.mainwindow.tab_widget.downloadTab.is_download_active:
question = QMessageBox.question( question = QMessageBox.question(
self.mainwindow, self.mainwindow,
self.tr("Close"), self.tr("Close"),
@ -185,8 +195,11 @@ class App(QApplication):
if question == QMessageBox.No: if question == QMessageBox.No:
return return
else: else:
# clear queue
self.mainwindow.tab_widget.downloadTab.queue_widget.update_queue([])
self.mainwindow.tab_widget.downloadTab.stop_download() self.mainwindow.tab_widget.downloadTab.stop_download()
# FIXME: End of FIXME # FIXME: End of FIXME
self.mainwindow.timer.stop()
self.mainwindow.hide() self.mainwindow.hide()
threadpool = QThreadPool.globalInstance() threadpool = QThreadPool.globalInstance()
threadpool.waitForDone() threadpool.waitForDone()

View file

@ -34,11 +34,17 @@ class MainWindow(QMainWindow):
if self.settings.value("save_size", False, bool): if self.settings.value("save_size", False, bool):
width, height = self.settings.value("window_size", (width, height), tuple) width, height = self.settings.value("window_size", (width, height), tuple)
# move the window outside the viewport self.resize(width, height)
self.move(-50000, -50000)
# show the window in order for it to get decorated, otherwise windowHandle() is null
self.show()
if not shared.args.offline:
self.rpc = DiscordRPC()
self.timer = QTimer()
self.timer.timeout.connect(self.timer_finished)
self.timer.start(1000)
def show_window_centralized(self):
self.show()
# get the margins of the decorated window # get the margins of the decorated window
margins = self.windowHandle().frameMargins() margins = self.windowHandle().frameMargins()
# get the screen the cursor is on # get the screen the cursor is on
@ -47,21 +53,12 @@ class MainWindow(QMainWindow):
screen_rect = current_screen.availableGeometry() screen_rect = current_screen.availableGeometry()
decor_width = margins.left() + margins.right() decor_width = margins.left() + margins.right()
decor_height = margins.top() + margins.bottom() decor_height = margins.top() + margins.bottom()
window_size = QSize(width, height).boundedTo(screen_rect.size() - QSize(decor_width, decor_height)) window_size = QSize(self.width(), self.height()).boundedTo(
screen_rect.size() - QSize(decor_width, decor_height))
# hide the window again because we don't want to show it at this point
self.hide()
self.resize(window_size) self.resize(window_size)
self.move(screen_rect.center() - self.rect().adjusted(0, 0, decor_width, decor_height).center()) self.move(screen_rect.center() - self.rect().adjusted(0, 0, decor_width, decor_height).center())
if not shared.args.offline:
self.rpc = DiscordRPC()
self.timer = QTimer()
self.timer.timeout.connect(self.timer_finished)
self.timer.start(1000)
def timer_finished(self): def timer_finished(self):
file_path = os.path.join(data_dir, "lockfile") file_path = os.path.join(data_dir, "lockfile")
if os.path.exists(file_path): if os.path.exists(file_path):
@ -89,4 +86,5 @@ class MainWindow(QMainWindow):
return return
elif self.offline: elif self.offline:
pass pass
e.accept() self.signals.exit_app.emit(0)
e.ignore()

View file

@ -221,6 +221,10 @@ class DownloadsTab(QWidget, Ui_DownloadsTab):
self.downloadTab.install_game(download_item) self.downloadTab.install_game(download_item)
self.games_tab.start_download(download_item.options.app_name) self.games_tab.start_download(download_item.options.app_name)
@property
def is_download_active(self):
return self.active_game is not None
class UpdateWidget(QWidget): class UpdateWidget(QWidget):
update_signal = pyqtSignal(InstallOptionsModel) update_signal = pyqtSignal(InstallOptionsModel)

View file

@ -61,7 +61,6 @@ class DlQueueWidget(QGroupBox):
dl_queue = [] dl_queue = []
def __init__(self): def __init__(self):
super(DlQueueWidget, self).__init__() super(DlQueueWidget, self).__init__()
self.setTitle(self.tr("Download Queue")) self.setTitle(self.tr("Download Queue"))
self.setLayout(QVBoxLayout()) self.setLayout(QVBoxLayout())