Skip to content

Commit

Permalink
HTTP Service: don't delete tab if last remaining
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tombh committed Jun 5, 2018
1 parent 3d39cf8 commit 7d3620e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions webext/src/background/common_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion webext/src/background/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: ['*://*/*']},
Expand Down
21 changes: 20 additions & 1 deletion webext/src/background/tab_commands_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}
};

0 comments on commit 7d3620e

Please sign in to comment.