Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a dock icon notification indicator with Electron in OS X?

I don't actually know the thing's name, I am talking about the red dot on the right top corner of app icon.

Slack Notification

like image 488
previous_developer Avatar asked Aug 04 '15 15:08

previous_developer


1 Answers

I'll have to make some assumptions here because I don't own a Mac to test this with. I believe that those red dots on the corner of an app icon are referred to as badges. In Electron's App module there are methods to get/set the badge along with other dock features. Check out http://electron.atom.io/docs/v0.30.0/api/app/ for more information. Here are the relevant methods:

app.dock.setBadge(text)

text String Sets the string to be displayed in the dock’s badging area.

Note: This API is only available on Mac.

app.dock.getBadge()

Returns the badge string of the dock.

Note: This API is only available on Mac.

My guess is the code to produce the dot that you see in the example from Slack that you provided would look something like this:

var app = require('app');
app.dock.setBadge('.');
like image 145
Shawn Rakowski Avatar answered Oct 26 '22 15:10

Shawn Rakowski