Jorricks / macos-notifications

Create interactable notifications in the Notification Centre on any Mac using Python
https://jorricks.github.io/macos-notifications/
MIT License
74 stars 4 forks source link

One program, two notifications: one notification seems to dismiss the other #18

Closed dstromberg closed 10 months ago

dstromberg commented 1 year ago

I don't really know much about MacOS' notifications, but should one notification that's already up, be knocked down by a second notification?

EG, in the snippet below, I've got 2 notifications in the one program, each notification having 1 callback - but I can't seem to find where to acknowledge "the other one".

Should I block until the first is acknowledged before submitting the second? Is there a way to make the notifications "pile up"?

#!/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!')

Thanks!

dstromberg commented 1 year ago

It also seems to happen if I just bring up one notification, but then switch to another virtual desktop in mission control - the notification goes away without me (intentionally) dismissing it. Is this by (Apple's) design?

dstromberg commented 10 months ago

I eventually found: System Settings -> Notifications -> Python ...in which you can select Alerts instead of the default Banners, to get the desired behavior.

dstromberg commented 10 months ago

I consider this done.