mirror of
https://github.com/open-webui/computer.git
synced 2026-11-25 23:00:55 -05:00
refac
This commit is contained in:
1 parent
827b3918be
commit
e61eb1b737
1 file changed
+21
-21
@@ -76,6 +76,27 @@
|
||||
selectionBackground: 'rgba(0, 0, 0, 0.15)',
|
||||
};
|
||||
|
||||
// Send input to PTY via WebSocket (binary prefix protocol)
|
||||
function sendInput(data: string) {
|
||||
if (ws?.readyState === WebSocket.OPEN) {
|
||||
const encoded = textEncoder.encode(data);
|
||||
const buf = new Uint8Array(1 + encoded.length);
|
||||
buf[0] = MSG_INPUT;
|
||||
buf.set(encoded, 1);
|
||||
ws.send(buf.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
function sendResize(cols: number, rows: number) {
|
||||
if (ws?.readyState === WebSocket.OPEN) {
|
||||
const payload = textEncoder.encode(JSON.stringify({ cols, rows }));
|
||||
const buf = new Uint8Array(1 + payload.length);
|
||||
buf[0] = MSG_RESIZE;
|
||||
buf.set(payload, 1);
|
||||
ws.send(buf.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (!containerEl) return;
|
||||
|
||||
@@ -98,27 +119,6 @@
|
||||
});
|
||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
||||
|
||||
// Send input to PTY via WebSocket (binary prefix protocol)
|
||||
function sendInput(data: string) {
|
||||
if (ws?.readyState === WebSocket.OPEN) {
|
||||
const encoded = textEncoder.encode(data);
|
||||
const buf = new Uint8Array(1 + encoded.length);
|
||||
buf[0] = MSG_INPUT;
|
||||
buf.set(encoded, 1);
|
||||
ws.send(buf.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
function sendResize(cols: number, rows: number) {
|
||||
if (ws?.readyState === WebSocket.OPEN) {
|
||||
const payload = textEncoder.encode(JSON.stringify({ cols, rows }));
|
||||
const buf = new Uint8Array(1 + payload.length);
|
||||
buf[0] = MSG_RESIZE;
|
||||
buf.set(payload, 1);
|
||||
ws.send(buf.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle macOS key combos that need special escape sequences
|
||||
term.attachCustomKeyEventHandler((e: KeyboardEvent) => {
|
||||
if (e.type !== 'keydown') return true;
|
||||
|
||||
Reference in new issue
Block a user