-
Notifications
You must be signed in to change notification settings - Fork 39
/
linuxActionHandler.js
47 lines (45 loc) · 1.44 KB
/
linuxActionHandler.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
const { existsSync } = require('fs');
const configParse = require('./configParse');
const { setCwd } = require('./setCwd');
const fixPath = require('./fixPath');
let tabs = {};
module.exports = ({ getState, dispatch }) => next => async (action) => {
switch (action.type) {
case 'CONFIG_LOAD': {
const hypercwdConfig = configParse(action.config);
if (hypercwdConfig.initialWorkingDirectory) {
const initialWorkingDirectory = fixPath(hypercwdConfig.initialWorkingDirectory);
if (initialWorkingDirectory && existsSync(initialWorkingDirectory)) {
dispatch({
type: 'SESSION_SET_CWD',
cwd: initialWorkingDirectory,
});
} else {
console.error(`hypercwd: could not find initialWorkingDirectory path: ${hypercwdConfig.initialWorkingDirectory} - see https://github.com/hharnisc/hypercwd#configuration for configuration details`);
}
}
break;
}
case 'SESSION_REQUEST':
case 'TERM_GROUP_REQUEST':
const { sessions: { activeUid } } = getState();
if (activeUid) {
await setCwd({ dispatch, action, tab: tabs[activeUid]});
}
break;
case 'SESSION_ADD':
tabs[action.uid] = {
pid: action.pid,
};
break;
case 'SESSION_PTY_EXIT':
delete tabs[action.uid];
break;
case 'SESSION_USER_EXIT':
delete tabs[action.uid];
break;
default:
break;
}
next(action);
}