add addons-webgl, protected with clientsettings flag (#532)

This commit is contained in:
Mike Sawka 2024-03-28 23:19:39 -07:00 committed by GitHub
parent 7c2265f3e3
commit 8a3d9628ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 1 deletions

View File

@ -23,6 +23,7 @@
"@table-nav/react": "^0.0.7", "@table-nav/react": "^0.0.7",
"@tanstack/match-sorter-utils": "^8.8.4", "@tanstack/match-sorter-utils": "^8.8.4",
"@tanstack/react-table": "^8.10.3", "@tanstack/react-table": "^8.10.3",
"@xterm/addon-webgl": "^0.17.0",
"autobind-decorator": "^2.4.0", "autobind-decorator": "^2.4.0",
"base64-js": "^1.5.1", "base64-js": "^1.5.1",
"classnames": "^2.3.1", "classnames": "^2.3.1",

View File

@ -11,6 +11,7 @@ import { boundMethod } from "autobind-decorator";
import { windowWidthToCols, windowHeightToRows } from "@/util/textmeasure"; import { windowWidthToCols, windowHeightToRows } from "@/util/textmeasure";
import { boundInt } from "@/util/util"; import { boundInt } from "@/util/util";
import { GlobalModel } from "@/models"; import { GlobalModel } from "@/models";
import { WebglAddon } from "@xterm/addon-webgl";
type DataUpdate = { type DataUpdate = {
data: Uint8Array; data: Uint8Array;
@ -20,6 +21,20 @@ type DataUpdate = {
const MinTermCols = 10; const MinTermCols = 10;
const MaxTermCols = 1024; const MaxTermCols = 1024;
// detect webgl support
function detectWebGLSupport(): boolean {
try {
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("webgl");
return !!ctx;
} catch (e) {
return false;
}
}
const WebGLSupported = detectWebGLSupport();
let loggedWebGL = false;
type TermWrapOpts = { type TermWrapOpts = {
termContext: TermContextUnion; termContext: TermContextUnion;
usedRows?: number; usedRows?: number;
@ -142,6 +157,17 @@ class TermWrap {
} }
}) })
); );
if (WebGLSupported && GlobalModel.clientData.get().clientopts?.webgl) {
const webglAddon = new WebglAddon();
webglAddon.onContextLoss(() => {
webglAddon.dispose();
});
this.terminal.loadAddon(webglAddon);
if (!loggedWebGL) {
console.log("loaded webgl!");
loggedWebGL = true;
}
}
this.terminal._core._inputHandler._parser.setErrorHandler((state) => { this.terminal._core._inputHandler._parser.setErrorHandler((state) => {
this.numParseErrors++; this.numParseErrors++;
return state; return state;

View File

@ -588,6 +588,7 @@ declare global {
}; };
globalshortcut: string; globalshortcut: string;
globalshortcutenabled: boolean; globalshortcutenabled: boolean;
webgl: boolean;
}; };
type ReleaseInfoType = { type ReleaseInfoType = {

View File

@ -5849,8 +5849,20 @@ func ClientSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (sc
return nil, fmt.Errorf("error updating client openai base url: %v", err) return nil, fmt.Errorf("error updating client openai base url: %v", err)
} }
} }
if webglStr, found := pk.Kwargs["webgl"]; found {
webglVal := resolveBool(webglStr, false)
if webglVal {
varsUpdated = append(varsUpdated, "webgl")
}
clientOpts := clientData.ClientOpts
clientOpts.WebGL = webglVal
err = sstore.SetClientOpts(ctx, clientOpts)
if err != nil {
return nil, fmt.Errorf("error updating client webgl: %v", err)
}
}
if len(varsUpdated) == 0 { if len(varsUpdated) == 0 {
return nil, fmt.Errorf("/client:set requires a value to set: %s", formatStrs([]string{"termfontsize", "termfontfamily", "openaiapitoken", "openaimodel", "openaibaseurl", "openaimaxtokens", "openaimaxchoices"}, "or", false)) return nil, fmt.Errorf("/client:set requires a value to set: %s", formatStrs([]string{"termfontsize", "termfontfamily", "openaiapitoken", "openaimodel", "openaibaseurl", "openaimaxtokens", "openaimaxchoices", "webgl"}, "or", false))
} }
clientData, err = sstore.EnsureClientData(ctx) clientData, err = sstore.EnsureClientData(ctx)
if err != nil { if err != nil {

View File

@ -246,6 +246,7 @@ type ClientOptsType struct {
RightSidebar *SidebarValueType `json:"rightsidebar,omitempty"` RightSidebar *SidebarValueType `json:"rightsidebar,omitempty"`
GlobalShortcut string `json:"globalshortcut,omitempty"` GlobalShortcut string `json:"globalshortcut,omitempty"`
GlobalShortcutEnabled bool `json:"globalshortcutenabled,omitempty"` GlobalShortcutEnabled bool `json:"globalshortcutenabled,omitempty"`
WebGL bool `json:"webgl,omitempty"`
} }
type FeOptsType struct { type FeOptsType struct {

View File

@ -2707,6 +2707,11 @@
resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.10.tgz#a1337ca426aa61cef9fe15b5b28e340a72f6fa99" resolved "https://registry.yarnpkg.com/@xmldom/xmldom/-/xmldom-0.8.10.tgz#a1337ca426aa61cef9fe15b5b28e340a72f6fa99"
integrity sha512-2WALfTl4xo2SkGCYRt6rDTFfk9R1czmBvUQy12gK2KuRKIpWEhcbbzy8EZXtz/jkRqHX8bFEc6FC1HjX4TUWYw== integrity sha512-2WALfTl4xo2SkGCYRt6rDTFfk9R1czmBvUQy12gK2KuRKIpWEhcbbzy8EZXtz/jkRqHX8bFEc6FC1HjX4TUWYw==
"@xterm/addon-webgl@^0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@xterm/addon-webgl/-/addon-webgl-0.17.0.tgz#1da534456b7971ebb2f08c381d4732d1f104d7d8"
integrity sha512-KUH//EZCz7j1+IekW8sZzmcj/y9gOLf/HMcsWXjg0Xr5cT1lIBIIbbBlbf5kZ+XnA/8c1IuBm1vx+blzlfPk0g==
"@xtuc/ieee754@^1.2.0": "@xtuc/ieee754@^1.2.0":
version "1.2.0" version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790" resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"