moses-palmer / pystray

GNU General Public License v3.0
473 stars 59 forks source link

run_detached doesn't show an icon #107

Closed danrossi closed 2 years ago

danrossi commented 2 years ago

I am desperately trying to get pystray working with an asyncio application and send click events back to the app. The callbacks have no event loop and fail. I discovered this other method so run the icon with uvicorn app launched. But the icon doesn't show up. I get the icon object returned. But no icon is showing.

icon.run_detached(self.on_setup)

The only way to get it working is to run this before uvicorn is launched. But they cannot communicate to eachother. The callback complains of not having an event loop running to message the app of icon clicks

update_thread = threading.Thread(target=app.startSystray)
update_thread.start()
danrossi commented 2 years ago

this seems to work for me. Run the main loop through this method

loop.create_task(run_in_threadpool(app.startSystray))
loop.create_task(server.serve())

loop.run_forever()