DEV Community

Jochem Stoel
Jochem Stoel

Posted on

2 1

Electron Tray application: How to reference target balloon in event handler of balloon-clicked event?

Electron Tray applications can show balloons using the Tray.displayBalloon method that takes an object with title, content and optional icon property.

To my knowledge, the balloon interface does not include a click or onClick property. The Tray class does have a balloon-click event that fires when a balloon is clicked as well as a balloon-closed and balloon-show event. However the event object passed to the callback function does not seem to include a reference to the balloon that dispatched the event. (the balloon that was displayed, clicked or closed)

tray.on('balloon-click', console.log)
tray.on('balloon-show', console.log)
tray.on('balloon-closed', console.log)
Enter fullscreen mode Exit fullscreen mode

Log:

    { preventDefault: [Function: preventDefault],
      sender:
       Tray {
         _events:
          { 'balloon-click': [Function],
            'balloon-show': [Function: consoleLog] },
         _eventsCount: 2 } }
Enter fullscreen mode Exit fullscreen mode

My Tray application sends balloon notifications from different sources. What happens when you click the balloon (where to navigate to or what window to open) kinda depends on what the balloon is saying.

I need a reference to the balloon that was clicked, not just that there was a balloon click somewhere at some point. It strongly expected this to be there.

I can think of many ways to implement a solution ranging from a simple wrapper function and an activeBalloon variable to an entire BalloonManager class but I don't feel like wasting my time if I just overlooked this in the Electron Tray API documentation.

This question was also asked on discuss.atom.io in August 2017

Source: [https://discuss.atom.io/t/tray-balloon-click-how-to-know-which-balloon-is-clicked/46744][2]

Redis image

Short-term memory for faster
AI agents 🤖💨

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

Top comments (0)

Dev Diairies image

User Feedback & The Pivot That Saved The Project ↪️

We’re following the journey of a dev team building on the Stellar Network as they go from hackathon idea to funded startup, testing their product in the real world and adapting as they go.

Watch full video 🎥

👋 Kindness is contagious

Explore this compelling article, highly praised by the collaborative DEV Community. All developers, whether just starting out or already experienced, are invited to share insights and grow our collective expertise.

A quick “thank you” can lift someone’s spirits—drop your kudos in the comments!

On DEV, sharing experiences sparks innovation and strengthens our connections. If this post resonated with you, a brief note of appreciation goes a long way.

Get Started