Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix demo again #4193

Merged
merged 4 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion addons/xterm-addon-canvas/src/CanvasAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class CanvasAddon extends Disposable implements ITerminalAddon {
public activate(terminal: Terminal): void {
const core = (terminal as any)._core;
if (!terminal.element) {
this.register(core.onWillOpen(() => this.activate(terminal)));
this.register(toDisposable(() => {
core.onWillOpen(() => this.activate(terminal));
}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change may not be needed? Regardless this won't work as it will only attach the onWillOpen event after the webgl renderer is disposed. The intent with that is to allow loading webgl/canvas without calling Terminal.open yet

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I understand it. So, I've added a try-catch around terminal.open, but it fails somewhere else then. It looks like the terminal remains broken when it needs to fallback to a different renderer such as canvas or dom.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the dom renderer back now, but the demo fails to see that the webgl didn't load, since the error is handled silently in terminal.ts now. It should be thrown again at the end of the terminal initialization.

return;
}

Expand Down
4 changes: 3 additions & 1 deletion addons/xterm-addon-webgl/src/WebglAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
}
const core = (terminal as any)._core;
if (!terminal.element) {
this.register(core.onWillOpen(() => this.activate(terminal)));
this.register(toDisposable(() => {
core.onWillOpen(() => this.activate(terminal));
}));
return;
}
this._terminal = terminal;
Expand Down
15 changes: 10 additions & 5 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,16 @@ function createTerminal(): void {
socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/terminals/';

addons.fit.instance!.fit();
typedTerm.loadAddon(addons.webgl.instance);
setTimeout(() => {
addTextureAtlas(addons.webgl.instance.textureAtlas);
addons.webgl.instance.onChangeTextureAtlas(e => addTextureAtlas(e));
}, 0);
try { // try-catch to allow the demo to load if webgl is not supported
typedTerm.loadAddon(addons.webgl.instance);
setTimeout(() => {
addTextureAtlas(addons.webgl.instance.textureAtlas);
addons.webgl.instance.onChangeTextureAtlas(e => addTextureAtlas(e));
}, 0);
}
catch {
addons.webgl.instance = undefined;
}

term.open(terminalContainer);
term.focus();
Expand Down