forked from ethereum/mist
/
ipcProviderWrapper.js
92 lines (72 loc) · 2 KB
/
ipcProviderWrapper.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
/**
@module MistUI
*/
/**
The IPC provider wrapper to communicate to the backend
@class ipcProviderWrapper
@constructor
*/
const ipc = require('electron').ipcRenderer;
/**
Gets the writable property.
@method on('ipcProvider-setWritable')
*/
ipc.on('ipcProvider-setWritable', function(e, writable){
ipcProviderWrapper.writable = writable;
});
ipcProviderWrapper = {
writable: false,
/**
Connects the IPC on the backend to the gexp node
Note: web3.isConnected will always return true, as otherwise race conditions can occour,
letting it look like youre not connected via IPC.
@method connect
*/
connect: function(path) {
// console.log('CONNECT SYNC');
this.writable = ipc.sendSync('ipcProvider-create'); // path is set in the backend
// ipc.send('ipcProvider-create'); // path is set in the backend
return this;
},
/**
Returns data from the IPC through the backend
@method on
@param {String} name `connect`, `error`, `end`, `timeout` or `data`
@param {Funciton} callback
*/
on: function(name, callback) {
ipc.on('ipcProvider-'+ name, function(e, result){
callback(result);
});
},
/**
Removes listener
@method removeListener
*/
removeListener: function(type, callback){
ipc.removeListener('ipcProvider-'+ type, callback);
},
/**
Removes all listeners
@method removeAllListeners
*/
removeAllListeners: function(type){
ipc.removeAllListeners('ipcProvider-'+ type);
},
/**
Write to the IPC connection through the backend
@method write
*/
write: function (payload) {
ipc.send('ipcProvider-write', payload);
},
/**
Write synchronous to the IPC connection through the backend
@method writeSync
*/
writeSync: function (payload) {
// console.log('SEND SYNC', payload);
return ipc.sendSync('ipcProvider-writeSync', payload);
}
};
module.exports = ipcProviderWrapper;