-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
60 lines (49 loc) · 1.47 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
const { app, ipcMain } = require('electron')
const log = require('electron-log');
log.transports.file.level = true;
log.transports.console.level = false;
console.log = log.log;
const receiveMessages = require('./receiveMessages');
const Executor = require('./executor');
const lndChannel = "lnd";
const browserChannel = "browser";
const storageChannel = "store";
const mainChannel = "main";
const executor = new Executor(app);
receiveMessages(message => {
app.whenReady().then(() => {
log.info(`New browser message: ${JSON.stringify(message)}`);
executor.handleBrowserMessage(message);
});
});
app.on('window-all-closed', () => {
app.quit();
});
ipcMain.on(lndChannel, (event, command, args) => {
executor.ln(command, args)
.then(response => {
event.returnValue = {data: response};
})
.catch(error => {
event.returnValue = {error: error};
});
});
ipcMain.on(browserChannel, (event, message) => {
executor.sendMessage(message);
event.returnValue = 'sent';
});
ipcMain.on(storageChannel, (event, command, ...args) => {
if (command === 'get') {
event.returnValue = executor.store.get(...args);
} else if (command === 'set') {
event.returnValue = executor.store.set(...args);
} else if (command === 'clear') {
event.returnValue = executor.store.clear();
}
});
ipcMain.on(mainChannel, (event, command) => {
console.log(`Main channel ipc command: ${command}`);
if (command === 'restart') {
executor.processMessage();
}
});