Skip to content

Commit

Permalink
Use tray from di
Browse files Browse the repository at this point in the history
  • Loading branch information
nietoga committed Mar 24, 2024
1 parent c082d9a commit bc8b22b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
external_services_config.configure()
mail_service = ExternalServices.mail_service
user_data = ExternalServices.user_data_provider
Tray = ExternalServices.Tray

DEFAULT_MAIL_SENDER = config.get("DEFAULT_MAIL_SENDER")

Expand Down Expand Up @@ -81,22 +82,19 @@ def run_main_window():


def run_system_tray():
tray = sg.SystemTray(
menu=["", ["Open", "Exit"]],
filename=file_utils.get_absolute_path("rat.ico"),
)

while True:
menu_item = tray.read(0)

if menu_item == "Exit":
break
elif menu_item in [sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED, "Open"]:
tray.hide()
run_main_window()
tray.un_hide()

tray.close()
def close_tray(tray: Tray):
tray.close()

def open_window(tray: Tray):
tray.set_visible(False)
run_main_window()
tray.set_visible(True)

tray = Tray(file_utils.get_absolute_path("rat.ico"), ["Open", "Exit"])
tray.attach_listener("Exit", close_tray)
tray.attach_listener("Open", open_window)
tray.attach_listener(Tray.DOUBLE_CLICK_EVENT, open_window)
tray.run()


def exit_application(signum, frame):
Expand Down

0 comments on commit bc8b22b

Please sign in to comment.