forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreloader.js
85 lines (63 loc) · 2.13 KB
/
preloader.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
81
82
83
const ipc = require('ipc');
const remote = require('remote');
const Menu = remote.require('menu');
const MenuItem = remote.require('menu-item');
// make variables globally accessable
window.dirname = __dirname;
// Wait for webview toogle
ipc.on('toogleWebviewDevTool', function(id){
var webview = Helpers.getWebview(id);
if(!webview)
return;
if(webview.isDevToolsOpened())
webview.closeDevTools();
else
webview.openDevTools();
});
/**
Update the main appliction menu with a toogle for all webview devtools.
*/
window.updateApplicationMenuDevTools = function(webviews){
var returnWebviews = [];
if(webviews) {
webviews.each(function(){
$webview = $(this);
returnWebviews.push({
name: (!$webview.data('id')) ? 'the browser' : $webview.attr('src'),
id: $webview.data('id') || 'browser'
});
});
}
ipc.send('setupWebviewDevToolsMenu', returnWebviews);
};
// CONTEXT MENU
var currentMousePosition = {x: 0, y: 0};
var menu = new Menu();
// menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({ label: 'Reload', accelerator: 'Command+R', click: function() {
var webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if(webview)
webview.reloadIgnoringCache();
}}));
menu.append(new MenuItem({ label: 'Inspect Element', click: function() {
var webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if(webview)
webview.inspectElement(currentMousePosition.x, currentMousePosition.y);
}}));
window.addEventListener('contextmenu', function (e) {
e.preventDefault();
// OPEN CONTEXT MENU over webviews
if($('webview:hover')[0]) {
currentMousePosition.x = e.layerX;
currentMousePosition.y = e.layerY;
menu.popup(remote.getCurrentWindow());
}
}, false);
document.addEventListener('keydown', function (e) {
// RELOAD current webview
if(e.metaKey && e.keyCode === 82) {
var webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if(webview)
webview.reloadIgnoringCache();
}
}, false);