From 4e6008a8f7bc03d0d4f23a446a31f87252b04c10 Mon Sep 17 00:00:00 2001 From: loathingKernel <142770+loathingKernel@users.noreply.github.com> Date: Fri, 19 Jan 2024 17:17:31 +0200 Subject: [PATCH] TrayIcon: Generic notifications * Add a notification when starting a download too --- rare/components/tabs/downloads/__init__.py | 18 +++++++++++++----- rare/components/tabs/downloads/thread.py | 11 +++++------ rare/components/tray_icon.py | 13 +++---------- rare/models/signals.py | 4 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/rare/components/tabs/downloads/__init__.py b/rare/components/tabs/downloads/__init__.py index c9932f13..c7bb2216 100644 --- a/rare/components/tabs/downloads/__init__.py +++ b/rare/components/tabs/downloads/__init__.py @@ -194,7 +194,7 @@ class DownloadsTab(QWidget): if item.expired: self.__refresh_download(item) return - dl_thread = DlThread(item, self.rcore.get_game(item.options.app_name), self.core, self.args.debug) + dl_thread = DlThread(item, rgame, self.core, self.args.debug) dl_thread.result.connect(self.__on_download_result) dl_thread.progress.connect(self.__on_download_progress) dl_thread.finished.connect(dl_thread.deleteLater) @@ -206,6 +206,11 @@ class DownloadsTab(QWidget): RareCore.instance().image_manager().get_pixmap(rgame.app_name, True) ) + self.signals.application.notify.emit( + self.tr("Downloads"), + self.tr("Starting: \"{}\" is now downloading.").format(rgame.app_title) + ) + @pyqtSlot(UIUpdate, object) def __on_download_progress(self, ui_update: UIUpdate, dl_size: int): self.download_widget.ui.progress_bar.setValue(int(ui_update.progress)) @@ -231,16 +236,19 @@ class DownloadsTab(QWidget): if result.shortcut and desktop_links_supported(): if not create_desktop_link( app_name=result.options.app_name, - app_title=result.shortcut_title, - link_name=result.shortcut_name, + app_title=result.app_title, + link_name=result.folder_name, link_type="desktop", ): # maybe add it to download summary, to show in finished downloads logger.error(f"Failed to create desktop link on {platform.system()}") else: - logger.info(f"Created desktop link {result.shortcut_name} for {result.options.app_name}") + logger.info(f"Created desktop link {result.folder_name} for {result.app_title}") - self.signals.application.notify.emit(result.options.app_name) + self.signals.application.notify.emit( + self.tr("Downloads"), + self.tr("Finished: \"{}\" is now playable.").format(result.app_title), + ) if self.updates_group.contains(result.options.app_name): self.updates_group.set_widget_enabled(result.options.app_name, True) diff --git a/rare/components/tabs/downloads/thread.py b/rare/components/tabs/downloads/thread.py index 9309ef25..7aaa7486 100644 --- a/rare/components/tabs/downloads/thread.py +++ b/rare/components/tabs/downloads/thread.py @@ -34,8 +34,8 @@ class DlResultModel: sync_saves: bool = False tip_url: str = "" shortcut: bool = False - shortcut_name: str = "" - shortcut_title: str = "" + folder_name: str = "" + app_title: str = "" class DlThread(QThread): @@ -151,10 +151,9 @@ class DlThread(QThread): self.item.download.repair_file, ) - if not self.item.options.update and self.item.options.create_shortcut: - result.shortcut = True - result.shortcut_name = self.rgame.folder_name - result.shortcut_title = self.rgame.app_title + result.shortcut = not self.item.options.update and self.item.options.create_shortcut + result.folder_name = self.rgame.folder_name + result.app_title = self.rgame.app_title self.__finish(result) diff --git a/rare/components/tray_icon.py b/rare/components/tray_icon.py index a0c49aa9..8b40cca1 100644 --- a/rare/components/tray_icon.py +++ b/rare/components/tray_icon.py @@ -59,17 +59,10 @@ class TrayIcon(QSystemTrayIcon): last_played.sort(key=lambda g: g.metadata.last_played, reverse=True) return last_played[0:5] - @pyqtSlot(str) - def notify(self, app_name: str): + @pyqtSlot(str, str) + def notify(self, title: str, body: str): if self.settings.value("notification", True, bool): - self.showMessage( - self.tr("Download finished"), - self.tr("Download finished. {} is playable now").format( - self.rcore.get_game(app_name).app_title - ), - self.Information, - 4000, - ) + self.showMessage(f"{QApplication.applicationName()} - {title}", body, QSystemTrayIcon.Information, 4000) @pyqtSlot() def update_actions(self): diff --git a/rare/models/signals.py b/rare/models/signals.py index 3c614237..522ad7f9 100644 --- a/rare/models/signals.py +++ b/rare/models/signals.py @@ -11,8 +11,8 @@ class GlobalSignals: class ApplicationSignals(QObject): # int: exit code quit = pyqtSignal(int) - # str: app_title - notify = pyqtSignal(str) + # str: title, str: body + notify = pyqtSignal(str, str) # none prefix_updated = pyqtSignal() # none