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

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

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('.');

you can also try this
app.setBadgeCount(numberOfNotifiations)
What I usually do is simply increase the current badge count by 1, like so:
app.setBadgeCount(app.getBadgeCount() + 1)
see https://electron.atom.io/docs/all/#appsetbadgecountcount-linux-macos

Related

Find Window By Name and Take a Screenshot of the Window

I would like to take a screenshot of an open window / app. The environment might have a multiple displays or a single display as well as the application can be a full screen or windowed.
Here are the list of things I need to be able to get it right;
Find a Window by process name, for example app.exe.
Take a full screenshot of the app.
Take a portioned screenshot. Such as only top right corner with determined width and height.
It looks like github.com/lxn/win provides some functionality but not sure what exactly I need to use to get it done as I'm not familiar with WIN API or how to use it at all (not a Win user).
I looked into github.com/kbinani/screenshot but it takes a screenshot of a desktop of given screen index. Put me in a bit of right direction but couldn't get it done.
I'd appreciate any help in that matter.

show NSUserNotification additionalActions on click

In the image above you can see two notifications on OS X. The first one is from my app and the second is from Apple's Reminders.app. In the image you can see the otherButtonTitle 'Complete' and the actionButtonTitle 'Later'.
The second notification, i.e. the one from Reminders.app behaves quite differently. It gets this little arrow pointing downwards on mouse over indicating that there are more actions when clicked. And indeed, you just need to click once on 'Later' and it will give you a couple more options to choose from.
However, I can't get the same behavior to work for my notification. I don't get the little arrow on mouse over and I don't get more options displayed from a single click on 'Later' (notification just gets dismissed). More options only get displayed when holding down the mouse button on 'Later' which is not obvious.
Am I missing something obvious here? How can I get my notification to have exactly the same as the ones from the Reminders.app?
While trying to find a solution for the same problem I found this nice explanation for the NSUserNotificationPrivate class that explains how the Reminders app does it.
https://github.com/indragiek/NSUserNotificationPrivate
If the notification type is set to "Alert", the alternateActionButtonTitles property lets you set an array of additional menu item titles to be shown in an action menu that can be accessed by hovering on the Action button and clicking on the arrow.
Once a notification is handled, the index of the action can be retrieved using the _alternateActionIndex property.
So they are using a private API. As the site's disclaimer say using any of this will result in your app being rejected from the MAS and potentially breaking if the APIs change.

How do I set program title and icon in Clutter toolkit?

I have recently been learning how to program with the Clutter GUI toolkit. One thing I haven't been able to figure out is how to set the programs title and icon for the window manager.
As illustrated in the image below, Gnome Shell says that the program name is "Unknown" and that the program does not have an icon.
So, how do I do this?
you cannot do this from Clutter: the windowing system API inside Clutter only allows basic operations.
if you want proper integration in a windowing system you should use Clutter-GTK, and embed a ClutterStage into a Gtk application.
In theory, you can do that in this way:
let stage = Clutter.Stage.get_default ();
let gdkWind = ClutterGdk.get_stage_window (stage);
// The list most containt icons in different sizes.
let list = [GdkPixbuf.Pixbuf.new_from_file("test.png")];
gdkWind.set_icon_list(list);
//The next line not work
gdkWind.set_title("This title is not added");
In practice, you only will can load the icon and the windows title, but not the task bar title for the windows. The set_title won't work as Gdk.Window reference say it will (https://people.gnome.org/~gcampagna/docs/Gdk-3.0/Gdk.Window.set_title.html). Is then a Clutter issue, because is not a GDK "special case". But well is not working.

API to access dictionary popover in OS X?

I've been trying to find this in the developer documentation, but having trouble so hoping somebody could answer it or point me in the right direction.
In OS X apps using (I think) Core Text, you can hover over a word and type ctrl + cmd + d (or in Lion triple-finger tap as a gesture) to look up a dictionary definition via popover.
Is there a public API to insert additional information into that popover?
Apples Dictionary Services Reference offers HIDictionaryWindowShow(_:_:_:_:_:_:_:). This function opens a window containing the definition of your phrase.

How can I get the screen position of the DockTile in OSX?

I need a window to 'point' to the icon that was clicked on in the dock, similar to the way the context menu has the little callout-arrow pointing to it. This means I need to get the screen location of the dock, or more accurately the DockTile. (Yes I could use the mouse coordinates, but that doesn't look as good as it 'moves'.)
Now my thought is to get the associated view (I already have that), then use view-to-screen coordinate conversions, but that's becoming problematic as the x/left and y/top values of the bounding rectangle always say zero. I know that's because there's a nested hierarchy of views as well. Problem is I've walked it and always end up hitting a road block.
So thoughts?
Mark
You can get the dock icon positions using the accessibility API, there's some excellent sample code and app from Apple here.

Resources