From 7d3620e12d39fbed66f5760e81af6dee2dcac474 Mon Sep 17 00:00:00 2001 From: Thomas Buckley-Houston Date: Tue, 5 Jun 2018 18:50:10 +0800 Subject: [PATCH] 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. --- .travis.yml | 2 +- webext/src/background/common_mixin.js | 1 + webext/src/background/manager.js | 4 +++- webext/src/background/tab_commands_mixin.js | 21 ++++++++++++++++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 674bbb1..683636a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/webext/src/background/common_mixin.js b/webext/src/background/common_mixin.js index 16ac47e..4e8d78e 100644 --- a/webext/src/background/common_mixin.js +++ b/webext/src/background/common_mixin.js @@ -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); } diff --git a/webext/src/background/manager.js b/webext/src/background/manager.js index 052c5d1..cafa620 100644 --- a/webext/src/background/manager.js +++ b/webext/src/background/manager.js @@ -264,7 +264,9 @@ export default class extends utils.mixins(CommonMixin, TTYCommandsMixin) { let message; if (e.type == 'main_frame') { message = `Loading ${e.url}`; - this.currentTab().updateStatus('info', message); + if (this.currentTab() !== undefined) { + this.currentTab().updateStatus('info', message); + } } }, {urls: ['*://*/*']}, diff --git a/webext/src/background/tab_commands_mixin.js b/webext/src/background/tab_commands_mixin.js index eea5981..00df60b 100644 --- a/webext/src/background/tab_commands_mixin.js +++ b/webext/src/background/tab_commands_mixin.js @@ -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') + ); } };