-
Notifications
You must be signed in to change notification settings - Fork 39
/
windowsActionHandler.js
51 lines (49 loc) · 1.58 KB
/
windowsActionHandler.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
const { existsSync } = require('fs');
const configParse = require('./configParse');
const { windowsSetCwd } = require('./setCwd');
const fixPath = require('./fixPath');
let tabs = {};
let curTabId;
module.exports = ({ dispatch }) => next => (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_PTY_DATA':
windowsSetCwd({ dispatch, action, tab: tabs[action.uid], curTabId });
break;
case 'SESSION_ADD':
tabs[action.uid] = {
pid: action.pid,
};
curTabId = action.uid;
windowsSetCwd({ dispatch, action, tab: tabs[action.uid], curTabId });
break;
case 'SESSION_SET_ACTIVE':
curTabId = action.uid;
dispatch({
type: 'SESSION_SET_CWD',
cwd: tabs[curTabId].cwd,
});
break;
case 'SESSION_PTY_EXIT':
delete tabs[action.uid];
break;
case 'SESSION_USER_EXIT':
delete tabs[action.uid];
break;
}
next(action);
};