Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions app/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {app} = require('electron');
const uuid = require('uuid');
const {openConfig} = require('./config');
const {updatePlugins} = require('./plugins');
const {installCLI} = require('./utils/cli-install');
Expand All @@ -10,16 +11,16 @@ const commands = {
},
'tab:new': focusedWindow => {
if (focusedWindow) {
focusedWindow.rpc.emit('termgroup add req');
focusedWindow.rpc.emit('termgroup add req', {termGroupUid: uuid.v4(), sessionUid: uuid.v4()});
} else {
setTimeout(app.createWindow, 0);
}
},
'pane:splitVertical': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('split request vertical');
focusedWindow && focusedWindow.rpc.emit('split request vertical', {sessionUid: uuid.v4()});
},
'pane:splitHorizontal': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('split request horizontal');
focusedWindow && focusedWindow.rpc.emit('split request horizontal', {sessionUid: uuid.v4()});
},
'pane:close': focusedWindow => {
focusedWindow && focusedWindow.rpc.emit('termgroup close req');
Expand Down
13 changes: 13 additions & 0 deletions app/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,19 @@ exports.onWindow = win => {
});
};

exports.extendSession = (window, opts, newSession) => {
modules.forEach(plugin => {
if (plugin.extendSession) {
try {
newSession = plugin.extendSession(window, opts, newSession);
} catch (e) {
notify('Plugin error!', `"${plugin._name}" has encountered an error. Check Developer Tools for details.`);
}
}
});
return newSession;
};

// decorates the base object by calling plugin[key]
// for all the available plugins
function decorateObject(base, key) {
Expand Down
13 changes: 10 additions & 3 deletions app/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ try {
const envFromConfig = config.getConfig().env || {};

module.exports = class Session extends EventEmitter {
constructor({rows, cols: columns, cwd, shell, shellArgs}) {
const osLocale = require('os-locale');
constructor() {
super();
}

init({rows, cols: columns, cwd, shell, shellArgs}) {
const osLocale = require('os-locale');
const baseEnv = Object.assign(
{},
process.env,
Expand Down Expand Up @@ -68,7 +71,7 @@ module.exports = class Session extends EventEmitter {
if (this.ended) {
return;
}
this.emit('data', decoder.write(data));
this.read(decoder.write(data));
});

this.pty.on('exit', () => {
Expand All @@ -85,6 +88,10 @@ module.exports = class Session extends EventEmitter {
this.destroy();
}

read(data) {
this.emit('data', data);
}

write(data) {
this.pty.write(data);
}
Expand Down
15 changes: 10 additions & 5 deletions app/ui/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class Window {
// If no callback is passed to createWindow,
// a new session will be created by default.
if (!fn) {
fn = win => win.rpc.emit('termgroup add req');
fn = win => win.rpc.emit('termgroup add req', {termGroupUid: uuid.v4(), sessionUid: uuid.v4()});
}

// app.windowCallback is the createWindow callback
Expand Down Expand Up @@ -99,7 +99,10 @@ module.exports = class Window {
);

const initSession = (opts, fn_) => {
fn_(uuid.v4(), new Session(opts));
const session = new Session();
const newSession = app.plugins.extendSession(window, opts, session);
newSession.init(opts);
fn_(opts.sessionUid, newSession);
};

initSession(sessionOpts, (uid, session) => {
Expand All @@ -110,11 +113,13 @@ module.exports = class Window {
uid,
splitDirection: sessionOpts.splitDirection,
shell: session.shell,
pid: session.pty.pid
pid: session.pty ? session.pty.pid : null,
termGroupUid: sessionOpts.termGroupUid,
activeUid: sessionOpts.activeUid
});

session.on('data', data => {
rpc.emit('session data', uid + data);
rpc.emit('session data', {uid, data});
});

session.on('exit', () => {
Expand Down Expand Up @@ -188,8 +193,8 @@ module.exports = class Window {
const deleteSessions = () => {
sessions.forEach((session, key) => {
session.removeAllListeners();
session.destroy();
sessions.delete(key);
session.destroy();
});
};
// we reset the rpc channel only upon
Expand Down
7 changes: 4 additions & 3 deletions lib/actions/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SESSION_SET_XTERM_TITLE
} from '../constants/sessions';

export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
export function addSession({uid, shell, pid, cols, rows, splitDirection, termGroupUid, activeUid}) {
return (dispatch, getState) => {
const {sessions} = getState();
const now = Date.now();
Expand All @@ -30,8 +30,9 @@ export function addSession({uid, shell, pid, cols, rows, splitDirection}) {
cols,
rows,
splitDirection,
activeUid: sessions.activeUid,
now
activeUid: activeUid ? activeUid : sessions.activeUid,
now,
termGroupUid
});
};
}
Expand Down
14 changes: 9 additions & 5 deletions lib/actions/term-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import getRootGroups from '../selectors';
import {setActiveSession, ptyExitSession, userExitSession} from './sessions';

function requestSplit(direction) {
return () => (dispatch, getState) => {
return (sessionUid, activeUid) => (dispatch, getState) => {
dispatch({
type: SESSION_REQUEST,
effect: () => {
const {ui} = getState();
const {ui, sessions} = getState();
rpc.emit('new', {
splitDirection: direction,
cwd: ui.cwd
cwd: ui.cwd,
sessionUid,
activeUid: activeUid ? activeUid : sessions.activeUid
});
}
});
Expand All @@ -37,7 +39,7 @@ export function resizeTermGroup(uid, sizes) {
};
}

export function requestTermGroup() {
export function requestTermGroup(termGroupUid, sessionUid) {
return (dispatch, getState) => {
dispatch({
type: TERM_GROUP_REQUEST,
Expand All @@ -48,7 +50,9 @@ export function requestTermGroup() {
isNewGroup: true,
cols,
rows,
cwd
cwd,
termGroupUid,
sessionUid
});
}
});
Expand Down
17 changes: 7 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ rpc.on('session add', data => {
store_.dispatch(sessionActions.addSession(data));
});

rpc.on('session data', d => {
// the uid is a uuid v4 so it's 36 chars long
const uid = d.slice(0, 36);
const data = d.slice(36);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chabou Why was this done instead of using an object? Let me know if you want me to revert this part of the PR (I have no idea why to encode the uid + data in this way, but there may be a reason).

rpc.on('session data', ({uid, data}) => {
store_.dispatch(sessionActions.addSessionData(uid, data));
});

Expand Down Expand Up @@ -103,16 +100,16 @@ rpc.on('session break req', () => {
store_.dispatch(sessionActions.sendSessionData(null, '\x03'));
});

rpc.on('termgroup add req', () => {
store_.dispatch(termGroupActions.requestTermGroup());
rpc.on('termgroup add req', ({termGroupUid, sessionUid}) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will these params always be undefined without your plugin? 🤔
This is a problem. It adds some complexity than a newcomer can't understand.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. Let me set them upstream

store_.dispatch(termGroupActions.requestTermGroup(termGroupUid, sessionUid));
});

rpc.on('split request horizontal', () => {
store_.dispatch(termGroupActions.requestHorizontalSplit());
rpc.on('split request horizontal', ({sessionUid, activeUid}) => {
store_.dispatch(termGroupActions.requestHorizontalSplit(sessionUid, activeUid));
});

rpc.on('split request vertical', () => {
store_.dispatch(termGroupActions.requestVerticalSplit());
rpc.on('split request vertical', ({sessionUid, activeUid}) => {
store_.dispatch(termGroupActions.requestVerticalSplit(sessionUid, activeUid));
});

rpc.on('reset fontSize req', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/reducers/term-groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const reducer = (state = initialState, action) => {
return setActiveGroup(state, action);
}

const uid = uuid.v4();
const uid = action.termGroupUid;
const termGroup = TermGroup({
uid,
sessionUid: action.uid
Expand Down