forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmistUI.js
More file actions
172 lines (137 loc) · 5.02 KB
/
Copy pathmistUI.js
File metadata and controls
172 lines (137 loc) · 5.02 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/**
@module preloader MistUI
*/
// Initialise the Redux store
window.store = require('./rendererStore');
require('./include/common')('mist');
require('./include/web3CurrentProvider.js');
const { ipcRenderer, remote, webFrame } = require('electron'); // eslint-disable-line import/newline-after-import
const { Menu, MenuItem } = remote;
const dbSync = require('../dbSync.js');
const i18n = require('../i18n.js');
const mist = require('./include/mistAPI.js');
const web3Admin = require('../web3Admin.js');
require('./include/setBasePath')('interface');
// add admin later
setTimeout(() => {
web3Admin.extend(window.web3);
}, 1000);
window.mist = mist();
window.mistMode = remote.getGlobal('mode');
window.dbSync = dbSync;
window.dirname = remote.getGlobal('dirname');
window.ipc = ipcRenderer;
// remove require and module, because node-integration is on
delete window.module;
delete window.require;
// prevent overwriting the Dapps Web3
// delete global.Web3;
// delete window.Web3;
// set the langauge for the electron interface
// ipcRenderer.send('setLanguage', navigator.language.substr(0,2));
// A message coming from other window, to be passed to a webview
ipcRenderer.on('uiAction_windowMessage', (e, type, id, error, value) => {
if ((type === 'requestAccount') || (type === 'connectAccount') && !error) {
Tabs.update({ webviewId: id }, { $addToSet: { 'permissions.accounts': value } });
}
// forward to the webview (TODO: remove and manage in the ipcCommunicator?)
const tab = Tabs.findOne({ webviewId: id });
if (tab) {
webview = $(`webview[data-id=${tab._id}]`)[0];
if (webview) {
webview.send('uiAction_windowMessage', type, error, value);
}
}
});
ipcRenderer.on('uiAction_enableBlurOverlay', (e, value) => {
$('html').toggleClass('has-blur-overlay', !!value);
});
// Wait for webview toggle
ipcRenderer.on('uiAction_toggleWebviewDevTool', (e, id) => {
const webview = Helpers.getWebview(id);
if (!webview) {
return;
}
if (webview.isDevToolsOpened()) {
webview.closeDevTools();
} else {
webview.openDevTools();
}
});
// randomize accounts and drop half
// also certainly remove the web3.ethbase one
const randomizeAccounts = (acc, coinbase) => {
let accounts = _.shuffle(acc);
accounts = _.rest(accounts, (accounts.length / 2).toFixed(0));
accounts = _.without(accounts, coinbase);
return accounts;
};
// Run tests
ipcRenderer.on('uiAction_runTests', (e, type) => {
if (type === 'webview') {
web3.eth.getAccounts((error, accounts) => {
if (error) return;
web3.eth.getCoinbase((coinbaseError, coinbase) => {
if (coinbaseError) return;
Tabs.upsert('tests', {
position: -1,
name: 'Tests',
url: '', // is hardcoded in webview.html to prevent hijacking
permissions: {
accounts: randomizeAccounts(accounts, coinbase),
},
});
Tracker.afterFlush(() => {
LocalStore.set('selectedTab', 'tests');
});
// update the permissions, when accounts change
Tracker.autorun(() => {
const accountList = _.pluck(EthAccounts.find({}, { fields: { address: 1 } }).fetch(), 'address');
Tabs.update('tests', { $set: {
'permissions.accounts': randomizeAccounts(accountList, coinbase),
} });
});
});
});
}
});
// CONTEXT MENU
const currentMousePosition = { x: 0, y: 0 };
const menu = new Menu();
// menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({ label: i18n.t('mist.rightClick.reload'), accelerator: 'Command+R', click() {
const webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if (webview) {
webview.reloadIgnoringCache();
}
} }));
menu.append(new MenuItem({ label: i18n.t('mist.rightClick.openDevTools'), click() {
const webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if (webview) {
webview.openDevTools();
}
} }));
menu.append(new MenuItem({ label: i18n.t('mist.rightClick.inspectElements'), click() {
const webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if (webview) {
webview.inspectElement(currentMousePosition.x, currentMousePosition.y);
}
} }));
window.addEventListener('contextmenu', (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', (e) => {
// RELOAD current webview
if (e.metaKey && e.keyCode === 82) {
const webview = Helpers.getWebview(LocalStore.get('selectedTab'));
if (webview) {
webview.reloadIgnoringCache();
}
}
}, false);