forked from DanInglis/hyper-run
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
41 lines (35 loc) · 784 Bytes
/
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
'use strict';
// let fs = require('fs');
let commands = [];
// debugging purposes
// function log(str) {
// fs.appendFile(`${__dirname}/log.txt`, str + '\n');
// }
function waitFor(object, key, fn) {
if (key in object) {
fn(object[key]);
} else {
setTimeout(() => waitFor(object, key, fn), 10);
}
}
exports.onApp = function (obj) {
const config = obj.config.getConfig();
if (config.commands) {
commands = config.commands;
}
};
exports.onWindow = win => {
win.rpc.on('execute commands', uid => {
commands.forEach(cmd => {
win.sessions.get(uid).write(cmd + '\r');
});
});
};
exports.onRendererWindow = win => {
waitFor(win, 'rpc', rpc => {
rpc.on('session add', details => {
const { uid } = details;
rpc.emit('execute commands', uid);
});
});
};