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