Fix silent mode + refactoring: move window to center, when showing window
This commit is contained in:
parent
67003bb1b2
commit
5cd942b9e8
27
rare/app.py
27
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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in a new issue