Coder Social home page Coder Social logo

cequencer / node-mac-notifier Goto Github PK

View Code? Open in Web Editor NEW

This project forked from charliehess/node-mac-notifier

0.0 3.0 0.0 70 KB

Create macOS notifications from Node.js

License: MIT License

C++ 8.31% Python 2.68% Objective-C 3.70% Objective-C++ 61.63% JavaScript 23.69%

node-mac-notifier's Introduction

node-mac-notifier

A native Node module that lets you create macOS notifications from Node.js, without dishing out to a separate process. This is useful for desktop applications built with Electron (or something similar), as it adheres to the HTML5 Notification API.

Installation

npm install node-mac-notifier

Usage

Ensure that this module is called from a renderer process; it will have no effect in the main process. Works with Electron >=0.37.7.

const Notification = require('node-mac-notifier');
const notification = new Notification('Hello from node-mac-notifier', { body: 'It works!' });
notification.addEventListener('click', () => console.log('Got a click'));

In addition to the standard click event, these notifications also support a (non-standard) reply event. To enable the reply button, set canReply in the options argument. The user's response is included as a parameter on the event:

const notification = new Notification('Wow, replies!', { canReply: true });
notification.addEventListener('reply', ({ response }) => {
  console.log(`User entered: ${response}`);
});

API

new Notification(title, options)

title (string) (required)

The title of the notification.

options (Object)

Additional parameters to the notification.

  • options.id (string)

    A string identifying the notification. Maps to NSUserNotification.identifier. A notification with an id matching a previously delivered notification will not be shown. If not provided, defaults to a RFC4122 v4 string. Note that if you repeatedly create notifications with the same ID, only the first instance will be shown and future instances will not appear until that instance is closed.

  • options.body (string)

    The body text. Maps to NSUserNotification.informativeText.

  • options.subtitle (string)

    The subtitle text. Maps to NSUserNotification.subtitle.

  • options.icon (string)

    A URL with image content. Maps to NSUserNotification.contentImage. Should be an absolute URL.

  • options.soundName (string)

    The name of a sound file to play once the notification is delivered. Maps to NSUserNotification.soundName. Set to default to use NSUserNotificationDefaultSoundName, or leave undefined for a silent notification.

  • options.canReply (bool)

    If true, this notification will have a reply action button, and can emit the reply event. Maps to NSUserNotification.hasReplyButton.

  • options.bundleId (string)

    Set this to override the NSBundle.bundleIdentifier used for the notification. This is a brute force way for your notifications to take on the appropriate app icon.

close()

Dismisses the notification immediately.

node-mac-notifier's People

Contributors

charliehess avatar felixrieseberg avatar poiru avatar nornagon avatar ccnokes avatar anaisbetts avatar

Watchers

James Cloos avatar Jim Huang avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.