Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 1.0.0 to 1.1.0

45

index.js
'use strict';
const electron = require('electron');
const isAccelerator = require('electron-is-accelerator');

@@ -14,6 +14,2 @@ const globalShortcut = electron.globalShortcut;

function isAccelerator(arg) {
return typeof arg === 'string';
}
function unregisterAllShortcuts(win) {

@@ -53,3 +49,3 @@ const shortcuts = windowsWithShortcuts.get(win);

function register(win, accelerator, callback) {
if (arguments.length === 2 && isAccelerator(win)) {
if (arguments.length === 2 && typeof win === 'string') {
// register shortcut for any window in the app

@@ -61,2 +57,4 @@ // win = accelerator, accelerator = callback

checkAccelerator(accelerator);
if (windowsWithShortcuts.has(win)) {

@@ -73,2 +71,6 @@ const shortcuts = windowsWithShortcuts.get(win);

}]);
win.on('close', () => {
unregisterAllShortcuts(win);
console.log('close event below', 2);
});
}

@@ -86,2 +88,3 @@

}
checkAccelerator(accelerator);

@@ -100,9 +103,25 @@ const shortcuts = windowsWithShortcuts.get(win);

function checkAccelerator(accelerator) {
if (!isAccelerator(accelerator)) {
const w = {};
Error.captureStackTrace(w);
const msg = `
WARNING: ${accelerator} is not a valid accelerator.
${w.stack.split('\n').slice(4).join('\n')}
`;
console.error(msg);
}
}
function unregister(win, accelerator) {
if (arguments.length === 1 && isAccelerator(win)) {
if (arguments.length === 1 && typeof win === 'string') {
// unregister shortcut for any window in the app
// win = accelerator
// win === accelerator
unregister(ANY_WINDOW, win);
return;
}
checkAccelerator(accelerator);
const shortcutToUnregisterIdx = indexOfShortcut(win, accelerator);

@@ -118,3 +137,3 @@

function isRegistered(win, accelerator) {
if (arguments.length === 1 && isAccelerator(win)) {
if (arguments.length === 1 && typeof win === 'string') {
// check shortcut for any window in the app

@@ -125,2 +144,4 @@ // win = accelerator

checkAccelerator(accelerator);
return indexOfShortcut(win, accelerator) !== -1;

@@ -153,2 +174,8 @@ }

// all shortcuts should be unregistered by closing the window.
// just for double check
app.on('window-all-closed', () => {
unregisterAll();
});
module.exports = {

@@ -155,0 +182,0 @@ register,

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

@@ -23,3 +23,6 @@ "repository": "parro-it/electron-localshortcut",

"xo": "^0.17.0"
},
"dependencies": {
"electron-is-accelerator": "^0.1.0"
}
}

3

readme.md

@@ -132,4 +132,1 @@ # electron-localshortcut

Copyright (c) 2016 Andrea Parodi
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