Use icon.visible to show or hide the tray icon on all systems
On Linux, pystray's icon.stop() currently doesn't work well with the AppIndicator backend. So, instead of destroying the icon when the user restores from tray (only to later re-create it when the user minimizes to tray again), we have the option to control the icon's visibility instead! Luckily, that works on Windows too! Note that for this change to work properly on Linux, we need to switch to the master version of pystray, because we need this specific fix: https://github.com/moses-palmer/pystray/commit/5943ed4e19be48224cf39b70444de8ffe22c23ce After pystray releases a version newer than 0.19.4, we can switch back. Co-authored-by: DevilXD <bartosz.peszek@gmail.com>
This commit is contained in:
1 parent
7a07e1a9e4
commit
f8c0dba1ee
2 files changed
+12
-11
No files matched your search
@@ -1048,11 +1048,9 @@ class TrayIcon:
|
|||||||
self._button.grid(column=0, row=0, sticky="ne")
|
self._button.grid(column=0, row=0, sticky="ne")
|
||||||
|
|
||||||
def __del__(self) -> None:
|
def __del__(self) -> None:
|
||||||
|
self.stop()
|
||||||
self.icon_image.close()
|
self.icon_image.close()
|
||||||
|
|
||||||
def is_tray(self) -> bool:
|
|
||||||
return self.icon is not None
|
|
||||||
|
|
||||||
def get_title(self, drop: TimedDrop | None) -> str:
|
def get_title(self, drop: TimedDrop | None) -> str:
|
||||||
if drop is None:
|
if drop is None:
|
||||||
return self.TITLE
|
return self.TITLE
|
||||||
@@ -1064,8 +1062,7 @@ class TrayIcon:
|
|||||||
f"{drop.progress:.1%} ({campaign.claimed_drops}/{campaign.total_drops})"
|
f"{drop.progress:.1%} ({campaign.claimed_drops}/{campaign.total_drops})"
|
||||||
)
|
)
|
||||||
|
|
||||||
def start(self):
|
def _start(self):
|
||||||
if self.icon is None:
|
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
drop = self._manager.progress._drop
|
drop = self._manager.progress._drop
|
||||||
|
|
||||||
@@ -1091,13 +1088,16 @@ class TrayIcon:
|
|||||||
self._manager.close()
|
self._manager.close()
|
||||||
|
|
||||||
def minimize(self):
|
def minimize(self):
|
||||||
if not self.is_tray():
|
if self.icon is None:
|
||||||
self.start()
|
self._start()
|
||||||
|
else:
|
||||||
|
self.icon.visible = True
|
||||||
self._manager._root.withdraw()
|
self._manager._root.withdraw()
|
||||||
|
|
||||||
def restore(self):
|
def restore(self):
|
||||||
if self.is_tray():
|
if self.icon is not None:
|
||||||
self.stop()
|
# self.stop()
|
||||||
|
self.icon.visible = False
|
||||||
self._manager._root.deiconify()
|
self._manager._root.deiconify()
|
||||||
|
|
||||||
def notify(
|
def notify(
|
||||||
@@ -1107,7 +1107,7 @@ class TrayIcon:
|
|||||||
if not self._manager._twitch.settings.tray_notifications:
|
if not self._manager._twitch.settings.tray_notifications:
|
||||||
return None
|
return None
|
||||||
if self.icon is not None:
|
if self.icon is not None:
|
||||||
icon = self.icon
|
icon = self.icon # nonlocal scope bind
|
||||||
|
|
||||||
async def notifier():
|
async def notifier():
|
||||||
icon.notify(message, title)
|
icon.notify(message, title)
|
||||||
|
|||||||
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
aiohttp>2.0,<4.0
|
aiohttp>2.0,<4.0
|
||||||
Pillow
|
Pillow
|
||||||
pystray
|
# TODO: switch back to a stable pystray release when a version newer than v0.19.4 is out
|
||||||
|
pystray@git+https://github.com/moses-palmer/pystray.git@903836104f8b1a2979f4fa5a333870ef7b075992
|
||||||
# selenium-wire
|
# selenium-wire
|
||||||
# undetected-chromedriver
|
# undetected-chromedriver
|
||||||
# this is installed only on windows
|
# this is installed only on windows
|
||||||
|
|||||||
Reference in new issue
Block a user