-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (75 loc) · 1.98 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Custom keyboard shortcuts. This function is only ran when in dev mode.
* It gives the developer access to common/expected keyboard shortcuts.
*
* @param {object} window Browser window object
*/
function nwDevKeyBindings (window) {
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.nw &&
window.nw.Window &&
window.nw.Window.get &&
(
isSDK ||
isSuperOld
)
) {
win = window.nw.Window.get();
} else {
return;
}
var CTRL = pressed.ctrlKey;
var CMD = pressed.metaKey;
var OPTION = pressed.altKey;
var SHIFT = pressed.shiftKey;
var F5 = pressed.keyCode === 116;
var F12 = pressed.keyCode === 123;
var I = pressed.keyCode === 73;
var R = pressed.keyCode === 82;
// Refresh ignoring cache
if (SHIFT && F5 || CMD && SHIFT && R) {
pressed.preventDefault();
win.reloadIgnoringCache();
return false;
// Hard refresh
} else if (CTRL && F5 || CTRL && R || CMD && R) {
pressed.preventDefault();
win.reloadDev();
return false;
// Soft refresh
} else if (F5) {
pressed.preventDefault();
win.reload();
return false;
// Open Dev Tools
} else if (F12 || CTRL && SHIFT && I || OPTION && SHIFT && I) {
pressed.preventDefault();
win.showDevTools();
return false;
}
};
}
module.exports = nwDevKeyBindings;