Socket
Socket
Sign inDemoInstall

electron-localshortcut

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-localshortcut - npm Package Compare versions

Comparing version 2.0.0 to 2.0.2

38

index.js

@@ -14,2 +14,3 @@ 'use strict';

let _enableShortcut = shortcut => {
debug(`Calling globalShortcut.register(${shortcut.accelerator}, ${shortcut.callback.name})`);
globalShortcut.register(shortcut.accelerator, shortcut.callback);

@@ -20,2 +21,3 @@ shortcut.registered = true;

let _disableShortcut = shortcut => {
debug(`Calling globalShortcut.unregister(${shortcut.accelerator})`);
globalShortcut.unregister(shortcut.accelerator);

@@ -31,2 +33,3 @@ shortcut.registered = false;

function _enableWindowAndApp(win) {
debug(`_enableWindowAndApp ${win.getTitle && win.getTitle()}`);
if (windowsWithShortcuts.has(ANY_WINDOW)) {

@@ -44,2 +47,3 @@ enableAll(ANY_WINDOW);

function _disableWindowAndApp(win) {
debug(`_disableWindowAndApp ${win.getTitle && win.getTitle()}`);
if (windowsWithShortcuts.has(ANY_WINDOW)) {

@@ -151,7 +155,9 @@ disableAll(ANY_WINDOW);

const _unregister = () => {
const _unregister = because => () => {
debug(`Disabling shortcuts for app and for window '${(win.getTitle && win.getTitle()) || 'No name'}' because ${because}.`);
_disableWindowAndApp(win);
};
const _register = () => {
const _register = because => () => {
debug(`Enabling shortcuts for app and for window '${(win.getTitle && win.getTitle()) || 'No name'}' because ${because}.`);
_enableWindowAndApp(win);

@@ -167,11 +173,11 @@ };

if (win !== ANY_WINDOW) {
win.on('close', _unregister);
win.on('close', _unregister('the window was closed.'));
win.on('hide', _unregister);
win.on('hide', _unregister('the window was hidden.'));
win.on('minimize', _unregister);
win.on('minimize', _unregister('the window was minimized.'));
win.on('restore', _register);
win.on('restore', _register('the window was restored from minimized state.'));
win.on('show', _register);
win.on('show', _register('the window was showed.'));
}

@@ -185,8 +191,6 @@ }

const registeringWindowIsMinimized = () => focusedWin.isMinimized();
debug(registeringWindowHasFocus, win && win === ANY_WINDOW ? 'ANY_WINDOW' : win.getTitle(), focusedWin && focusedWin.getTitle());
debug(JSON.stringify({registeringAppShortcut, appHasFocus, registeringWindowHasFocus}));
if ((registeringAppShortcut && appHasFocus) ||
(registeringWindowHasFocus && !registeringWindowIsMinimized())) {
_register();
_register('the window was focused at shortcut registration.');
}

@@ -239,5 +243,15 @@ }

app.on('browser-window-focus', (_, win) => _enableWindowAndApp(win));
app.on('browser-window-blur', (_, win) => _disableWindowAndApp(win));
const windowBlur = because => (_, win) => {
debug(`Disabling shortcuts for app and for window '${(win.getTitle && win.getTitle()) || 'No name'}' because ${because}.`);
_disableWindowAndApp(win);
};
const windowFocus = because => (_, win) => {
debug(`Enabling shortcuts for app and for window '${(win.getTitle && win.getTitle()) || 'No name'}' because ${because}.`);
_enableWindowAndApp(win);
};
app.on('browser-window-focus', windowFocus('the window gained focus'));
app.on('browser-window-blur', windowBlur('the window loose focus'));
// All shortcuts should be unregistered by closing the window.

@@ -244,0 +258,0 @@ // just for double check

{
"name": "electron-localshortcut",
"version": "2.0.0",
"version": "2.0.2",
"description": "register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu",

@@ -24,3 +24,2 @@ "repository": "parro-it/electron-localshortcut",

"devDependencies": {
"debug": "^2.6.6",
"delay": "^2.0.0",

@@ -37,4 +36,5 @@ "documentation": "^4.0.0-rc.1",

"dependencies": {
"debug": "^2.6.8",
"electron-is-accelerator": "^0.1.0"
}
}

@@ -54,2 +54,9 @@ # electron-localshortcut

# Shortcut behaviour.
If you register a shortcut for a window, this module unregister the shortcut when the window is hidden, unfocused or minimized, and automatically restore them when the window is restored and focused again.
If you register an app shortcut, this module unregister the shortcut when all windows of your app are hidden, unfocused or minimized, and automatically restore it when any window of your app is restored and focused again.
# API

@@ -56,0 +63,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc