mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
session: improve title subscriptions
This commit is contained in:
parent
81bfbd6006
commit
2f2268906a
1 changed files with 11 additions and 5 deletions
16
session.js
16
session.js
|
|
@ -40,19 +40,24 @@ module.exports = class Session extends EventEmitter {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.shell = defaultShell;
|
||||||
this.getTitle();
|
this.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
focus () {
|
focus () {
|
||||||
this.getTitle(true);
|
this.subscribed = true;
|
||||||
|
this.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
blur () {
|
blur () {
|
||||||
|
this.subscribed = false;
|
||||||
clearTimeout(this.titlePoll);
|
clearTimeout(this.titlePoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTitle (subscribe = false) {
|
getTitle () {
|
||||||
if ('win32' === process.platform) return;
|
if ('win32' === process.platform) return;
|
||||||
|
if (this.fetching) return;
|
||||||
|
this.fetching = true;
|
||||||
|
|
||||||
let tty = this.pty.stdout.ttyname;
|
let tty = this.pty.stdout.ttyname;
|
||||||
tty = tty.replace(/^\/dev\/tty/, '');
|
tty = tty.replace(/^\/dev\/tty/, '');
|
||||||
|
|
@ -64,6 +69,7 @@ module.exports = class Session extends EventEmitter {
|
||||||
// TODO: limit the concurrency of how many processes we run?
|
// TODO: limit the concurrency of how many processes we run?
|
||||||
// TODO: only tested on mac
|
// TODO: only tested on mac
|
||||||
exec(`ps uxac | grep ${tty} | head -n 1`, (err, out) => {
|
exec(`ps uxac | grep ${tty} | head -n 1`, (err, out) => {
|
||||||
|
this.fetching = false;
|
||||||
if (this.ended) return;
|
if (this.ended) return;
|
||||||
if (err) return;
|
if (err) return;
|
||||||
let title = out.split(' ').pop();
|
let title = out.split(' ').pop();
|
||||||
|
|
@ -76,8 +82,8 @@ module.exports = class Session extends EventEmitter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subscribe) {
|
if (this.subscribed) {
|
||||||
this.titlePoll = setTimeout(() => this.getTitle(true), TITLE_POLL_INTERVAL);
|
this.titlePoll = setTimeout(() => this.getTitle(), TITLE_POLL_INTERVAL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +112,7 @@ module.exports = class Session extends EventEmitter {
|
||||||
}
|
}
|
||||||
this.emit('exit');
|
this.emit('exit');
|
||||||
this.ended = true;
|
this.ended = true;
|
||||||
clearTimeout(this.titlePoll);
|
this.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue