From 5cd942b9e856512b19ebb1eabea6053a295352e1 Mon Sep 17 00:00:00 2001 From: Dummerle <44114474+Dummerle@users.noreply.github.com> Date: Wed, 22 Dec 2021 21:21:49 +0100 Subject: [PATCH] Fix silent mode + refactoring: move window to center, when showing window --- rare/app.py | 27 ++++++++++++----- rare/components/main_window.py | 30 +++++++++---------- rare/components/tabs/downloads/__init__.py | 4 +++ .../tabs/downloads/dl_queue_widget.py | 1 - 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/rare/app.py b/rare/app.py index 2cb15eef..5bc0cd44 100644 --- a/rare/app.py +++ b/rare/app.py @@ -49,9 +49,14 @@ def excepthook(exc_type, exc_value, exc_tb): class App(QApplication): + mainwindow: MainWindow = None + tray_icon: QSystemTrayIcon = None + def __init__(self): super(App, self).__init__(sys.argv) self.args = shared.args # add some options + self.window_launched = False + self.setQuitOnLastWindowClosed(False) # init Legendary try: @@ -81,8 +86,6 @@ class App(QApplication): self.core.lgd.save_config() # set Application name for settings - self.mainwindow = None - self.tray_icon = None self.launch_dialog = None self.setApplicationName("Rare") self.setOrganizationName("Rare") @@ -90,7 +93,7 @@ class App(QApplication): 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( lambda title: self.tray_icon.showMessage( @@ -142,16 +145,23 @@ class App(QApplication): 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): self.mainwindow = MainWindow() self.launch_dialog.close() self.tray_icon = TrayIcon(self) self.tray_icon.exit_action.triggered.connect(self.exit_app) - self.tray_icon.start_rare.triggered.connect(self.mainwindow.show) - self.tray_icon.activated.connect(self.tray) + self.tray_icon.start_rare.triggered.connect(self.show_mainwindow) + self.tray_icon.activated.connect(lambda r: self.show_mainwindow() if r == QSystemTrayIcon.DoubleClick else None) 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.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): # FIXME: Fix this with the downlaod tab redesign 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( self.mainwindow, self.tr("Close"), @@ -185,8 +195,11 @@ class App(QApplication): if question == QMessageBox.No: return else: + # clear queue + self.mainwindow.tab_widget.downloadTab.queue_widget.update_queue([]) self.mainwindow.tab_widget.downloadTab.stop_download() # FIXME: End of FIXME + self.mainwindow.timer.stop() self.mainwindow.hide() threadpool = QThreadPool.globalInstance() threadpool.waitForDone() diff --git a/rare/components/main_window.py b/rare/components/main_window.py index f3eb16fe..4a190745 100644 --- a/rare/components/main_window.py +++ b/rare/components/main_window.py @@ -34,11 +34,17 @@ class MainWindow(QMainWindow): if self.settings.value("save_size", False, bool): width, height = self.settings.value("window_size", (width, height), tuple) - # move the window outside the viewport - self.move(-50000, -50000) - # show the window in order for it to get decorated, otherwise windowHandle() is null - self.show() + self.resize(width, height) + 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 margins = self.windowHandle().frameMargins() # get the screen the cursor is on @@ -47,21 +53,12 @@ class MainWindow(QMainWindow): screen_rect = current_screen.availableGeometry() decor_width = margins.left() + margins.right() decor_height = margins.top() + margins.bottom() - window_size = QSize(width, 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() + window_size = QSize(self.width(), self.height()).boundedTo( + screen_rect.size() - QSize(decor_width, decor_height)) self.resize(window_size) 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): file_path = os.path.join(data_dir, "lockfile") if os.path.exists(file_path): @@ -89,4 +86,5 @@ class MainWindow(QMainWindow): return elif self.offline: pass - e.accept() + self.signals.exit_app.emit(0) + e.ignore() diff --git a/rare/components/tabs/downloads/__init__.py b/rare/components/tabs/downloads/__init__.py index ea37fc2f..f1bf47d0 100644 --- a/rare/components/tabs/downloads/__init__.py +++ b/rare/components/tabs/downloads/__init__.py @@ -221,6 +221,10 @@ class DownloadsTab(QWidget, Ui_DownloadsTab): self.downloadTab.install_game(download_item) 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): update_signal = pyqtSignal(InstallOptionsModel) diff --git a/rare/components/tabs/downloads/dl_queue_widget.py b/rare/components/tabs/downloads/dl_queue_widget.py index b6baa6e6..c9da6b6e 100644 --- a/rare/components/tabs/downloads/dl_queue_widget.py +++ b/rare/components/tabs/downloads/dl_queue_widget.py @@ -61,7 +61,6 @@ class DlQueueWidget(QGroupBox): dl_queue = [] def __init__(self): - super(DlQueueWidget, self).__init__() self.setTitle(self.tr("Download Queue")) self.setLayout(QVBoxLayout())