Refactoring, delayed message
This commit is contained in:
parent
adccf133e1
commit
4c0e419263
|
@ -9,6 +9,7 @@ from PIL import Image
|
||||||
|
|
||||||
NAME = 'Eye Strain Reminder'
|
NAME = 'Eye Strain Reminder'
|
||||||
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
|
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
|
||||||
|
MESSAGE_MISSED = 'Missed notification(s), resuming countdown'
|
||||||
TIMEOUT = 20
|
TIMEOUT = 20
|
||||||
MILLISECOND = 1000
|
MILLISECOND = 1000
|
||||||
MINUTE = 60
|
MINUTE = 60
|
||||||
|
@ -18,10 +19,13 @@ icon = None
|
||||||
mute = False
|
mute = False
|
||||||
disable_notifications = False
|
disable_notifications = False
|
||||||
|
|
||||||
def toggle_mute():
|
def init():
|
||||||
global mute
|
global icon
|
||||||
mute = True if not mute else False
|
image = Image.open(f"{DIR}/files/eye_light.png")
|
||||||
update_menu()
|
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
|
||||||
|
icon.run()
|
||||||
|
print("Initializing EyeStrainReminder...")
|
||||||
|
notify2.init(NAME)
|
||||||
|
|
||||||
def generate_menu_items():
|
def generate_menu_items():
|
||||||
menu_items = []
|
menu_items = []
|
||||||
|
@ -31,40 +35,46 @@ def generate_menu_items():
|
||||||
menu_items.append(item('Unmute', toggle_mute))
|
menu_items.append(item('Unmute', toggle_mute))
|
||||||
return menu_items
|
return menu_items
|
||||||
|
|
||||||
|
def toggle_mute():
|
||||||
|
global mute
|
||||||
|
mute = True if not mute else False
|
||||||
|
update_menu()
|
||||||
|
|
||||||
def update_menu():
|
def update_menu():
|
||||||
global icon
|
global icon
|
||||||
icon.menu = generate_menu_items()
|
icon.menu = generate_menu_items()
|
||||||
icon.update_menu()
|
icon.update_menu()
|
||||||
|
|
||||||
def init():
|
|
||||||
global icon
|
|
||||||
image = Image.open(f"{DIR}/files/eye_light.png")
|
|
||||||
icon = pystray.Icon(NAME, image, NAME, generate_menu_items())
|
|
||||||
icon.run()
|
|
||||||
print("Initializing EyeStrainReminder...")
|
|
||||||
notify2.init(NAME)
|
|
||||||
|
|
||||||
def uninit():
|
def uninit():
|
||||||
notify2.uninit()
|
notify2.uninit()
|
||||||
|
|
||||||
def wait():
|
def wait():
|
||||||
#sleep(TIMEOUT*MINUTE)
|
sleep(TIMEOUT*MINUTE)
|
||||||
pass
|
#pass
|
||||||
|
|
||||||
def play_sound():
|
|
||||||
if not mute:
|
|
||||||
playsound(f"{DIR}/files/default.wav")
|
|
||||||
|
|
||||||
def send_notification():
|
def send_notification():
|
||||||
|
if not disable_notifications:
|
||||||
|
notify(MESSAGE)
|
||||||
|
else:
|
||||||
|
print("Notifications are disabled, waiting for an enable...")
|
||||||
|
while disable_notifications:
|
||||||
|
sleep(10)
|
||||||
|
notify(MESSAGE_MISSED)
|
||||||
|
|
||||||
|
def notify(message):
|
||||||
print(MESSAGE)
|
print(MESSAGE)
|
||||||
notification = notify2.Notification(NAME, MESSAGE, "notification-device-eject")
|
notification = notify2.Notification(NAME, message, "notification-device-eject")
|
||||||
notification.set_timeout(TIMEOUT * MILLISECOND)
|
notification.set_timeout(TIMEOUT * MILLISECOND)
|
||||||
notification.set_urgency(notify2.URGENCY_LOW)
|
notification.set_urgency(notify2.URGENCY_LOW)
|
||||||
notification.show()
|
notification.show()
|
||||||
play_sound()
|
play_sound()
|
||||||
sleep(TIMEOUT)
|
sleep(TIMEOUT)
|
||||||
notification.close()
|
notification.close()
|
||||||
play_sound()
|
play_sound()
|
||||||
|
|
||||||
|
def play_sound():
|
||||||
|
if not mute:
|
||||||
|
playsound(f"{DIR}/files/default.wav")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
init()
|
init()
|
||||||
|
|
Loading…
Reference in New Issue