HTTP Service: don't delete tab if last remaining

Previously we were using the tab's ID to decide if it was the root tab
(that if deleted would close the browser). However our ol' "friend" the
Firefox Privacy tab can sometimes take the TAB ID=1 hotspot, so now we
just have to call out to the browser to ask it how many tabs are
currently loaded, this is more reliable.
This commit is contained in:
Thomas Buckley-Houston 2018-06-05 18:50:10 +08:00
parent 3d39cf8b6d
commit 7d3620e12d
4 changed files with 25 additions and 3 deletions

View file

@ -35,7 +35,7 @@ install:
script:
- cd $REPO_ROOT/webext && npm test
- cd $REPO_ROOT/interfacer && go test src/browsh/*.go -v
- cd $REPO_ROOT/interfacer && go test test/tty/*.go -v
- cd $REPO_ROOT/interfacer && go test test/tty/*.go -v -ginkgo.flakeAttempts=3
- cd $REPO_ROOT/interfacer && go test test/http-server/*.go -v
after_failure:
- cat $REPO_ROOT/interfacer/test/tty/debug.log

View file

@ -12,6 +12,7 @@ export default (MixinBase) => class extends MixinBase {
}
sendToTerminal(message) {
if (this.terminal === undefined) { return }
if (this.terminal.readyState === 1) {
this.terminal.send(message);
}

View file

@ -264,8 +264,10 @@ export default class extends utils.mixins(CommonMixin, TTYCommandsMixin) {
let message;
if (e.type == 'main_frame') {
message = `Loading ${e.url}`;
if (this.currentTab() !== undefined) {
this.currentTab().updateStatus('info', message);
}
}
},
{urls: ['*://*/*']},
["blocking"]

View file

@ -48,6 +48,25 @@ export default (MixinBase) => class extends MixinBase {
_rawTextRequest(incoming) {
incoming.request_id = this.request_id;
this.sendToTerminal(`/raw_text,${JSON.stringify(incoming)}`);
if (this.id !== 1) { this.remove() }
this._tabCount((count) => {
if (count > 1) { this.remove(); }
});
}
_tabCount(callback) {
this._getAllTabs((windowInfoArray) => {
callback(windowInfoArray.length);
});
}
_getAllTabs(callback) {
var getting = browser.windows.getAll({
populate: true,
windowTypes: ["normal"]
});
getting.then(
(windowInfoArray) => callback(windowInfoArray),
() => this.log('Error getting all tabs in Tab class')
);
}
};