npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

not-the-systray

v0.3.1

Published

Because calling it the system tray [would be wrong](https://devblogs.microsoft.com/oldnewthing/20030910-00/?p=42583).

Downloads

9

Readme

Windows Notification Icons

Because calling it the system tray would be wrong.

Description

Provides fairly direct access to the Win32 Shell_NotifyIcon API, which allows adding an icon to the notification area, and support for the related windows APIs to load icons and use context (e.g. right-click) menus.

Prebuilt as N-API (64-bit only for now, sorry), meaning you don't need Visual Studio or build tools installed on your development machine or CI server.

Note that this is using the Win32 desktop APIs, so you don't need to be running under the UWP (Windows Store) model, and thus has odd limitations like requiring an icon in the notification area to show a notification message, and not supporting notification actions (e.g. buttons).

Usage

The type definitions have fuller jsdoc descriptions, but as a basic overview:

import { NotifyIcon, Icon, Menu } from "not-the-systray";

// Creates an empty (blank) icon in the notification area
// that does nothing.
// Unfortunately the Windows terminology I'm exposing here is
// pretty confusing, they have "Notification icons" that have
// icons and can show notifications that also have icons.
const emptyIcon = new NotifyIcon();
// Remove it!
emptyIcon.remove();

// Creates and adds an initialized icon, with a select callback.
const appIcon = new NotifyIcon({
    icon: Icon.load("my-icon.ico", Icon.small), // Notify icons should use 
    tooltip: "My icon from nodejs",
    onSelect({ target, rightButton, mouseX, mouseY }) {
        // `this` is `target` is `appIcon`.
        // `rightButton` is which mouse button it was selected with,
        // `mouseX and `mouseX` are the screen co-ordinates of the click.
        // If selected with the keyboard, these values will be simulated.

        if (rightButton) {
            handleMenu(mouseX, mouseY);
        } else {
            // some default action, or just show the same menu.
        }
    },
});

// Notifications should use the size `Icon.large`.
// Icons can be loaded ahead of time to catch errors earlier,
// and save a bit of time and memory.
const notificationIcon = Icon.load("notification-icon.ico", Icon.large);
// You can also use some built-in icons, for example:
const errorIcon = Icon.load(Icon.ids.error, Icon.large);

const toggleId = 1;
const notificationId = 2;
const submenuId = 3;

const menu = new Menu([
    { id: toggleId, text: "Toggle item", checked: true },
    { id: notificationId, text: "Show notification" },
    { separator: true },
    { text: "Sub-menu", items: [
        { id: submenuId, text: "Sub-menu item" },
    ] }
]);

function handleMenu(x, y) {
    const id = menu.showSync(x, y);
    switch (id) {
        case null:
            // user cancelled selection.
            break;
        case toggleId: {
            // You can read the immediate properties (ie. not counting `items`)
            // of any item by id.
            const { checked } = menu.get(toggleId);
            // You can update any properties of an item whenever you want, including
            // `items`.
            menu.update(toggleId, { checked: !checked });
            break;
        }
        case notificationId:
            // The win32 (non-UWP) model of notifications are as
            // a property of a notification area icon, and can't
            // be displayed without one (remember the old balloons?)
            // Updating with a new notification will remove the
            // previous one.
            appIcon.update({
                notification: {
                    icon: notificationIcon,
                    title: "Hello, world",
                    text: "A notification from nodejs",
                },
            });
            break;
        case submenuId:
            // Ids work in submenus too.
            console.log("Selected the submenu item");
            break;
    }
}