Skip to content

Commit 934a29a

Browse files
committed
fix: 多字符串窗口发送回显 (复用 parseHexString/bytesToHex + isHex 语义, 改走 Tauri emit 跨窗口事件, 主窗口 listen 接收)
1 parent 6c6398c commit 934a29a

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/js/multi.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { invoke } from '@tauri-apps/api/core';
22
import { getCurrentWindow } from '@tauri-apps/api/window';
3-
import { listen } from '@tauri-apps/api/event';
3+
import { listen, emit } from '@tauri-apps/api/event';
44
import { open, save } from '@tauri-apps/plugin-dialog';
55
import { writeTextFile, readTextFile } from '@tauri-apps/plugin-fs';
6-
import { parseHexString, getSettings } from './utils.js';
6+
import { parseHexString, bytesToHex, getSettings } from './utils.js';
77
import { initIcons, createElement, GripVertical, X } from './icons.js';
88
import { Keybindings } from './keybindings.js';
99
import { t, setLang, applyI18n, detectLang } from './i18n.js';
@@ -262,6 +262,20 @@ async function sendItem(item) {
262262
try {
263263
const s = await getSettings();
264264
const encoding = s.encoding || 'utf-8';
265+
// Echo into the MAIN window's debug view via a cross-window Tauri event
266+
// (CustomEvent cannot cross webview boundaries). Same semantics as the
267+
// send box: hex sends echo the actual bytes (no re-encoding).
268+
if (item.hex) {
269+
let echo = item.text;
270+
try {
271+
echo = bytesToHex(parseHexString(item.text));
272+
} catch (e) {
273+
/* keep raw input as echo */
274+
}
275+
emit('send-echo', { text: echo, isHex: true }).catch(() => {});
276+
} else {
277+
emit('send-echo', { text: item.text }).catch(() => {});
278+
}
265279
await invoke('send_data_raw', { data: item.text, hexMode: item.hex, encoding });
266280
} catch (e) {
267281
console.error('Multi send error:', e);

src/js/receive.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,11 @@ export async function initReceive() {
526526
appendSentText(e.detail.text, e.detail.isHex === true);
527527
});
528528

529+
// Cross-window echo from the multi-string window (Tauri event broadcast).
530+
listen('send-echo', (e) => {
531+
appendSentText(e.payload.text, e.payload.isHex === true);
532+
});
533+
529534
document.addEventListener('terminal-input-echo', (e) => {
530535
const marker = echoPrefix ? (showTimestamp ? `[T-${timestamp()}]` : '[T]') : null;
531536
appendEchoFrame(e.detail.text, marker, false);

0 commit comments

Comments
 (0)