#!/usr/bin/python3
import notify2
from time import sleep
from playsound import playsound

NAME = 'Eye Strain Reminder'
MESSAGE = 'Friendly reminder to observe the 20-20-20 rule'
TIMEOUT = 20
MILLISECOND = 1000
MINUTE = 60

def init():
    print("Initializing EyeStrainReminder...")
    notify2.init(NAME)

def uninit():
    notify2.uninit()

def wait():
    sleep(TIMEOUT*MINUTE)

def send_notification():
    print(MESSAGE)
    notification = notify2.Notification(NAME, MESSAGE, "notification-device-eject")
    notification.set_timeout(TIMEOUT * MILLISECOND)
    notification.set_urgency(notify2.URGENCY_LOW)
    notification.show()
    playsound('files/default.wav')
    sleep(TIMEOUT)
    notification.close()
    playsound('files/default.wav')

def main():
    init()
    while 1:
        wait()
        send_notification()
    uninit()

if __name__ == '__main__':
    main()