Added "Exit" functionality

This commit is contained in:
Abhorrent_Anger 2019-10-29 19:25:32 +02:00 committed by Mārtiņš Kurmis
parent 5e7d11470e
commit f9037c8acd
1 changed files with 9 additions and 2 deletions

View File

@ -8,7 +8,7 @@ import notify2
import pystray
from PIL import Image
from playsound import playsound
from pystray import MenuItem as item
from pystray import Menu as menu, MenuItem as item
NAME = 'Eye Strain Reminder'
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
@ -29,7 +29,7 @@ def create_tray_icon():
image = get_image()
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
icon.run()
def update_icon():
global icon
image = get_image()
@ -44,6 +44,8 @@ def generate_menu_items():
menu_items = []
menu_items.append(item('Mute' if not mute else 'Unmute', toggle_mute))
menu_items.append(item('Do Not Disturb' if not disable_notifs else 'Enable Notifications', toggle_notifications))
menu_items.append(menu.SEPARATOR)
menu_items.append(item('Exit', exit))
return menu_items
def toggle_mute():
@ -57,6 +59,11 @@ def toggle_notifications():
update_menu()
update_icon()
def exit():
global icon
icon.stop()
os._exit(0)
def update_menu():
global icon
icon.menu = generate_menu_items()