Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJaredWilcurt committed Jan 11, 2024
1 parent 8b5b87d commit 26524be
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# nw-dev-keybindings
Open dev tools and refresh keybindings for NW.js

"Open dev tools" and "refresh page" keybindings for NW.js.

Skips creating bindings if you are not on the SDK version.

Written in glorius ES5 (that means it runs in all version of NW.js, even super old ones).


## Usage

1. `npm install --save nw-dev-keybindings`
1. Add this to your HTML file:

```html
<script>
const nwDevKeyBindings = require('nw-dev-keybindings');
nwDevKeyBindings(window);
</script>
```


Then, if you are in the SDK version of NW.js, you'll be able to run these commands:

Key binding | Outcome
:-- | :--
`F5` | Soft refresh
`Shift+F5` | Refresh ignoring cache
`Command+Shift+R` | Refresh ignoring cache
`Ctrl+F5` | Hard refresh
`Ctrl+R` | Hard refresh
`Command+R` | Hard refresh
`F12` | Open Dev Tools
`Ctrl+Shift+I` | Open Dev Tools
`Option+Shift+I` | Open Dev Tools
29 changes: 23 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,38 @@
* @param {object} window Browser window object
*/
function nwDevKeyBindings (window) {
if (!window || !window.document) {
if (
!window ||
!window.document ||
!window.process
) {
return;
}

window.document.onkeydown = function (pressed) {
var win;
var isSDK = (
window.process.versions &&
window.process.versions['nw-flavor'] &&
window.process.versions['nw-flavor'] === 'sdk'
);
var isSuperOld = (
window.process['node-webkit'] &&
window.process['node-webkit'].startsWith &&
(
window.process.versions['node-webkit'].startsWith('0.10.') ||
window.process.versions['node-webkit'].startsWith('0.11.') ||
window.process.versions['node-webkit'].startsWith('0.12.')
);

if (
window &&
window.nw &&
window.nw.Window &&
window.nw.Window.get &&
window.process &&
window.process.versions &&
window.process.versions['nw-flavor'] &&
window.process.versions['nw-flavor'] === 'sdk'
(
isSDK ||
isSuperOld
)
) {
win = window.nw.Window.get();
} else {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "nw-dev-keybindings",
"version": "1.0.0",
"description": "Open dev tools and refresh keybindings for NW.js",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/nwutils/nw-dev-keybindings.git"
},
"keywords": [
"NW.js",
"dev",
"tools",
"shortcuts",
"key",
"binding",
"tooling"
],
"author": "The Jared Wilcurt",
"license": "MIT",
"bugs": {
"url": "https://github.com/nwutils/nw-dev-keybindings/issues"
},
"homepage": "https://github.com/nwutils/nw-dev-keybindings#readme"
}

0 comments on commit 26524be

Please sign in to comment.