2016-07-13 12:44:24 -08:00
|
|
|
import rpc from '../rpc';
|
2016-09-21 06:27:11 -08:00
|
|
|
import {keys} from '../utils/object';
|
2016-10-25 04:53:15 -08:00
|
|
|
import findBySession from '../utils/term-groups';
|
2016-07-13 12:44:24 -08:00
|
|
|
import {
|
|
|
|
|
SESSION_ADD,
|
|
|
|
|
SESSION_RESIZE,
|
|
|
|
|
SESSION_REQUEST,
|
2017-09-25 03:55:04 -08:00
|
|
|
SESSION_ADD_DATA,
|
2016-07-13 12:44:24 -08:00
|
|
|
SESSION_PTY_DATA,
|
|
|
|
|
SESSION_PTY_EXIT,
|
|
|
|
|
SESSION_USER_EXIT,
|
|
|
|
|
SESSION_SET_ACTIVE,
|
|
|
|
|
SESSION_CLEAR_ACTIVE,
|
|
|
|
|
SESSION_USER_DATA,
|
2016-10-22 12:05:32 -08:00
|
|
|
SESSION_SET_XTERM_TITLE
|
2016-07-13 12:44:24 -08:00
|
|
|
} from '../constants/sessions';
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
const {sessions} = getState();
|
2017-10-03 14:18:55 -08:00
|
|
|
const now = Date.now();
|
2016-07-13 16:21:23 -08:00
|
|
|
dispatch({
|
2016-07-13 15:32:52 -08:00
|
|
|
type: SESSION_ADD,
|
2016-07-14 15:40:15 -08:00
|
|
|
uid,
|
2016-07-16 14:41:13 -08:00
|
|
|
shell,
|
2016-10-03 18:00:50 -08:00
|
|
|
pid,
|
|
|
|
|
cols,
|
|
|
|
|
rows,
|
|
|
|
|
splitDirection,
|
2017-10-03 14:18:55 -08:00
|
|
|
activeUid: sessions.activeUid,
|
|
|
|
|
now
|
2016-07-13 15:32:52 -08:00
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export function requestSession() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_REQUEST,
|
|
|
|
|
effect: () => {
|
2018-03-21 03:40:56 -08:00
|
|
|
const {ui} = getState();
|
|
|
|
|
const {cols, rows, cwd} = ui;
|
2016-09-21 06:27:11 -08:00
|
|
|
rpc.emit('new', {cols, rows, cwd});
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export function addSessionData(uid, data) {
|
2019-03-03 09:13:50 -09:00
|
|
|
return dispatch => {
|
2017-09-25 03:55:04 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_ADD_DATA,
|
|
|
|
|
data,
|
|
|
|
|
effect() {
|
2017-10-03 14:18:55 -08:00
|
|
|
const now = Date.now();
|
2017-09-25 03:55:04 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_PTY_DATA,
|
|
|
|
|
uid,
|
2017-10-03 14:18:55 -08:00
|
|
|
data,
|
|
|
|
|
now
|
2017-09-25 03:55:04 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
function createExitAction(type) {
|
|
|
|
|
return uid => (dispatch, getState) => {
|
2016-07-13 12:44:24 -08:00
|
|
|
return dispatch({
|
2016-10-03 18:00:50 -08:00
|
|
|
type,
|
2016-07-13 12:44:24 -08:00
|
|
|
uid,
|
2016-09-21 06:27:11 -08:00
|
|
|
effect() {
|
2016-10-03 18:00:50 -08:00
|
|
|
if (type === SESSION_USER_EXIT) {
|
|
|
|
|
rpc.emit('exit', {uid});
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-18 14:12:14 -08:00
|
|
|
const sessions = keys(getState().sessions.sessions);
|
2016-10-12 17:35:44 -08:00
|
|
|
if (sessions.length === 0) {
|
2016-07-18 14:12:14 -08:00
|
|
|
window.close();
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
// we want to distinguish an exit
|
|
|
|
|
// that's UI initiated vs pty initiated
|
|
|
|
|
export const userExitSession = createExitAction(SESSION_USER_EXIT);
|
|
|
|
|
export const ptyExitSession = createExitAction(SESSION_PTY_EXIT);
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export function setActiveSession(uid) {
|
2016-11-04 09:52:03 -08:00
|
|
|
return dispatch => {
|
2016-07-13 12:44:24 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_SET_ACTIVE,
|
2016-11-04 09:52:03 -08:00
|
|
|
uid
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export function clearActiveSession() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return {
|
|
|
|
|
type: SESSION_CLEAR_ACTIVE
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export function setSessionXtermTitle(uid, title) {
|
2016-07-13 12:44:24 -08:00
|
|
|
return {
|
|
|
|
|
type: SESSION_SET_XTERM_TITLE,
|
|
|
|
|
uid,
|
|
|
|
|
title
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export function resizeSession(uid, cols, rows) {
|
2016-10-03 18:00:50 -08:00
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
const {termGroups} = getState();
|
|
|
|
|
const group = findBySession(termGroups, uid);
|
|
|
|
|
const isStandaloneTerm = !group.parentUid && !group.children.length;
|
2017-10-03 14:18:55 -08:00
|
|
|
const now = Date.now();
|
2016-10-03 18:00:50 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_RESIZE,
|
|
|
|
|
uid,
|
|
|
|
|
cols,
|
|
|
|
|
rows,
|
|
|
|
|
isStandaloneTerm,
|
2017-10-03 14:18:55 -08:00
|
|
|
now,
|
2016-10-03 18:00:50 -08:00
|
|
|
effect() {
|
|
|
|
|
rpc.emit('resize', {uid, cols, rows});
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 08:12:03 -08:00
|
|
|
export function sendSessionData(uid, data, escaped) {
|
2017-09-10 05:35:10 -08:00
|
|
|
return (dispatch, getState) => {
|
2016-08-04 05:43:57 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_USER_DATA,
|
|
|
|
|
data,
|
2016-09-21 06:27:11 -08:00
|
|
|
effect() {
|
2016-10-10 02:26:47 -08:00
|
|
|
// If no uid is passed, data is sent to the active session.
|
2016-08-04 05:43:57 -08:00
|
|
|
const targetUid = uid || getState().sessions.activeUid;
|
2017-06-14 08:12:03 -08:00
|
|
|
|
|
|
|
|
rpc.emit('data', {uid: targetUid, data, escaped});
|
2016-08-04 05:43:57 -08:00
|
|
|
}
|
|
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
};
|
|
|
|
|
}
|