samschott / desktop-notifier

Python library for cross-platform desktop notifications
https://desktop-notifier.readthedocs.io
MIT License
92 stars 10 forks source link

Callbacks on Windows #120

Open Joustie opened 6 months ago

Joustie commented 6 months ago

Description

I am trying the callback mechanism using the Et tu brutus example on Windows. There is no feedback after responding to the notification, I checked if the terminal was hanging by hitting enter a few times, but no, the callbacks don't seem to be executed.

Any special things I forgot for Windows? It works on my mac...

This script saved as send.py

import asyncio
from desktop_notifier import DesktopNotifier, Urgency, Button, ReplyField

notifier = DesktopNotifier()

async def main():
  await notifier.send(
      title="Julius Caesar",
      message="Et tu, Brute?",
      urgency=Urgency.Critical,
      buttons=[
        Button(
          title="Mark as read",
          on_pressed=lambda: print("Marked as read")),
      ],
      reply_field=ReplyField(
        title="Reply",
        button_title="Send",
        on_replied=lambda text: print("Brutus replied:", text),
      ),
      on_clicked=lambda: print("Notification clicked"),
      on_dismissed=lambda: print("Notification dismissed"),
      sound=True,
  )

loop = asyncio.get_event_loop()
loop.create_task(main())
loop.run_forever()

Executed python send.py

Then entered answer in the textbox and clicked send

Screen Recording 2024-03-15 at 11 07 55

michelcrypt4d4mus commented 3 months ago

not an expert but you may need to call asyncio.set_event_loop_policy() as is done in the example doc for macOS? while it's a totally unrelated package i know Twisted has special policy requirements around using asyncio on Windows for some python versions.