From bd661fdb071db5adb132722f1f946c32c0320ffe Mon Sep 17 00:00:00 2001 From: Simon Lamon Date: Sun, 9 Oct 2022 11:29:33 +0000 Subject: [PATCH 1/4] Fix demo again --- addons/xterm-addon-canvas/src/CanvasAddon.ts | 4 +++- addons/xterm-addon-webgl/src/WebglAddon.ts | 4 +++- demo/client.ts | 15 ++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/addons/xterm-addon-canvas/src/CanvasAddon.ts b/addons/xterm-addon-canvas/src/CanvasAddon.ts index 1dc607e5..dcd35704 100644 --- a/addons/xterm-addon-canvas/src/CanvasAddon.ts +++ b/addons/xterm-addon-canvas/src/CanvasAddon.ts @@ -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)); + })); return; } diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index 71487315..538713c2 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -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; diff --git a/demo/client.ts b/demo/client.ts index ea55d6d9..3228bd7f 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -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(); From 627410a53743a7fe420f99b7db7b48eef0b654eb Mon Sep 17 00:00:00 2001 From: Simon Lamon Date: Sun, 9 Oct 2022 14:26:08 +0000 Subject: [PATCH 2/4] Add broken demo to investigate --- addons/xterm-addon-canvas/src/CanvasAddon.ts | 4 +- addons/xterm-addon-webgl/src/WebglAddon.ts | 4 +- addons/xterm-addon-webgl/src/WebglRenderer.ts | 3 ++ demo/client.ts | 48 ++++++++++--------- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/addons/xterm-addon-canvas/src/CanvasAddon.ts b/addons/xterm-addon-canvas/src/CanvasAddon.ts index dcd35704..1dc607e5 100644 --- a/addons/xterm-addon-canvas/src/CanvasAddon.ts +++ b/addons/xterm-addon-canvas/src/CanvasAddon.ts @@ -25,9 +25,7 @@ export class CanvasAddon extends Disposable implements ITerminalAddon { public activate(terminal: Terminal): void { const core = (terminal as any)._core; if (!terminal.element) { - this.register(toDisposable(() => { - core.onWillOpen(() => this.activate(terminal)); - })); + this.register(core.onWillOpen(() => this.activate(terminal))); return; } diff --git a/addons/xterm-addon-webgl/src/WebglAddon.ts b/addons/xterm-addon-webgl/src/WebglAddon.ts index 538713c2..71487315 100644 --- a/addons/xterm-addon-webgl/src/WebglAddon.ts +++ b/addons/xterm-addon-webgl/src/WebglAddon.ts @@ -33,9 +33,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon { } const core = (terminal as any)._core; if (!terminal.element) { - this.register(toDisposable(() => { - core.onWillOpen(() => this.activate(terminal)); - })); + this.register(core.onWillOpen(() => this.activate(terminal))); return; } this._terminal = terminal; diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index ed99a225..8f747c03 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -103,6 +103,9 @@ export class WebglRenderer extends Disposable implements IRenderer { throw new Error('WebGL2 not supported ' + this._gl); } + // TODO: Remove me. + throw new Error('WebGL2 not supported ' + this._gl); + this.register(addDisposableDomListener(this._canvas, 'webglcontextlost', (e) => { console.log('webglcontextlost event received'); // Prevent the default behavior in order to enable WebGL context restoration. diff --git a/demo/client.ts b/demo/client.ts index 3228bd7f..6d48b302 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -61,26 +61,26 @@ interface IDemoAddon { canChange: boolean; ctor: ( T extends 'attach' ? typeof AttachAddon : - T extends 'canvas' ? typeof CanvasAddon : - T extends 'fit' ? typeof FitAddon : - T extends 'search' ? typeof SearchAddon : - T extends 'serialize' ? typeof SerializeAddon : - T extends 'web-links' ? typeof WebLinksAddon : - T extends 'unicode11' ? typeof Unicode11Addon : - T extends 'ligatures' ? typeof LigaturesAddon : - typeof WebglAddon + T extends 'canvas' ? typeof CanvasAddon : + T extends 'fit' ? typeof FitAddon : + T extends 'search' ? typeof SearchAddon : + T extends 'serialize' ? typeof SerializeAddon : + T extends 'web-links' ? typeof WebLinksAddon : + T extends 'unicode11' ? typeof Unicode11Addon : + T extends 'ligatures' ? typeof LigaturesAddon : + typeof WebglAddon ); instance?: ( T extends 'attach' ? AttachAddon : - T extends 'canvas' ? CanvasAddon : - T extends 'fit' ? FitAddon : - T extends 'search' ? SearchAddon : - T extends 'serialize' ? SerializeAddon : - T extends 'web-links' ? WebLinksAddon : - T extends 'webgl' ? WebglAddon : - T extends 'unicode11' ? typeof Unicode11Addon : - T extends 'ligatures' ? typeof LigaturesAddon : - never + T extends 'canvas' ? CanvasAddon : + T extends 'fit' ? FitAddon : + T extends 'search' ? SearchAddon : + T extends 'serialize' ? SerializeAddon : + T extends 'web-links' ? WebLinksAddon : + T extends 'webgl' ? WebglAddon : + T extends 'unicode11' ? typeof Unicode11Addon : + T extends 'ligatures' ? typeof LigaturesAddon : + never ); } @@ -271,18 +271,20 @@ function createTerminal(): void { socketURL = protocol + location.hostname + ((location.port) ? (':' + location.port) : '') + '/terminals/'; addons.fit.instance!.fit(); - try { // try-catch to allow the demo to load if webgl is not supported - typedTerm.loadAddon(addons.webgl.instance); - setTimeout(() => { + typedTerm.loadAddon(addons.webgl.instance); + setTimeout(() => { + if (addons.webgl.instance !== undefined) { addTextureAtlas(addons.webgl.instance.textureAtlas); addons.webgl.instance.onChangeTextureAtlas(e => addTextureAtlas(e)); - }, 0); + } + }, 0); + + try { // try-catch to allow the demo to load if webgl is not supported + term.open(terminalContainer); } catch { addons.webgl.instance = undefined; } - - term.open(terminalContainer); term.focus(); addDomListener(paddingElement, 'change', setPadding); From 1c345bef48977ce409f29313f1c442168c75f2aa Mon Sep 17 00:00:00 2001 From: Simon Lamon Date: Sun, 9 Oct 2022 15:01:15 +0000 Subject: [PATCH 3/4] Handle onWillFire if it fails, so it loads dom renderer --- addons/xterm-addon-webgl/src/WebglRenderer.ts | 3 --- src/browser/Terminal.ts | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index 8f747c03..ed99a225 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -103,9 +103,6 @@ export class WebglRenderer extends Disposable implements IRenderer { throw new Error('WebGL2 not supported ' + this._gl); } - // TODO: Remove me. - throw new Error('WebGL2 not supported ' + this._gl); - this.register(addDisposableDomListener(this._canvas, 'webglcontextlost', (e) => { console.log('webglcontextlost event received'); // Prevent the default behavior in order to enable WebGL context restoration. diff --git a/src/browser/Terminal.ts b/src/browser/Terminal.ts index e0ba8a94..9b17c55c 100644 --- a/src/browser/Terminal.ts +++ b/src/browser/Terminal.ts @@ -515,7 +515,10 @@ export class Terminal extends CoreTerminal implements ITerminal { // Performance: Add viewport and helper elements from the fragment this.element.appendChild(fragment); - this._onWillOpen.fire(this.element); + try { + this._onWillOpen.fire(this.element); + } + catch { /* fails to load addon for some reason */ } if (!this._renderService.hasRenderer()) { this._renderService.setRenderer(this._createRenderer()); } From a4c62792df5b732e34bd25257fa2cfdf05d7c0a8 Mon Sep 17 00:00:00 2001 From: Simon Lamon Date: Sun, 9 Oct 2022 15:03:54 +0000 Subject: [PATCH 4/4] revert formatting changes --- demo/client.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index 6d48b302..44a96eb3 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -61,26 +61,26 @@ interface IDemoAddon { canChange: boolean; ctor: ( T extends 'attach' ? typeof AttachAddon : - T extends 'canvas' ? typeof CanvasAddon : - T extends 'fit' ? typeof FitAddon : - T extends 'search' ? typeof SearchAddon : - T extends 'serialize' ? typeof SerializeAddon : - T extends 'web-links' ? typeof WebLinksAddon : - T extends 'unicode11' ? typeof Unicode11Addon : - T extends 'ligatures' ? typeof LigaturesAddon : - typeof WebglAddon + T extends 'canvas' ? typeof CanvasAddon : + T extends 'fit' ? typeof FitAddon : + T extends 'search' ? typeof SearchAddon : + T extends 'serialize' ? typeof SerializeAddon : + T extends 'web-links' ? typeof WebLinksAddon : + T extends 'unicode11' ? typeof Unicode11Addon : + T extends 'ligatures' ? typeof LigaturesAddon : + typeof WebglAddon ); instance?: ( T extends 'attach' ? AttachAddon : - T extends 'canvas' ? CanvasAddon : - T extends 'fit' ? FitAddon : - T extends 'search' ? SearchAddon : - T extends 'serialize' ? SerializeAddon : - T extends 'web-links' ? WebLinksAddon : - T extends 'webgl' ? WebglAddon : - T extends 'unicode11' ? typeof Unicode11Addon : - T extends 'ligatures' ? typeof LigaturesAddon : - never + T extends 'canvas' ? CanvasAddon : + T extends 'fit' ? FitAddon : + T extends 'search' ? SearchAddon : + T extends 'serialize' ? SerializeAddon : + T extends 'web-links' ? WebLinksAddon : + T extends 'webgl' ? WebglAddon : + T extends 'unicode11' ? typeof Unicode11Addon : + T extends 'ligatures' ? typeof LigaturesAddon : + never ); }