Implement tray drop claim notifications

This commit is contained in:
DevilXD
2022-01-11 22:23:58 +01:00
parent 1aba5984d2
commit 9f7c865abb
2 changed files with 19 additions and 2 deletions

15
gui.py
View File

@@ -727,6 +727,17 @@ class TrayIcon:
self.stop()
self._manager._root.deiconify()
def notify(self, message: str, title: Optional[str] = None, duration: float = 10):
if self._icon is not None:
icon = self._icon
async def notifier():
icon.notify(message, title)
await asyncio.sleep(duration)
icon.remove_notification()
asyncio.create_task(notifier())
class GUIManager:
def __init__(self, twitch: Twitch):
@@ -942,6 +953,10 @@ if __name__ == "__main__":
gui.channels.set_watching(channel)
gui._root.update()
gui.channels.get_selection()
# Tray
# gui.tray.minimize()
# await asyncio.sleep(1)
# gui.tray.notify("Bounty Coins (3/7)", "Mined Drop")
# Drop progress
drop = create_drop("Wardrobe Cleaning", "Fancy Pants", 2, 7, 239, 240)
gui.progress.display(drop)

View File

@@ -434,10 +434,12 @@ class Twitch:
campaign = drop.campaign
mined = await drop.claim()
if mined:
self.gui.print(
f"Claimed drop: {drop.rewards_text()} "
claim_text = (
f"{drop.rewards_text()} "
f"({campaign.claimed_drops}/{campaign.total_drops})"
)
self.gui.print(f"Claimed drop: {claim_text}")
self.gui.tray.notify(claim_text, "Mined Drop")
else:
logger.error(f"Drop claim failed! Drop ID: {drop_id}")
if not mined or campaign.remaining_drops == 0: