Skip to content

Commit

Permalink
Tray icon refactor, now hide on termination
Browse files Browse the repository at this point in the history
  • Loading branch information
IGalat committed Feb 19, 2024
1 parent ee37a33 commit f65a819
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/tapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ def start(blocking: bool = True) -> None:
init()
_initializer.start(_listeners)

# If tray icon is on, it will be blocking anyway, which is required for Mac compatibility.
# So this is for cases where it's not on.
# But boolean flag is there mostly for testing.
# Should be blocking for normal usage, flag is for testing.
# If tray icon is on, it will be blocking anyway.
if blocking:
while True:
_time.sleep(1000000)
2 changes: 1 addition & 1 deletion src/tapper/boot/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ def start(listeners: list[SignalListener]) -> None:
controller._start()
for listener in listeners:
listener.start()
if config.tray_icon: # this is blocking
if config.tray_icon and config.os != "darwin": # No tray for MacOS
tray_icon.create()
9 changes: 6 additions & 3 deletions src/tapper/boot/tray_icon.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import atexit
import os
from typing import Any

Expand Down Expand Up @@ -28,6 +29,8 @@ def create() -> None:

stray = pystray.Icon("tapper", logo, menu=make_menu())

# this is blocking. Not running in separate thread for Mac compatibility
# https://pystray.readthedocs.io/en/latest/usage.html
stray.run()
@atexit.register
def remove_stray() -> None:
stray.visible = False

stray.run_detached()
5 changes: 4 additions & 1 deletion src/tapper/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
"""

tray_icon = True
"""Icon in bottom right in your task bar lets you know tapper is running and allows control."""
"""
Icon in bottom right in your task bar lets you know tapper is running and allows control.
Not implemented for MacOS.
"""

"""
------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions src/tapper/helper/controls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import atexit
import os
import signal
import subprocess
Expand All @@ -20,4 +21,5 @@ def terminate() -> None:


def _terminate() -> None:
atexit._run_exitfuncs()
os.kill(os.getpid(), signal.SIGINT)

0 comments on commit f65a819

Please sign in to comment.