Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 6, 2025. It is now read-only.

mullvad/NSEventMonitor

Open more actions menu

Repository files navigation

NSEventMonitor

Build Status dependencies Status devDependencies Status

Currently when building menubar apps with Electron, window.on('blur', ...) does not fire if user clicks on other menubar items leaving displayed window on screen.

Native macOS popovers usually hide if user clicks anywhere on screen. This extension attempts to fix that for Electron apps, so the following will never be the case anymore:

Example

import { NSEventMonitor, NSEventMask } from 'nseventmonitor';

let macEventMonitor = new NSEventMonitor();

window.on('blur', () => {
  window.hide();
});

window.on('show', () => {
  // start capturing global mouse events
  macEventMonitor.start((NSEventMask.leftMouseDown | NSEventMask.rightMouseDown), () => {
    window.hide();
  });
});

window.on('hide', () => {
  // stop capturing global mouse events
  macEventMonitor.stop();
});

To run example app:

$ cd example
$ npm i
$ npm start

Electron support

Electron comes with its own Node.js runtime, which may differ from the one installed on your desktop. Therefore all native modules have to be built specifically for Electron.

We strongly advise to use electron-builder and add a postinstall script to your package.json in order to automatically compile native modules for Electron:

electron-builder install-app-deps

Building from source

To compile the extension run the following command:

$ npm i --build-from-source

You can confirm everything built correctly by running the test suite.

To run tests:

$ npm test

Note: tests are currently disabled due to issues with automation on macOS.

About

Node.js module for monitoring NSEvents

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.