Improves terminal command execution status handling

Replaces status prop with a ref to ensure up-to-date session status
during command execution checks, preventing stale state issues.
Also updates Chinese translations for code package terminology for
consistency and clarity.
This commit is contained in:
LAPTOP-O016UC3M\Qi Chen committed 2025-12-17 20:55:50 +08:00
1 parent 3cd3cf1145
commit a7e016c394
3 files changed
+16 -13

No files matched your search

+10 -10
View File
@@ -768,20 +768,20 @@ const zhCN: Messages = {
// Snippets
'snippets.searchPlaceholder': '搜索代码片段...',
'snippets.action.newSnippet': '新建代码片段',
'snippets.action.newPackage': '新建 Package',
'snippets.action.newPackage': '新建代码包',
'snippets.panel.newTitle': '新建代码片段',
'snippets.panel.editTitle': '编辑代码片段',
'snippets.field.description': '描述',
'snippets.field.descriptionPlaceholder': '例如:check network load',
'snippets.field.package': '添加 Package',
'snippets.field.packagePlaceholder': '选择或创建 Package',
'snippets.field.createPackage': '创建 Package',
'snippets.field.package': '添加代码包',
'snippets.field.packagePlaceholder': '选择或创建代码包',
'snippets.field.createPackage': '创建代码包',
'snippets.field.scriptRequired': '脚本 *',
'snippets.targets.title': '目标主机',
'snippets.targets.add': '添加目标主机',
'snippets.history.title': 'Shell History',
'snippets.history.title': 'Shell 历史',
'snippets.history.subtitle': '{count} 条命令',
'snippets.history.emptyTitle': '暂无 Shell History',
'snippets.history.emptyTitle': '暂无 Shell 历史',
'snippets.history.emptyDesc': '你执行过的命令会显示在这里',
'snippets.history.loadMore': '加载更多',
'snippets.history.separator': '•',
@@ -791,21 +791,21 @@ const zhCN: Messages = {
'snippets.history.time.minutesAgo': '{count} 分钟前',
'snippets.history.time.hoursAgo': '{count} 小时前',
'snippets.history.time.daysAgo': '{count} 天前',
'snippets.breadcrumb.allPackages': '全部 Packages',
'snippets.breadcrumb.allPackages': '全部代码包',
'snippets.breadcrumb.separator': '›',
'snippets.empty.title': '创建代码片段',
'snippets.empty.desc': '将常用命令保存为代码片段,一键复用。',
'snippets.section.packages': 'Packages',
'snippets.section.packages': '代码包',
'snippets.section.snippets': '代码片段',
'snippets.package.count': '{count} 个代码片段',
'snippets.commandFallback': '命令',
'snippets.view.grid': '网格',
'snippets.view.list': '列表',
'snippets.packageDialog.title': '新建 Package',
'snippets.packageDialog.title': '新建代码包',
'snippets.packageDialog.parent': '父级:{parent}',
'snippets.packageDialog.root': '根目录',
'snippets.packageDialog.placeholder': '例如:ops/maintenance',
'snippets.packageDialog.hint': '使用 "/" 创建嵌套 Package。',
'snippets.packageDialog.hint': '使用 "/" 创建嵌套代码包。',
};
export default zhCN;
+4 -1
View File
@@ -165,6 +165,9 @@ const TerminalComponent: React.FC<TerminalProps> = ({
const [progressValue, setProgressValue] = useState(15);
const [hasSelection, setHasSelection] = useState(false);
const statusRef = useRef<TerminalSession["status"]>(status);
statusRef.current = status;
const [chainProgress, setChainProgress] = useState<{
currentHop: number;
totalHops: number;
@@ -315,7 +318,7 @@ const TerminalComponent: React.FC<TerminalProps> = ({
isBroadcastEnabledRef,
onBroadcastInputRef,
sessionId,
status,
statusRef,
onCommandExecuted,
commandBufferRef,
setIsSearchOpen,
@@ -61,7 +61,7 @@ export type CreateXTermRuntimeContext = {
>;
sessionId: string;
status: TerminalSession["status"];
statusRef: RefObject<TerminalSession["status"]>;
onCommandExecuted?: (
command: string,
hostId: string,
@@ -388,7 +388,7 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
ctx.onBroadcastInputRef.current(data, ctx.sessionId);
}
if (ctx.status === "connected" && ctx.onCommandExecuted) {
if (ctx.statusRef.current === "connected" && ctx.onCommandExecuted) {
if (data === "\r" || data === "\n") {
const cmd = ctx.commandBufferRef.current.trim();
if (cmd) ctx.onCommandExecuted(cmd, ctx.host.id, ctx.host.label, ctx.sessionId);