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

electron-taskbar-badge

v1.1.2

Published

An easy way for electron apps to add app badges to the taskbar to indicate notifications and other countable things, with maximum compatibility and customizability.

Downloads

1,549

Readme

versionweekly_downloadsdownloadsissueslicenseelectron-taskbar-badge

Electron Taskbar Badge

An easy way for electron apps to add app badges to the taskbar to indicate notifications and other countable things, with maximum compatibility and customizability.


Changelog (v1.1.2)

• Fixed non win32 environments detection
• And more bug fixes


Installation

npm i electron-taskbar-badge

Basic Usage

This library is ONLY compatible with node version 14 and above! Only supports Windows at the moment

First, you must import the library using the following code:

const Badge = require('electron-taskbar-badge');
// or `import * as Badge from 'electron-taskbar-badge';` for ESM users


For basic usage, all you have to do is call the function with the options:

Process: Main

const Badge = require('electron-taskbar-badge');
// or `import * as Badge from 'electron-taskbar-badge';` for ESM users

// NOTE: Although the font size 62px seems large, it is not. It is relative to the radius. Lowering both of these values can decrease quality significantly. Increasing them can reduce performance. Leave the font size and the radius as is for basic usage
const badgeOptions = {
	fontColor: '#FFFFFF', // The font color
	font: '62px Microsoft Yahei', // The font and its size. You shouldn't have to change this at all
	color: '#FF0000', // The background color
	radius: 48, // The radius for the badge circle. You shouldn't have to change this at all
	updateBadgeEvent: 'notificationCount', // The IPC event name to listen on
	badgeDescription: 'Unread Notifications', // The badge description
	invokeType: 'handle', // The IPC event type
	max: 9, // The maximum integer allowed for the badge. Anything above this will have "+" added to the end of it.
	fit: false, // Useful for multi-digit numbers. For single digits keep this set to false
	additionalFunc: (count) => {
		// An additional function to run whenever the IPC event fires. It has a count parameter which is the number that the badge was set to.
		console.log(`Received ${count} new notifications!`);
	},
};

// "win" would be your Electron BrowserWindow object
new Badge(win, badgeOptions);

Process: Renderer

// If invokeType is set to "handle"
// Replace 8 with whatever number you want the badge to display
ipcRenderer.invoke('notificationCount', 8);

// If invokeType is set to "send"
ipcRenderer.sendSync('notificationCount', 8);

That's it! Now you have it running!

More examples

Native look

If you want your badge to look native to the operating system, which means that it follows the default OS's font and color, you can use the useSystemAccentTheme option. Here's an example:

// DO NOT change the font or the radius
// fontColor and color will be overridden. The background color would be the system accent color, and the font color would be automatically chosen between black or white, whichever looks best.
const badgeOptions = {
	fontColor: '#000000',
	font: '62px Microsoft Yahei',
	color: '#000000',
	radius: 48,
	updateBadgeEvent: 'notificationCount',
	badgeDescription: 'Unread Notifications',
	invokeType: 'handle',
	max: 9,
	fit: false,
	useSystemAccentTheme: true,
	additionalFunc: (count) => {
		console.log(`Received ${count} new notifications!`);
	},
};

new Badge(win, badgeOptions);

Examples

Taskbar Badge Purple
Taskbar Badge Blue
Taskbar Badge Green

Auto font color

If you want your badge's font color to be automatically chosen, simply set fontColor to auto. This will choose the font color between black or white, whichever looks best. Here's an example:

const badgeOptions = {
	fontColor: 'auto',
	font: '62px Microsoft Yahei',
	color: '#00FF00',
	radius: 48,
	updateBadgeEvent: 'notificationCount',
	badgeDescription: 'Unread Notifications',
	invokeType: 'handle',
	max: 9,
	fit: false,
	additionalFunc: (count) => {
		console.log(`Received ${count} new notifications!`);
	},
};

new Badge(win, badgeOptions);

Options

Options info for Badge(options)

| Parameters | Type | Description | Default | |---------------|---------|----------------------------------------|---------| | fontColor | string (required) | The font color in hex or RGB color format. Pretty self-explanatory. | auto | | font | string | The font for the badge icon. The format is [size]px [Font family name] ALWAYS SET THE FONT SIZE TO 62px FOR BEST QUALITY | 62px Microsoft Yahei | | color | string (required) | The background color for the badge icon in hex or RGB color format. | null | | radius | number | The radius for the badge icon ALWAYS SET TO 48 FOR BEST QUALITY | 48 | | updateBadgeEvent | string (required) | The IPC event name to listen on | null | | badgeDescription | string | A description that will be provided to Accessibility screen readers | this.updateBadgeEvent | | invokeType | string | The IPC event type. Can be send or handle. | send | | max | number | The maximum integer allowed for the badge. Anything above this will have "+" added to the end of it. | 99 | | fit | boolean | Automatically sizes large numbers to fit in the badge icon. Set to true only for large 3-digit numbers (including the "+"!) | false | | useSystemAccentTheme | boolean | Whether to use the system accent color for the background color. fontColor and color will be overridden. It would be automatically chosen between black or white, whichever looks best. | false | | additionalFunc | function(count) | An additional function to run whenever the IPC event fires. It has a count parameter which is the number that the badge was set to. | null |