From f1c23868e60ec0f9dcd4655896087b3553bc4f87 Mon Sep 17 00:00:00 2001 From: Jason Gauci Date: Sat, 12 May 2018 21:35:07 -0700 Subject: [PATCH] Second pass at support for HTM in Hyper.js --- app/commands.js | 6 +++--- app/ui/window.js | 25 +++++++++++++++++-------- lib/actions/sessions.js | 7 ++++--- lib/actions/term-groups.js | 14 +++++++++----- lib/index.js | 17 +++++++---------- lib/reducers/term-groups.js | 5 ++++- 6 files changed, 44 insertions(+), 30 deletions(-) diff --git a/app/commands.js b/app/commands.js index ad848260fc4f..cd3b5d1b1d9a 100644 --- a/app/commands.js +++ b/app/commands.js @@ -9,16 +9,16 @@ const commands = { }, 'tab:new': focusedWindow => { if (focusedWindow) { - focusedWindow.rpc.emit('termgroup add req'); + focusedWindow.rpc.emit('termgroup add req', {}); } else { setTimeout(app.createWindow, 0); } }, 'pane:splitVertical': focusedWindow => { - focusedWindow && focusedWindow.rpc.emit('split request vertical'); + focusedWindow && focusedWindow.rpc.emit('split request vertical', {}); }, 'pane:splitHorizontal': focusedWindow => { - focusedWindow && focusedWindow.rpc.emit('split request horizontal'); + focusedWindow && focusedWindow.rpc.emit('split request horizontal', {}); }, 'pane:close': focusedWindow => { focusedWindow && focusedWindow.rpc.emit('termgroup close req'); diff --git a/app/ui/window.js b/app/ui/window.js index 923cfe42e9a8..a02feea8374e 100644 --- a/app/ui/window.js +++ b/app/ui/window.js @@ -4,6 +4,7 @@ const {parse: parseUrl} = require('url'); const uuid = require('uuid'); const fileUriToPath = require('file-uri-to-path'); const isDev = require('electron-is-dev'); + const updater = require('../updater'); const toElectronBackgroundColor = require('../utils/to-electron-background-color'); const {icon, cfgDir} = require('../config/paths'); @@ -66,7 +67,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', {}); } // app.windowCallback is the createWindow callback @@ -98,11 +99,7 @@ module.exports = class Window { options ); - const initSession = (opts, fn_) => { - fn_(uuid.v4(), new Session(opts)); - }; - - initSession(sessionOpts, (uid, session) => { + window.initSession(sessionOpts, (uid, session) => { sessions.set(uid, session); rpc.emit('session add', { rows: sessionOpts.rows, @@ -110,11 +107,15 @@ module.exports = class Window { uid, splitDirection: sessionOpts.splitDirection, shell: session.shell, - pid: session.pty.pid + pid: typeof session.pty !== 'undefined' ? session.pty.pid : null, + termGroupUid: sessionOpts.termGroupUid, + activeUid: sessionOpts.activeUid }); session.on('data', data => { - rpc.emit('session data', uid + data); + window.handleSessionData(uid, data, (innerUid, innerData) => { + rpc.emit('session data', {uid: innerUid, data: innerData}); + }); }); session.on('exit', () => { @@ -158,6 +159,14 @@ module.exports = class Window { session.write(data); } }); + window.initSession = (opts, fn_) => { + fn_(uuid.v4(), new Session(opts)); + }; + + window.handleSessionData = (uid, data, handleSessionCallback) => { + // By default, just execute the callback. Plugins can override. + return handleSessionCallback(uid, data); + }; rpc.on('open external', ({url}) => { shell.openExternal(url); }); diff --git a/lib/actions/sessions.js b/lib/actions/sessions.js index b48b9165aaca..146e444c8a5f 100644 --- a/lib/actions/sessions.js +++ b/lib/actions/sessions.js @@ -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(); @@ -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 }); }; } diff --git a/lib/actions/term-groups.js b/lib/actions/term-groups.js index 3c2940ac7b4a..b90be509e65a 100644 --- a/lib/actions/term-groups.js +++ b/lib/actions/term-groups.js @@ -12,14 +12,16 @@ import getRootGroups from '../selectors'; import {setActiveSession, ptyExitSession, userExitSession} from './sessions'; function requestSplit(direction) { - return () => (dispatch, getState) => { + return (sessionUid, sourceUid) => (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: sourceUid ? sourceUid : sessions.activeUid }); } }); @@ -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, @@ -48,7 +50,9 @@ export function requestTermGroup() { isNewGroup: true, cols, rows, - cwd + cwd, + termGroupUid, + sessionUid }); } }); diff --git a/lib/index.js b/lib/index.js index 034523c80f37..90c9b43a8ed9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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); +rpc.on('session data', ({uid, data}) => { store_.dispatch(sessionActions.addSessionData(uid, data)); }); @@ -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}) => { + store_.dispatch(termGroupActions.requestTermGroup(termGroupUid, sessionUid)); }); -rpc.on('split request horizontal', () => { - store_.dispatch(termGroupActions.requestHorizontalSplit()); +rpc.on('split request horizontal', ({sessionUid, sourceUid}) => { + store_.dispatch(termGroupActions.requestHorizontalSplit(sessionUid, sourceUid)); }); -rpc.on('split request vertical', () => { - store_.dispatch(termGroupActions.requestVerticalSplit()); +rpc.on('split request vertical', ({sessionUid, sourceUid}) => { + store_.dispatch(termGroupActions.requestVerticalSplit(sessionUid, sourceUid)); }); rpc.on('reset fontSize req', () => { diff --git a/lib/reducers/term-groups.js b/lib/reducers/term-groups.js index ad14152e8fe1..3fe72f861c24 100644 --- a/lib/reducers/term-groups.js +++ b/lib/reducers/term-groups.js @@ -192,7 +192,10 @@ const reducer = (state = initialState, action) => { return setActiveGroup(state, action); } - const uid = uuid.v4(); + let uid = uuid.v4(); + if (action.termGroupUid) { + uid = action.termGroupUid; + } const termGroup = TermGroup({ uid, sessionUid: action.uid