forked from ethereum/mist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmistAPI.js
111 lines (88 loc) · 2.69 KB
/
mistAPI.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
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
var remote = require('remote');
var ipc = require('ipc');
var web3 = require('web3'); //./node_modules/web3/dist/web3.min.js
var BigNumber = require('bignumber.js');
var prefix = 'entry_';
// set web3 providor
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
// filterId the id to only contain a-z A-Z 0-9
var filterId = function(str) {
var newStr = '';
for (var i = 0; i < str.length; i++) {
if(/[a-zA-Z0-9_-]/.test(str.charAt(i)))
newStr += str.charAt(i);
};
return newStr;
};
ipc.on('callFunction', function(id) {
if(mist.menu.entries[id] && mist.menu.entries[id].callback)
mist.menu.entries[id].callback();
});
var mist = {
menu: {
entries: {},
/**
Sets the badge text for the apps menu button
Example
mist.menu.setBadge('Some Text')
@method setBadge
@param {String} text
*/
setBadge: function(text){
ipc.sendToHost('setBadge', text);
},
/**
Adds/Updates a menu entry
Example
mist.menu.add('tkrzU', {
name: 'My Meny Entry',
badge: 50,
position: 1,
selected: true
}, function(){
// Router.go('/chat/1245');
})
@method add
@param {String} id The id of the menu, has to be the same accross page reloads.
@param {Object} options The menu options like {badge: 23, name: 'My Entry'}
@param {Function} callback Change the callback to be called when the menu is pressed.
*/
'add': function(id, options, callback){
id = prefix + filterId(id);
var entry = {
id: id,
position: options.position,
selected: !!options.selected,
name: options.name,
badge: options.badge,
};
ipc.sendToHost('addMenu', entry);
if(callback)
entry.callback = callback;
this.entries[id] = entry;
},
'update': function(){
this.add.apply(this, arguments);
},
/**
Removes a menu entry from the mist sidebar.
@method remove
@param {String} id
*/
'remove': function(id){
id = prefix + filterId(id);
delete this.entries[id];
ipc.sendToHost('removeMenu', id);
},
/**
Removes all menu entries.
@method clear
*/
'clear': function(){
ipc.sendToHost('clearMenu');
}
},
};
window.mist = mist;
window.BigNumber = BigNumber;
window.web3 = web3;