#!/usr/bin/env python3

import sys
import time

from mac_notifications import client


class Callback:
    def __init__(self):
        self.called_back = False

    def callback(self):
        self.called_back = True

    def __str__(self):
        if self.called_back:
            return 'callback called'
        else:
            return 'callback not called'

    __repr__ = __str__


if __name__ == '__main__':
    popup_list = []
    for i in range(2):
        cb = Callback()
        popup_list.append(cb)
        client.create_notification(
            title="title {}".format(i),
            subtitle="subtitle",
            icon=None,
            action_button_str="Acknowledge",
            action_callback=cb.callback,
        )
    while not all(p.called_back for p in popup_list):
        print('waiting...:', popup_list)
        sys.stdout.flush()
        time.sleep(1)
    client.stop_listening_for_callbacks()
    print('hello!')