1
0
Fork 0
mirror of synced 2024-06-29 03:31:06 +12:00
Rare/rare/components/tray_icon.py

87 lines
3.1 KiB
Python
Raw Normal View History

from logging import getLogger
from typing import List
from PyQt5.QtCore import pyqtSignal, pyqtSlot, QSettings
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu, QAction, QApplication
2021-04-23 00:34:06 +12:00
from rare.models.options import options
from rare.shared import RareCore
logger = getLogger("TrayIcon")
2021-04-08 00:46:27 +12:00
class TrayIcon(QSystemTrayIcon):
# none:
show_app: pyqtSignal = pyqtSignal()
# int: exit code
exit_app: pyqtSignal = pyqtSignal(int)
def __init__(self, parent=None):
super(TrayIcon, self).__init__(parent=parent)
self.__parent = parent
self.rcore = RareCore.instance()
self.core = RareCore.instance().core()
self.settings = QSettings()
2021-12-10 09:59:07 +13:00
self.setIcon(QIcon(":/images/Rare.png"))
2021-04-08 00:46:27 +12:00
self.setVisible(True)
self.setToolTip(QApplication.applicationName())
2021-04-08 00:46:27 +12:00
self.menu = QMenu()
self.show_action = QAction(QApplication.applicationName())
self.show_action.triggered.connect(self.show_app)
self.menu.addAction(self.show_action)
2021-04-08 00:46:27 +12:00
self.menu.addSeparator()
self.text_action = QAction("Quick launch")
self.text_action.setEnabled(False)
self.menu.addAction(self.text_action)
# We need to reference this separator to add game actions before it
self.separator = self.menu.addSeparator()
self.exit_action = QAction(self.tr("Quit"))
self.exit_action.triggered.connect(lambda: self.exit_app.emit(0))
self.menu.addAction(self.exit_action)
self.game_actions: List[QAction] = []
self.update_actions()
2021-04-08 00:46:27 +12:00
self.setContextMenu(self.menu)
self.signals = RareCore.instance().signals()
self.signals.game.uninstalled.connect(self.remove_button)
self.signals.application.notify.connect(self.notify)
self.signals.application.update_tray.connect(self.update_actions)
def last_played(self) -> List:
last_played = [game for game in self.rcore.games if (game.metadata and game.is_installed)]
last_played.sort(key=lambda g: g.metadata.last_played, reverse=True)
return last_played[:5]
@pyqtSlot(str, str)
def notify(self, title: str, body: str):
if self.settings.value(*options.notification):
2024-01-25 04:58:26 +13:00
self.showMessage(f"{title} - {QApplication.applicationName()}", body, QSystemTrayIcon.Information, 4000)
@pyqtSlot()
def update_actions(self):
for action in self.game_actions:
action.deleteLater()
self.game_actions.clear()
for rgame in self.last_played():
a = QAction(rgame.app_title)
a.setProperty("app_name", rgame.app_name)
a.triggered.connect(
DownloadsTab: Refactor downloads tab When updates are queued, they are removed from the update's list. An exceptions is made when the queued item comes from repairing (without updating), in which case the update is disabled for the runtime. A queued item can be either removed (if it is an update it will be added back to the updates groups) or forced to be updated now. If a queued item is forced, the currently running item will be added to the front of the queue. Downloads will be queued if there is no active download but there is a queue already. The download thread is now responsible for emitting the progress to `RareGame` InstallDialog: Pass `RareGame` and `InstallOptionsModel` only as arguments. The `update`, `repair` and `silent` arguments are already part of `InstallOptionsModel` `RareGame` is used to query information about the game. InstallInfoWorker: Pass only `InstallOptionsModel` as argument Emit `InstallQueueItemModel` as result, to re-use the worker when queuing stopped games RareGame: Query and store metadata property about entitlement grant date RareGame: Add `RareEosOverlay` class that imitates `RareGame` to handle the overlay LibraryWidgetController: Remove dead signal routing code, these signals are handled by `RareGame` Directly parent library widgets instead of reparenting them GameWidgets: Remove unused signals EOSGroup: Set install location based on preferences and use EOSOverlayApp from legendary GamesTab: Connect the `progress` signals of dlcs to the base game's signals GamesTab: Remove dead code GlobalSignals: Remove `ProgresSignals` RareCore: Mangle internal signleton's names Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com>
2023-01-21 13:15:06 +13:00
lambda: self.rcore.get_game(self.sender().property("app_name")).launch()
)
self.menu.insertAction(self.separator, a)
self.game_actions.append(a)
@pyqtSlot(str)
def remove_button(self, app_name: str):
if action := next((i for i in self.game_actions if i.property("app_name") == app_name), None):
self.game_actions.remove(action)
action.deleteLater()