Skip to content

Commit

Permalink
Fixes bug in HTTP Service rendering
Browse files Browse the repository at this point in the history
I think with the recent change to the method of hiding text by using a
dedicated blank font, the initial page load and parsing (upon which the
HTTP Service very much depends), browser window resizes were causing a
delay in the time taken for text to be properly parsed, resulting in
mostly empty raw text pages.

The fix was to ensure that the BlankMono.ttf font was loaded with the
initial page load, by using the webextensions injected style.css file.
  • Loading branch information
tombh committed Jun 4, 2018
1 parent cc23f0a commit 72c74f1
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
3 changes: 2 additions & 1 deletion webext/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ html * {
}

.browsh-hide-text,
.browsh-hide-text * {
.browsh-hide-text *,
html * {
font-family: 'BlankMono' !important;
}

Expand Down
9 changes: 6 additions & 3 deletions webext/src/background/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default class extends utils.mixins(CommonMixin) {
if (this.char.width != incoming.width ||
this.char.height != incoming.height) {
this.char = _.clone(incoming);
this.log(
`Requesting browser resize for new char dimensions: ` +
`${this.char.width}x${this.char.height}`
);
this.resizeBrowserWindow();
}
}
Expand Down Expand Up @@ -57,7 +61,6 @@ export default class extends utils.mixins(CommonMixin) {

_sendWindowResizeRequest(active_window, width, height) {
const tag = 'Resizing browser window';
this.log(tag, active_window, width, height);
const updating = browser.windows.update(
active_window.id,
{
Expand All @@ -67,8 +70,8 @@ export default class extends utils.mixins(CommonMixin) {
}
);
updating.then(
info => this.log(tag, info),
error => this.log(tag, error)
info => this.log(`${tag} successful (${info.width}x${info.height})`),
error => this.log(tag + " error: ", error)
);
}
}
4 changes: 4 additions & 0 deletions webext/src/background/tty_commands_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export default (MixinBase) => class extends MixinBase {
`/tty_size,${this.dimensions.tty.width},${this.dimensions.tty.height}`
)
}
this.log(
`Requesting browser resize for new TTY dimensions: ` +
`${width}x${height}`
);
this.dimensions.resizeBrowserWindow();
}

Expand Down
3 changes: 0 additions & 3 deletions webext/src/dom/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export default class extends utils.mixins(CommonMixin) {
x_last_big_frame: 0,
y_last_big_frame: 0
}
if (document.body) {
this.update();
}
}

update() {
Expand Down
1 change: 0 additions & 1 deletion webext/src/dom/graphics_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ export default class extends utils.mixins(CommonMixin) {
}

_getScreenshot() {
this.dimensions.update()
return this._getPixelData();
}

Expand Down
1 change: 0 additions & 1 deletion webext/src/dom/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default class extends utils.mixins(CommonMixin, CommandsMixin) {

_postCommsConstructor() {
this.dimensions.channel = this.channel;
this.dimensions.update();
this.graphics_builder = new GraphicsBuilder(this.channel, this.dimensions);
this.text_builder = new TextBuilder(
this.channel,
Expand Down
11 changes: 9 additions & 2 deletions webext/src/dom/text_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ export default class extends utils.mixins(CommonMixin) {
}

sendRawText() {
this.buildFormattedText();
this._sendRawText();
// TODO:
// The presence of the `getScreenshotWithText()` and `setTimeout()` calls are a hack
// that I am unable to understand the reasoning for - unfortunately they came about
// by trial and error :( Without them the the returned raw text is largely empty.
this.graphics_builder.getScreenshotWithText();
setTimeout(() => {
this.buildFormattedText();
this._sendRawText();
}, 200);
}

buildFormattedText() {
Expand Down

0 comments on commit 72c74f1

Please sign in to comment.