mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Optimistic session creation (#3352)
* Optimistically creating a session when a window is created to improve launch time * Fix linting issues
This commit is contained in:
parent
f324a67bb9
commit
a5309082b6
1 changed files with 51 additions and 20 deletions
|
|
@ -87,6 +87,34 @@ module.exports = class Window {
|
|||
}
|
||||
});
|
||||
|
||||
function createSession(options) {
|
||||
const uid = uuid.v4();
|
||||
const session = new Session(Object.assign({}, options, {uid}));
|
||||
sessions.set(uid, session);
|
||||
return {uid, session};
|
||||
}
|
||||
|
||||
// Optimistically create the initial session so that when the window sends
|
||||
// the first "new" IPC message, there's a session already warmed up.
|
||||
function createInitialSession() {
|
||||
let {session, uid} = createSession({});
|
||||
const initialEvents = [];
|
||||
const handleData = data => initialEvents.push(['session data', uid + data]);
|
||||
const handleExit = () => initialEvents.push(['session exit']);
|
||||
session.on('data', handleData);
|
||||
session.on('exit', handleExit);
|
||||
|
||||
function flushEvents() {
|
||||
for (let args of initialEvents) {
|
||||
rpc.emit(...args);
|
||||
}
|
||||
session.removeListener('data', handleData);
|
||||
session.removeListener('exit', handleExit);
|
||||
}
|
||||
return {session, uid, flushEvents};
|
||||
}
|
||||
let initialSession = createInitialSession();
|
||||
|
||||
rpc.on('new', options => {
|
||||
let cwd = null;
|
||||
if (workingDirectory) {
|
||||
|
|
@ -108,29 +136,32 @@ module.exports = class Window {
|
|||
options
|
||||
);
|
||||
|
||||
const initSession = (opts, fn_) => {
|
||||
fn_(uuid.v4(), new Session(opts));
|
||||
};
|
||||
const {uid, session} = initialSession || createSession();
|
||||
|
||||
initSession(sessionOpts, (uid, session) => {
|
||||
sessions.set(uid, session);
|
||||
rpc.emit('session add', {
|
||||
rows: sessionOpts.rows,
|
||||
cols: sessionOpts.cols,
|
||||
uid,
|
||||
splitDirection: sessionOpts.splitDirection,
|
||||
shell: session.shell,
|
||||
pid: session.pty.pid
|
||||
});
|
||||
sessions.set(uid, session);
|
||||
rpc.emit('session add', {
|
||||
rows: sessionOpts.rows,
|
||||
cols: sessionOpts.cols,
|
||||
uid,
|
||||
splitDirection: sessionOpts.splitDirection,
|
||||
shell: session.shell,
|
||||
pid: session.pty.pid
|
||||
});
|
||||
|
||||
session.on('data', data => {
|
||||
rpc.emit('session data', uid + data);
|
||||
});
|
||||
// If this is the initial session, flush any events that might have
|
||||
// occurred while the window was initializing
|
||||
if (initialSession) {
|
||||
initialSession.flushEvents();
|
||||
initialSession = null;
|
||||
}
|
||||
|
||||
session.on('exit', () => {
|
||||
rpc.emit('session exit', {uid});
|
||||
sessions.delete(uid);
|
||||
});
|
||||
session.on('data', data => {
|
||||
rpc.emit('session data', uid + data);
|
||||
});
|
||||
|
||||
session.on('exit', () => {
|
||||
rpc.emit('session exit', {uid});
|
||||
sessions.delete(uid);
|
||||
});
|
||||
});
|
||||
rpc.on('exit', ({uid}) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue