Skip to content

Commit

Permalink
🐛 修复开始 webgl 终端显示错误.
Browse files Browse the repository at this point in the history
  • Loading branch information
lijiahangmax committed Aug 28, 2024
1 parent ee9f51c commit cd05f71
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion orion-visor-ui/src/api/exec/exec-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export interface ExecLogQueryResponse extends TableData, ExecLogQueryExtraRespon
startTime: number;
finishTime: number;
hostIdList: Array<number>;
hosts: Array<ExecHostLogQueryResponse>;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions orion-visor-ui/src/components/exec/log/panel/log-appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Terminal } from '@xterm/xterm';
import { FitAddon } from '@xterm/addon-fit';
import { SearchAddon } from '@xterm/addon-search';
import { WebLinksAddon } from '@xterm/addon-web-links';
import { WebglAddon } from '@xterm/addon-webgl';
import { CanvasAddon } from '@xterm/addon-canvas';
import { Unicode11Addon } from '@xterm/addon-unicode11';

// 执行日志 appender 实现
Expand Down Expand Up @@ -129,20 +129,20 @@ export default class LogAppender implements ILogAppender {
// 初始化插件
initAddons(terminal: Terminal): XtermAddons {
const fit = new FitAddon();
const canvas = new CanvasAddon();
const search = new SearchAddon();
const webgl = new WebglAddon();
const weblink = new WebLinksAddon();
const unicode = new Unicode11Addon();
terminal.loadAddon(fit);
terminal.loadAddon(canvas);
terminal.loadAddon(search);
terminal.loadAddon(webgl);
terminal.loadAddon(weblink);
terminal.loadAddon(unicode);
terminal.unicode.activeVersion = '11';
return {
fit,
canvas,
search,
webgl,
weblink,
unicode
} as XtermAddons;
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class LogAppender implements ILogAppender {
if (this.client?.readyState === WebSocket.OPEN) {
this.client?.send('p');
}
}, 15000);
}, 15000) as unknown as number;
}

// 设置当前元素
Expand Down
8 changes: 6 additions & 2 deletions orion-visor-ui/src/views/host/terminal/handler/ssh-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ export default class SshSession extends BaseSession implements ISshSession {

private readonly addons: XtermAddons;

private readonly canUseWebgl: boolean;

constructor(tab: TerminalPanelTabItem,
channel: ITerminalChannel) {
channel: ITerminalChannel,
canUseWebgl: boolean) {
super(PanelSessionType.SSH.type, tab);
this.channel = channel;
this.canUseWebgl = canUseWebgl;
this.status = TerminalStatus.CONNECTING;
this.inst = undefined as unknown as Terminal;
this.handler = undefined as unknown as ISshSessionHandler;
Expand Down Expand Up @@ -173,7 +177,7 @@ export default class SshSession extends BaseSession implements ISshSession {
if (preference.pluginsSetting.enableWeblinkPlugin) {
this.addons.weblink = new WebLinksAddon();
}
if (preference.pluginsSetting.enableWebglPlugin) {
if (preference.pluginsSetting.enableWebglPlugin && this.canUseWebgl) {
// WebGL 渲染插件
this.addons.webgl = new WebglAddon(true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ export default class TerminalSessionManager implements ITerminalSessionManager {
async openSsh(tab: TerminalPanelTabItem, domRef: XtermDomRef) {
// 初始化客户端
await this.initChannel();
// 获取会话数量
const sshSessionLen = Object.values(this.sessions)
.filter(s => s?.type === PanelSessionType.SSH.type)
.length;
// 检查 webgl 数量
const canUseWebgl = (sshSessionLen || 0) <= (navigator.hardwareConcurrency || 0) / 2;
// 新建会话
const session = new SshSession(tab, this.channel);
const session = new SshSession(tab, this.channel, canUseWebgl);
// 初始化
session.init(domRef);
// 等待前端渲染完成
Expand Down

0 comments on commit cd05f71

Please sign in to comment.