-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
63 lines (48 loc) · 1.78 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
61
62
63
'use strict'
const { rulesHandler } = require('./src/rules/rules-handler')
const { clearBuffer } = require('./src/clear-buffer')
const { joinCommands } = require('./src/join-commands')
const { getSeparator } = require('./src/get-specifics')
const { getClearCommand } = require('./src/get-specifics')
const waitFor = require('./src/wait-for')
const init = {}
const terminal = {}
let clearCommand
let commandSeparator
exports.onApp = ({ config }) => {
clearCommand = config.getConfig().clearCommand || undefined
commandSeparator = config.getConfig().commandSeparator || undefined
Object.assign(init, config.getConfig().init)
}
exports.getTabProps = (uid, parentProps, props) =>
Object.assign(terminal, uid, { tabs: parentProps.tabs }) &&
Object.assign({}, props)
exports.reduceTermGroups = (reducer) =>
Object.assign(terminal, reducer.termGroups) && reducer
exports.middleware = () => (next) => (action) => {
if (action.type === 'SESSION_ADD') {
Object.assign(terminal, { splitDirection: action.splitDirection })
}
next(action)
}
exports.onWindow = (browserWindow) => {
browserWindow.rpc.on('hyper-init execute commands', ({ uid, terminal }) => {
if (commandSeparator === undefined) {
commandSeparator = getSeparator(browserWindow, uid)
}
if (clearCommand === undefined) {
clearCommand = getClearCommand(browserWindow, uid)
}
clearBuffer({ app: browserWindow, uid }, clearCommand)
Object.keys(init).map((key) => {
let cmd = joinCommands(init[key].commands, commandSeparator)
rulesHandler({ init, key, cmd, app: browserWindow, uid, terminal })
})
})
}
exports.onRendererWindow = (app) =>
waitFor(app, 'rpc', (rpc) =>
rpc.on('session add', ({ uid }) =>
rpc.emit('hyper-init execute commands', { uid, terminal })
)
)