Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mullvad/nseventmonitor
Node.js module for monitoring NSEvents
https://github.com/mullvad/nseventmonitor
electron macos menubar nsevent
Last synced: about 2 months ago
JSON representation
Node.js module for monitoring NSEvents
- Host: GitHub
- URL: https://github.com/mullvad/nseventmonitor
- Owner: mullvad
- License: mit
- Created: 2017-02-19T20:27:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-10-16T08:27:43.000Z (2 months ago)
- Last Synced: 2024-10-18T00:17:15.944Z (2 months ago)
- Topics: electron, macos, menubar, nsevent
- Language: Objective-C++
- Homepage:
- Size: 449 KB
- Stars: 17
- Watchers: 11
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NSEventMonitor
[![Build Status](https://api.travis-ci.org/mullvad/NSEventMonitor.svg)](https://travis-ci.org/mullvad/NSEventMonitor)
[![dependencies Status](https://david-dm.org/mullvad/NSEventMonitor/status.svg)](https://david-dm.org/mullvad/NSEventMonitor)
[![devDependencies Status](https://david-dm.org/mullvad/NSEventMonitor/dev-status.svg)](https://david-dm.org/mullvad/NSEventMonitor?type=dev)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
```js
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).
### To run tests:
```
$ npm test
```Note: tests are currently disabled due to issues with automation on macOS.