diff --git a/app/index.js b/app/index.js index 0b8b7515..7bf09f49 100644 --- a/app/index.js +++ b/app/index.js @@ -194,11 +194,6 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { rpc.emit('session data', {uid, data}); }); - session.on('title', title => { - win.setTitle(title); - rpc.emit('session title', {uid, title}); - }); - session.on('exit', () => { rpc.emit('session exit', {uid}); sessions.delete(uid); @@ -206,30 +201,6 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { }); }); - // TODO: this goes away when we are able to poll - // for the title ourselves, instead of relying - // on Session and focus/blur to subscribe - rpc.on('focus', ({uid}) => { - const session = sessions.get(uid); - if (typeof session !== 'undefined' && typeof session.lastTitle !== 'undefined') { - win.setTitle(session.lastTitle); - } - if (session) { - session.focus(); - } else { - console.log('session not found by', uid); - } - }); - rpc.on('blur', ({uid}) => { - const session = sessions.get(uid); - - if (session) { - session.blur(); - } else { - console.log('session not found by', uid); - } - }); - rpc.on('exit', ({uid}) => { const session = sessions.get(uid); if (session) { diff --git a/app/session.js b/app/session.js index 41cac284..9f75439f 100644 --- a/app/session.js +++ b/app/session.js @@ -1,4 +1,3 @@ -const {exec} = require('child_process'); const {EventEmitter} = require('events'); const {StringDecoder} = require('string_decoder'); @@ -21,8 +20,6 @@ try { ); } -const TITLE_POLL_INTERVAL = 500; - const envFromConfig = config.getConfig().env || {}; module.exports = class Session extends EventEmitter { @@ -62,60 +59,6 @@ module.exports = class Session extends EventEmitter { }); this.shell = shell || defaultShell; - this.getTitle(); - } - - focus() { - this.subscribed = true; - this.getTitle(); - } - - blur() { - this.subscribed = false; - clearTimeout(this.titlePoll); - } - - getTitle() { - if (process.platform === 'win32') { - return; - } - - if (this.fetching) { - return; - } - this.fetching = true; - - let tty = this.pty.stdout.ttyname; - tty = tty.replace(/^\/dev\/tty/, ''); - - // try to exclude grep from the results - // by grepping for `[s]001` instead of `s001` - tty = `[${tty[0]}]${tty.substr(1)}`; - - // TODO: limit the concurrency of how many processes we run? - // TODO: only tested on mac - exec(`ps uxac | grep ${tty} | head -n 1`, (err, out) => { - this.fetching = false; - if (this.ended) { - return; - } - if (err) { - return; - } - let title = out.split(' ').pop(); - if (title) { - title = title.replace(/^\(/, ''); - title = title.replace(/\)?\n$/, ''); - if (title !== this.lastTitle) { - this.emit('title', title); - this.lastTitle = title; - } - } - - if (this.subscribed) { - this.titlePoll = setTimeout(() => this.getTitle(), TITLE_POLL_INTERVAL); - } - }); } exit() { @@ -142,7 +85,6 @@ module.exports = class Session extends EventEmitter { } this.emit('exit'); this.ended = true; - this.blur(); } }; diff --git a/lib/actions/sessions.js b/lib/actions/sessions.js index 34c986d0..7fc0dec1 100644 --- a/lib/actions/sessions.js +++ b/lib/actions/sessions.js @@ -15,8 +15,7 @@ import { SESSION_USER_DATA, SESSION_URL_SET, SESSION_URL_UNSET, - SESSION_SET_XTERM_TITLE, - SESSION_SET_PROCESS_TITLE + SESSION_SET_XTERM_TITLE } from '../constants/sessions'; export function addSession({uid, shell, pid, cols, rows, splitDirection}) { @@ -127,14 +126,6 @@ export function clearActiveSession() { }; } -export function setSessionProcessTitle(uid, title) { - return { - type: SESSION_SET_PROCESS_TITLE, - uid, - title - }; -} - export function setSessionXtermTitle(uid, title) { return { type: SESSION_SET_XTERM_TITLE, diff --git a/lib/components/term.js b/lib/components/term.js index 1378e362..4f8a1ff8 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -69,6 +69,10 @@ export default class Term extends Component { this.term.modifierKeys = props.modifierKeys; // this.term.CursorNode_ is available at this point. this.term.setCursorShape(props.cursorShape); + + // emit onTitle event when hterm instance + // wants to set the title of its tab + this.term.setWindowTitle = props.onTitle; }; this.term.decorate(this.termRef); this.term.installKeyboard(); diff --git a/lib/constants/sessions.js b/lib/constants/sessions.js index 940a2bf6..aed788a1 100644 --- a/lib/constants/sessions.js +++ b/lib/constants/sessions.js @@ -11,5 +11,4 @@ export const SESSION_USER_DATA = 'SESSION_USER_DATA'; export const SESSION_URL_SET = 'SESSION_URL_SET'; export const SESSION_URL_UNSET = 'SESSION_URL_UNSET'; export const SESSION_SET_XTERM_TITLE = 'SESSION_SET_XTERM_TITLE'; -export const SESSION_SET_PROCESS_TITLE = 'SESSION_SET_PROCESS_TITLE'; export const SESSION_SET_CWD = 'SESSION_SET_CWD'; diff --git a/lib/index.js b/lib/index.js index 55908f4d..d896e202 100644 --- a/lib/index.js +++ b/lib/index.js @@ -52,10 +52,6 @@ rpc.on('session data send', ({uid, data}) => { store_.dispatch(sessionActions.sendSessionData(uid, data)); }); -rpc.on('session title', ({uid, title}) => { - store_.dispatch(sessionActions.setSessionProcessTitle(uid, title)); -}); - rpc.on('session exit', ({uid}) => { store_.dispatch(termGroupActions.ptyExitTermGroup(uid)); }); diff --git a/lib/reducers/sessions.js b/lib/reducers/sessions.js index 512b1e63..586037fe 100644 --- a/lib/reducers/sessions.js +++ b/lib/reducers/sessions.js @@ -10,8 +10,7 @@ import { SESSION_URL_SET, SESSION_URL_UNSET, SESSION_RESIZE, - SESSION_SET_XTERM_TITLE, - SESSION_SET_PROCESS_TITLE + SESSION_SET_XTERM_TITLE } from '../constants/sessions'; const initialState = Immutable({ @@ -94,7 +93,6 @@ const reducer = (state = initialState, action) => { return deleteSession(state, action.uid); case SESSION_SET_XTERM_TITLE: - case SESSION_SET_PROCESS_TITLE: return state.setIn(['sessions', action.uid, 'title'], action.title); case SESSION_RESIZE: