2016-07-13 12:44:24 -08:00
|
|
|
import rpc from '../rpc';
|
|
|
|
|
import getURL from '../utils/url-command';
|
|
|
|
|
import { keys } from '../utils/object';
|
|
|
|
|
import {
|
|
|
|
|
SESSION_ADD,
|
|
|
|
|
SESSION_RESIZE,
|
|
|
|
|
SESSION_REQUEST,
|
|
|
|
|
SESSION_ADD_DATA,
|
|
|
|
|
SESSION_PTY_DATA,
|
|
|
|
|
SESSION_PTY_EXIT,
|
|
|
|
|
SESSION_USER_EXIT,
|
|
|
|
|
SESSION_USER_EXIT_ACTIVE,
|
|
|
|
|
SESSION_SET_ACTIVE,
|
|
|
|
|
SESSION_CLEAR_ACTIVE,
|
|
|
|
|
SESSION_USER_DATA,
|
|
|
|
|
SESSION_URL_SET,
|
|
|
|
|
SESSION_URL_UNSET,
|
|
|
|
|
SESSION_SET_XTERM_TITLE,
|
|
|
|
|
SESSION_SET_PROCESS_TITLE
|
|
|
|
|
} from '../constants/sessions';
|
|
|
|
|
|
2016-07-16 14:41:13 -08:00
|
|
|
export function addSession (uid, shell, pid) {
|
2016-07-13 15:32:52 -08:00
|
|
|
return (dispatch, getState) => {
|
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,
|
|
|
|
|
pid
|
2016-07-13 15:32:52 -08:00
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function requestSession (uid) {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
const { ui } = getState();
|
2016-07-16 14:41:13 -08:00
|
|
|
const { cols, rows, cwd } = ui;
|
2016-07-13 12:44:24 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_REQUEST,
|
|
|
|
|
effect: () => {
|
2016-07-16 14:41:13 -08:00
|
|
|
rpc.emit('new', { cols, rows, cwd });
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function addSessionData (uid, data) {
|
2016-07-14 15:40:15 -08:00
|
|
|
return function (dispatch, getState) {
|
2016-07-13 12:44:24 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_ADD_DATA,
|
|
|
|
|
data,
|
|
|
|
|
effect () {
|
2016-07-14 15:40:15 -08:00
|
|
|
const { shell } = getState().sessions.sessions[uid];
|
2016-07-25 10:22:25 -08:00
|
|
|
|
|
|
|
|
const enterKey = Boolean(data.match(/\n/));
|
|
|
|
|
const url = enterKey ? getURL(shell, data) : null;
|
|
|
|
|
|
|
|
|
|
if (url) {
|
2016-07-13 12:44:24 -08:00
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_URL_SET,
|
|
|
|
|
uid,
|
|
|
|
|
url
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_PTY_DATA,
|
|
|
|
|
uid,
|
|
|
|
|
data
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function sessionExit (uid) {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
return dispatch({
|
|
|
|
|
type: SESSION_PTY_EXIT,
|
|
|
|
|
uid,
|
|
|
|
|
effect () {
|
|
|
|
|
// we reiterate the same logic as below
|
|
|
|
|
// for SESSION_USER_EXIT since the exit
|
|
|
|
|
// could happen pty side or optimistic
|
|
|
|
|
const sessions = keys(getState().sessions.sessions);
|
|
|
|
|
if (!sessions.length) {
|
|
|
|
|
window.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we want to distinguish an exit
|
|
|
|
|
// that's UI initiated vs pty initiated
|
|
|
|
|
export function userExitSession (uid) {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
return dispatch({
|
|
|
|
|
type: SESSION_USER_EXIT,
|
|
|
|
|
uid,
|
|
|
|
|
effect () {
|
2016-07-18 14:12:14 -08:00
|
|
|
rpc.emit('exit', { uid });
|
|
|
|
|
const sessions = keys(getState().sessions.sessions);
|
|
|
|
|
if (!sessions.length) {
|
|
|
|
|
window.close();
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function userExitActiveSession () {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_USER_EXIT_ACTIVE,
|
|
|
|
|
effect () {
|
|
|
|
|
const uid = getState().sessions.activeUid;
|
|
|
|
|
dispatch(userExitSession(uid));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setActiveSession (uid) {
|
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
const state = getState();
|
|
|
|
|
const prevUid = state.sessions.activeUid;
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_SET_ACTIVE,
|
|
|
|
|
uid,
|
|
|
|
|
effect () {
|
|
|
|
|
// TODO: this goes away when we are able to poll
|
|
|
|
|
// for the title ourseleves, instead of relying
|
|
|
|
|
// on Session and focus/blur to subscribe
|
|
|
|
|
if (prevUid) rpc.emit('blur', { uid: prevUid });
|
|
|
|
|
rpc.emit('focus', { uid });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function clearActiveSession () {
|
|
|
|
|
return {
|
|
|
|
|
type: SESSION_CLEAR_ACTIVE
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setSessionProcessTitle (uid, title) {
|
|
|
|
|
return {
|
|
|
|
|
type: SESSION_SET_PROCESS_TITLE,
|
|
|
|
|
uid,
|
|
|
|
|
title
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function setSessionXtermTitle (uid, title) {
|
|
|
|
|
return {
|
|
|
|
|
type: SESSION_SET_XTERM_TITLE,
|
|
|
|
|
uid,
|
|
|
|
|
title
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function resizeSession (uid, cols, rows) {
|
|
|
|
|
return {
|
|
|
|
|
type: SESSION_RESIZE,
|
|
|
|
|
cols,
|
|
|
|
|
rows,
|
|
|
|
|
effect () {
|
|
|
|
|
rpc.emit('resize', { cols, rows });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function sendSessionData (uid, data) {
|
2016-08-04 05:43:57 -08:00
|
|
|
return function (dispatch, getState) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: SESSION_USER_DATA,
|
|
|
|
|
data,
|
|
|
|
|
effect () {
|
|
|
|
|
// If no uid is passed, data is sended to the active session.
|
|
|
|
|
const targetUid = uid || getState().sessions.activeUid;
|
|
|
|
|
rpc.emit('data', { uid: targetUid, data });
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-07-13 12:44:24 -08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function exitSessionBrowser (uid) {
|
|
|
|
|
return {
|
|
|
|
|
type: SESSION_URL_UNSET,
|
|
|
|
|
uid
|
|
|
|
|
};
|
|
|
|
|
}
|