mirror of
https://github.com/S2-/gitlit
synced 2025-08-03 12:50:04 +02:00
initial commit
This commit is contained in:
135
app/node_modules/electron-localshortcut/README.md
generated
vendored
Normal file
135
app/node_modules/electron-localshortcut/README.md
generated
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
# electron-localshortcut
|
||||
|
||||
A module to register/unregister a keyboard shortcut
|
||||
locally to a BrowserWindow instance, without using a Menu.
|
||||
|
||||
This is built to circumvent [this Electron issue](https://github.com/atom/electron/issues/1334).
|
||||
|
||||
**Note:** Since this module internally use `global-shortcut` native module, you should not use it until the `ready` event of the app module is emitted. See [electron docs](http://electron.atom.io/docs/latest/api/global-shortcut/).
|
||||
|
||||
[](http://travis-ci.org/parro-it/electron-localshortcut)
|
||||
[](https://npmjs.org/package/electron-localshortcut)
|
||||
[](https://npmjs.org/package/electron-localshortcut)
|
||||
[](https://greenkeeper.io/)
|
||||
|
||||
# Installation
|
||||
|
||||
```bash
|
||||
npm install --save electron-localshortcut
|
||||
```
|
||||
|
||||
# Usage
|
||||
|
||||
```javascript
|
||||
const electronLocalshortcut = require('electron-localshortcut');
|
||||
const BrowserWindow = require('electron').BrowserWindow;
|
||||
|
||||
const win = new BrowserWindow();
|
||||
win.loadUrl('https://github.com');
|
||||
win.show();
|
||||
|
||||
electronLocalshortcut.register(win, 'Ctrl+A', () => {
|
||||
console.log('You pressed ctrl & A');
|
||||
});
|
||||
|
||||
electronLocalshortcut.register(win, 'Ctrl+B', () => {
|
||||
console.log('You pressed ctrl & B');
|
||||
});
|
||||
|
||||
console.log(
|
||||
electronLocalshortcut.isRegistered(win, 'Ctrl+A')
|
||||
); // true
|
||||
|
||||
electronLocalshortcut.unregister(win, 'Ctrl+A');
|
||||
electronLocalshortcut.unregisterAll(win);
|
||||
```
|
||||
|
||||
# App shortcuts.
|
||||
|
||||
If you omit the window argument of `isRegistered`, `unregisterAll`, `unregister` and `register` methods, the shortcut is registered as an app shortcut.
|
||||
It is active when any window of the app is focused.
|
||||
|
||||
They differ from native [global-shortcuts](https://github.com/atom/electron/blob/master/docs/api/global-shortcut.md) because they doesn't interfere with other apps running on the same machine.
|
||||
|
||||
# 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
|
||||
|
||||
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
||||
|
||||
## disableAll
|
||||
|
||||
Disable all of the shortcuts registered on the BrowserWindow instance.
|
||||
Registered shortcuts no more works on the `window` instance, but the module keep a reference on them. You can reactivate them later by calling `enableAll` method on the same window instance.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `win` **BrowserWindow** BrowserWindow instance
|
||||
|
||||
Returns **[Undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
|
||||
|
||||
## enableAll
|
||||
|
||||
Enable all of the shortcuts registered on the BrowserWindow instance that you had previously disabled calling `disableAll` method.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `win` **BrowserWindow** BrowserWindow instance
|
||||
|
||||
Returns **[Undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
|
||||
|
||||
## unregisterAll
|
||||
|
||||
Unregisters all of the shortcuts registered on any focused BrowserWindow instance. This method does not unregister any shortcut you registered on a particular window instance.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `win` **BrowserWindow** BrowserWindow instance
|
||||
|
||||
Returns **[Undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
|
||||
|
||||
## register
|
||||
|
||||
Registers the shortcut `accelerator`on the BrowserWindow instance.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `win` **BrowserWindow** BrowserWindow instance to register. This argument could be omitted, in this case the function register the shortcut on all app windows.
|
||||
- `accelerator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the shortcut to register
|
||||
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** This function is called when the shortcut is pressed and the window is focused and not minimized.
|
||||
|
||||
Returns **[Undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
|
||||
|
||||
## unregister
|
||||
|
||||
Unregisters the shortcut of `accelerator` registered on the BrowserWindow instance.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `win` **BrowserWindow** BrowserWindow instance to unregister. This argument could be omitted, in this case the function unregister the shortcut on all app windows. If you registered the shortcut on a particular window instance, it will do nothing.
|
||||
- `accelerator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the shortcut to unregister
|
||||
|
||||
Returns **[Undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
|
||||
|
||||
## isRegistered
|
||||
|
||||
Returns `true` or `false` depending on whether the shortcut `accelerator` is
|
||||
registered on `window`.
|
||||
|
||||
**Parameters**
|
||||
|
||||
- `win` **BrowserWindow** BrowserWindow instance to check. This argument could be omitted, in this case the function returns whether the shortcut `accelerator` is registered on all app windows. If you registered the shortcut on a particular window instance, it return false.
|
||||
- `accelerator` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the shortcut to check
|
||||
|
||||
Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if the shortcut `accelerator` is registered on `window`.
|
||||
|
||||
# License
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Andrea Parodi
|
302
app/node_modules/electron-localshortcut/index.js
generated
vendored
Normal file
302
app/node_modules/electron-localshortcut/index.js
generated
vendored
Normal file
@@ -0,0 +1,302 @@
|
||||
'use strict';
|
||||
const {app, BrowserWindow} = require('electron');
|
||||
const isAccelerator = require('electron-is-accelerator');
|
||||
const equals = require('keyboardevents-areequal');
|
||||
const {toKeyEvent} = require('keyboardevent-from-electron-accelerator');
|
||||
const _debug = require('debug');
|
||||
|
||||
const debug = _debug('electron-localshortcut');
|
||||
|
||||
// A placeholder to register shortcuts
|
||||
// on any window of the app.
|
||||
const ANY_WINDOW = {};
|
||||
|
||||
const windowsWithShortcuts = new WeakMap();
|
||||
|
||||
const title = win => {
|
||||
if (win) {
|
||||
try {
|
||||
return win.getTitle();
|
||||
} catch (err) {
|
||||
return 'A destroyed window';
|
||||
}
|
||||
}
|
||||
|
||||
return 'An falsy value';
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable all of the shortcuts registered on the BrowserWindow instance.
|
||||
* Registered shortcuts no more works on the `window` instance, but the module
|
||||
* keep a reference on them. You can reactivate them later by calling `enableAll`
|
||||
* method on the same window instance.
|
||||
* @param {BrowserWindow} win BrowserWindow instance
|
||||
* @return {Undefined}
|
||||
*/
|
||||
function disableAll(win) {
|
||||
debug(`Disabling all shortcuts on window ${title(win)}`);
|
||||
const wc = win.webContents;
|
||||
const shortcutsOfWindow = windowsWithShortcuts.get(wc);
|
||||
|
||||
for (const shortcut of shortcutsOfWindow) {
|
||||
shortcut.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable all of the shortcuts registered on the BrowserWindow instance that
|
||||
* you had previously disabled calling `disableAll` method.
|
||||
* @param {BrowserWindow} win BrowserWindow instance
|
||||
* @return {Undefined}
|
||||
*/
|
||||
function enableAll(win) {
|
||||
debug(`Enabling all shortcuts on window ${title(win)}`);
|
||||
const wc = win.webContents;
|
||||
const shortcutsOfWindow = windowsWithShortcuts.get(wc);
|
||||
|
||||
for (const shortcut of shortcutsOfWindow) {
|
||||
shortcut.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters all of the shortcuts registered on any focused BrowserWindow
|
||||
* instance. This method does not unregister any shortcut you registered on
|
||||
* a particular window instance.
|
||||
* @param {BrowserWindow} win BrowserWindow instance
|
||||
* @return {Undefined}
|
||||
*/
|
||||
function unregisterAll(win) {
|
||||
debug(`Unregistering all shortcuts on window ${title(win)}`);
|
||||
const wc = win.webContents;
|
||||
const shortcutsOfWindow = windowsWithShortcuts.get(wc);
|
||||
|
||||
// Remove listener from window
|
||||
shortcutsOfWindow.removeListener();
|
||||
|
||||
windowsWithShortcuts.delete(wc);
|
||||
}
|
||||
|
||||
function _normalizeEvent(input) {
|
||||
const normalizedEvent = {
|
||||
code: input.code,
|
||||
key: input.key
|
||||
};
|
||||
|
||||
['alt', 'shift', 'meta'].forEach(prop => {
|
||||
if (typeof input[prop] !== 'undefined') {
|
||||
normalizedEvent[`${prop}Key`] = input[prop];
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof input.control !== 'undefined') {
|
||||
normalizedEvent.ctrlKey = input.control;
|
||||
}
|
||||
|
||||
return normalizedEvent;
|
||||
}
|
||||
|
||||
function _findShortcut(event, shortcutsOfWindow) {
|
||||
let i = 0;
|
||||
for (const shortcut of shortcutsOfWindow) {
|
||||
if (equals(shortcut.eventStamp, event)) {
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const _onBeforeInput = shortcutsOfWindow => (e, input) => {
|
||||
if (input.type === 'keyUp') {
|
||||
return;
|
||||
}
|
||||
|
||||
const event = _normalizeEvent(input);
|
||||
|
||||
debug(`before-input-event: ${input} is translated to: ${event}`);
|
||||
for (const {eventStamp, callback} of shortcutsOfWindow) {
|
||||
if (equals(eventStamp, event)) {
|
||||
debug(`eventStamp: ${eventStamp} match`);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
debug(`eventStamp: ${eventStamp} no match`);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers the shortcut `accelerator`on the BrowserWindow instance.
|
||||
* @param {BrowserWindow} win - BrowserWindow instance to register.
|
||||
* This argument could be omitted, in this case the function register
|
||||
* the shortcut on all app windows.
|
||||
* @param {String} accelerator - the shortcut to register
|
||||
* @param {Function} callback This function is called when the shortcut is pressed
|
||||
* and the window is focused and not minimized.
|
||||
* @return {Undefined}
|
||||
*/
|
||||
function register(win, accelerator, callback) {
|
||||
let wc;
|
||||
if (typeof callback === 'undefined') {
|
||||
wc = ANY_WINDOW;
|
||||
callback = accelerator;
|
||||
accelerator = win;
|
||||
} else {
|
||||
wc = win.webContents;
|
||||
}
|
||||
|
||||
debug(`Registering callback for ${accelerator} on window ${title(win)}`);
|
||||
_checkAccelerator(accelerator);
|
||||
|
||||
debug(`${accelerator} seems a valid shortcut sequence.`);
|
||||
|
||||
let shortcutsOfWindow;
|
||||
if (windowsWithShortcuts.has(wc)) {
|
||||
debug(`Window has others shortcuts registered.`);
|
||||
shortcutsOfWindow = windowsWithShortcuts.get(wc);
|
||||
} else {
|
||||
debug(`This is the first shortcut of the window.`);
|
||||
shortcutsOfWindow = [];
|
||||
windowsWithShortcuts.set(wc, shortcutsOfWindow);
|
||||
|
||||
if (wc === ANY_WINDOW) {
|
||||
const keyHandler = _onBeforeInput(shortcutsOfWindow);
|
||||
const enableAppShortcuts = (e, win) => {
|
||||
const wc = win.webContents;
|
||||
wc.on('before-input-event', keyHandler);
|
||||
wc.once('closed', () =>
|
||||
wc.removeListener('before-input-event', keyHandler)
|
||||
);
|
||||
};
|
||||
|
||||
// Enable shortcut on current windows
|
||||
const windows = BrowserWindow.getAllWindows();
|
||||
|
||||
windows.forEach(win => enableAppShortcuts(null, win));
|
||||
|
||||
// Enable shortcut on future windows
|
||||
app.on('browser-window-created', enableAppShortcuts);
|
||||
|
||||
shortcutsOfWindow.removeListener = () => {
|
||||
const windows = BrowserWindow.getAllWindows();
|
||||
windows.forEach(win =>
|
||||
win.webContents.removeListener('before-input-event', keyHandler)
|
||||
);
|
||||
app.removeListener('browser-window-created', enableAppShortcuts);
|
||||
};
|
||||
} else {
|
||||
const keyHandler = _onBeforeInput(shortcutsOfWindow);
|
||||
wc.on('before-input-event', keyHandler);
|
||||
|
||||
// Save a reference to allow remove of listener from elsewhere
|
||||
shortcutsOfWindow.removeListener = () =>
|
||||
wc.removeListener('before-input-event', keyHandler);
|
||||
wc.once('closed', shortcutsOfWindow.removeListener);
|
||||
}
|
||||
}
|
||||
|
||||
debug(`Adding shortcut to window set.`);
|
||||
|
||||
const eventStamp = toKeyEvent(accelerator);
|
||||
|
||||
shortcutsOfWindow.push({
|
||||
eventStamp,
|
||||
callback,
|
||||
enabled: true
|
||||
});
|
||||
|
||||
debug(`Shortcut registered.`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters the shortcut of `accelerator` registered on the BrowserWindow instance.
|
||||
* @param {BrowserWindow} win - BrowserWindow instance to unregister.
|
||||
* This argument could be omitted, in this case the function unregister the shortcut
|
||||
* on all app windows. If you registered the shortcut on a particular window instance, it will do nothing.
|
||||
* @param {String} accelerator - the shortcut to unregister
|
||||
* @return {Undefined}
|
||||
*/
|
||||
function unregister(win, accelerator) {
|
||||
let wc;
|
||||
if (typeof accelerator === 'undefined') {
|
||||
wc = ANY_WINDOW;
|
||||
accelerator = win;
|
||||
} else {
|
||||
if (win.isDestroyed()) {
|
||||
debug(`Early return because window is destroyed.`);
|
||||
return;
|
||||
}
|
||||
wc = win.webContents;
|
||||
}
|
||||
|
||||
debug(`Unregistering callback for ${accelerator} on window ${title(win)}`);
|
||||
|
||||
_checkAccelerator(accelerator);
|
||||
|
||||
debug(`${accelerator} seems a valid shortcut sequence.`);
|
||||
|
||||
if (!windowsWithShortcuts.has(wc)) {
|
||||
debug(`Early return because window has never had shortcuts registered.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const shortcutsOfWindow = windowsWithShortcuts.get(wc);
|
||||
|
||||
const eventStamp = toKeyEvent(accelerator);
|
||||
const shortcutIdx = _findShortcut(eventStamp, shortcutsOfWindow);
|
||||
if (shortcutIdx === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
shortcutsOfWindow.splice(shortcutIdx, 1);
|
||||
|
||||
// If the window has no more shortcuts,
|
||||
// we remove it early from the WeakMap
|
||||
// and unregistering the event listener
|
||||
if (shortcutsOfWindow.length === 0) {
|
||||
// Remove listener from window
|
||||
shortcutsOfWindow.removeListener();
|
||||
|
||||
// Remove window from shrtcuts catalog
|
||||
windowsWithShortcuts.delete(wc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` or `false` depending on whether the shortcut `accelerator`
|
||||
* is registered on `window`.
|
||||
* @param {BrowserWindow} win - BrowserWindow instance to check. This argument
|
||||
* could be omitted, in this case the function returns whether the shortcut
|
||||
* `accelerator` is registered on all app windows. If you registered the
|
||||
* shortcut on a particular window instance, it return false.
|
||||
* @param {String} accelerator - the shortcut to check
|
||||
* @return {Boolean} - if the shortcut `accelerator` is registered on `window`.
|
||||
*/
|
||||
function isRegistered(win, accelerator) {
|
||||
_checkAccelerator(accelerator);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
register,
|
||||
unregister,
|
||||
isRegistered,
|
||||
unregisterAll,
|
||||
enableAll,
|
||||
disableAll
|
||||
};
|
22
app/node_modules/electron-localshortcut/license
generated
vendored
Normal file
22
app/node_modules/electron-localshortcut/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2017 Andrea Parodi
|
||||
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
76
app/node_modules/electron-localshortcut/package.json
generated
vendored
Normal file
76
app/node_modules/electron-localshortcut/package.json
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"_from": "electron-localshortcut",
|
||||
"_id": "electron-localshortcut@3.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-MgL/j5jdjW7iA0R6cI7S045B0GlKXWM1FjjujVPjlrmyXRa6yH0bGSaIAfxXAF9tpJm3pLEiQzerYHkRh9JG/A==",
|
||||
"_location": "/electron-localshortcut",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "electron-localshortcut",
|
||||
"name": "electron-localshortcut",
|
||||
"escapedName": "electron-localshortcut",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/electron-localshortcut/-/electron-localshortcut-3.1.0.tgz",
|
||||
"_shasum": "10c1ffd537b8d39170aaf6e1551341f7780dd2ce",
|
||||
"_spec": "electron-localshortcut",
|
||||
"_where": "E:\\projects\\p\\gitlit\\app",
|
||||
"author": {
|
||||
"name": "andrea@parro.it"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/parro-it/electron-localshortcut/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"debug": "^2.6.8",
|
||||
"electron-is-accelerator": "^0.1.0",
|
||||
"keyboardevent-from-electron-accelerator": "^1.1.0",
|
||||
"keyboardevents-areequal": "^0.2.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "register/unregister a keyboard shortcut locally to a BrowserWindow instance, without using a Menu",
|
||||
"devDependencies": {
|
||||
"delay": "^2.0.0",
|
||||
"documentation": "^4.0.0-rc.1",
|
||||
"electron": "~1.6.7",
|
||||
"faucet": "^0.0.1",
|
||||
"p-electron": "^0.8.0",
|
||||
"p-event": "^1.1.0",
|
||||
"p-timeout": "^1.0.0",
|
||||
"robotjs": "^0.4.7",
|
||||
"tape-async": "^2.3.0",
|
||||
"xo": "^0.19.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/parro-it/electron-localshortcut#readme",
|
||||
"keywords": [
|
||||
"electron",
|
||||
"shortcuts",
|
||||
"browser-window"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "electron-localshortcut",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/parro-it/electron-localshortcut.git"
|
||||
},
|
||||
"scripts": {
|
||||
"doc": "documentation readme index.js --section=API",
|
||||
"setup-dev": "npm rebuild --runtime=electron --target=1.6.7 --disturl=https://atom.io/download/atom-shell --abi=51",
|
||||
"start": "electron example.js",
|
||||
"tape": "DEBUG=electron-localshortcut electron test.js",
|
||||
"test": "electron test.js | faucet && xo"
|
||||
},
|
||||
"version": "3.1.0"
|
||||
}
|
Reference in New Issue
Block a user