1.45
This commit is contained in:
parent
3d6ca74fed
commit
70e6e0cac6
@ -24,7 +24,7 @@ export const LogStreamViewer: React.FC<LogStreamViewerProps> = ({
|
|||||||
|
|
||||||
// 注册日志接收回调
|
// 注册日志接收回调
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('[LogStreamViewer] useEffect triggered, connecting...');
|
if (import.meta.env.DEV) console.log('[LogStreamViewer] useEffect triggered, connecting...');
|
||||||
|
|
||||||
dataSource.onLog((logText) => {
|
dataSource.onLog((logText) => {
|
||||||
if (logViewerApiRef.current) {
|
if (logViewerApiRef.current) {
|
||||||
@ -41,7 +41,7 @@ export const LogStreamViewer: React.FC<LogStreamViewerProps> = ({
|
|||||||
dataSource.connect();
|
dataSource.connect();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log('[LogStreamViewer] useEffect cleanup, disconnecting...');
|
if (import.meta.env.DEV) console.log('[LogStreamViewer] useEffect cleanup, disconnecting...');
|
||||||
dataSource.cleanup();
|
dataSource.cleanup();
|
||||||
};
|
};
|
||||||
}, [dataSource]);
|
}, [dataSource]);
|
||||||
@ -70,7 +70,7 @@ export const LogStreamViewer: React.FC<LogStreamViewerProps> = ({
|
|||||||
// CONNECTING状态下不显示错误(可能是临时的连接问题)
|
// CONNECTING状态下不显示错误(可能是临时的连接问题)
|
||||||
const shouldShowError = error && !isConnecting;
|
const shouldShowError = error && !isConnecting;
|
||||||
|
|
||||||
console.log('[LogStreamViewer] Render - status:', currentStatus, 'error:', error, 'shouldShowError:', shouldShowError, 'isConnecting:', isConnecting);
|
if (import.meta.env.DEV) console.log('[LogStreamViewer] Render - status:', currentStatus, 'error:', error, 'shouldShowError:', shouldShowError, 'isConnecting:', isConnecting);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`flex flex-col h-full relative ${className}`}>
|
<div className={`flex flex-col h-full relative ${className}`}>
|
||||||
|
|||||||
@ -22,10 +22,10 @@ export class WebSocketLogSource implements LogDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
connect(): void {
|
connect(): void {
|
||||||
console.log('[WebSocketLogSource] connect() called, current readyState:', this.ws?.readyState);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] connect() called, current readyState:', this.ws?.readyState);
|
||||||
|
|
||||||
if (this.ws?.readyState === WebSocket.OPEN) {
|
if (this.ws?.readyState === WebSocket.OPEN) {
|
||||||
console.log('[WebSocketLogSource] Already connected, skipping');
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] Already connected, skipping');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,12 +37,12 @@ export class WebSocketLogSource implements LogDataSource {
|
|||||||
this.isManualDisconnect = false;
|
this.isManualDisconnect = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('[WebSocketLogSource] Creating new WebSocket:', this.config.url);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] Creating new WebSocket:', this.config.url);
|
||||||
this.ws = new WebSocket(this.config.url);
|
this.ws = new WebSocket(this.config.url);
|
||||||
console.log('[WebSocketLogSource] WebSocket created, readyState:', this.ws.readyState);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] WebSocket created, readyState:', this.ws.readyState);
|
||||||
|
|
||||||
this.ws.onopen = () => {
|
this.ws.onopen = () => {
|
||||||
console.log('[WebSocketLogSource] onopen triggered! readyState:', this.ws?.readyState);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] onopen triggered! readyState:', this.ws?.readyState);
|
||||||
this.reconnectAttempts = 0;
|
this.reconnectAttempts = 0;
|
||||||
this.hasConnected = true;
|
this.hasConnected = true;
|
||||||
this.updateStatus(LogStreamStatus.CONNECTED);
|
this.updateStatus(LogStreamStatus.CONNECTED);
|
||||||
@ -55,7 +55,7 @@ export class WebSocketLogSource implements LogDataSource {
|
|||||||
// 处理 STATUS 消息
|
// 处理 STATUS 消息
|
||||||
if (message.type === 'STATUS' && message.data?.response?.status) {
|
if (message.type === 'STATUS' && message.data?.response?.status) {
|
||||||
const newStatus = message.data.response.status as LogStreamStatus;
|
const newStatus = message.data.response.status as LogStreamStatus;
|
||||||
console.log('[WebSocketLogSource] Received STATUS:', newStatus);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] Received STATUS:', newStatus);
|
||||||
this.updateStatus(newStatus);
|
this.updateStatus(newStatus);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ export class WebSocketLogSource implements LogDataSource {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.ws.onclose = (event) => {
|
this.ws.onclose = (event) => {
|
||||||
console.log('[WebSocketLogSource] onclose triggered, code:', event.code, 'reason:', event.reason);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] onclose triggered, code:', event.code, 'reason:', event.reason);
|
||||||
|
|
||||||
if (event.code === 1006) {
|
if (event.code === 1006) {
|
||||||
this.updateError('无法连接到服务器,请检查网络连接');
|
this.updateError('无法连接到服务器,请检查网络连接');
|
||||||
@ -110,12 +110,12 @@ export class WebSocketLogSource implements LogDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disconnect(): void {
|
disconnect(): void {
|
||||||
console.log('[WebSocketLogSource] disconnect() called');
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] disconnect() called');
|
||||||
this.isManualDisconnect = true;
|
this.isManualDisconnect = true;
|
||||||
this.clearReconnectTimer();
|
this.clearReconnectTimer();
|
||||||
|
|
||||||
if (this.ws) {
|
if (this.ws) {
|
||||||
console.log('[WebSocketLogSource] Closing WebSocket, readyState:', this.ws.readyState);
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] Closing WebSocket, readyState:', this.ws.readyState);
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
this.ws = null;
|
this.ws = null;
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ export class WebSocketLogSource implements LogDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup(): void {
|
cleanup(): void {
|
||||||
console.log('[WebSocketLogSource] cleanup() called');
|
if (import.meta.env.DEV) console.log('[WebSocketLogSource] cleanup() called');
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
this.logCallback = null;
|
this.logCallback = null;
|
||||||
this.statusCallback = null;
|
this.statusCallback = null;
|
||||||
|
|||||||
@ -79,12 +79,12 @@ export function TerminalWindowManager<TResource = any>({
|
|||||||
setActiveWindowId(windowId);
|
setActiveWindowId(windowId);
|
||||||
onOpenWindow?.(windowId);
|
onOpenWindow?.(windowId);
|
||||||
|
|
||||||
console.log(`✅ 打开${type.toUpperCase()}窗口: ${getWindowTitle(resource)} (${windowId})`);
|
if (import.meta.env.DEV) console.log(`✅ 打开${type.toUpperCase()}窗口: ${getWindowTitle(resource)} (${windowId})`);
|
||||||
}, [windows.length, type, getWindowTitle, getResourceId, onOpenWindow]);
|
}, [windows.length, type, getWindowTitle, getResourceId, onOpenWindow]);
|
||||||
|
|
||||||
// 真正关闭窗口
|
// 真正关闭窗口
|
||||||
const actuallyCloseWindow = useCallback((windowId: string) => {
|
const actuallyCloseWindow = useCallback((windowId: string) => {
|
||||||
console.log(`❌ 真正关闭窗口: ${windowId}`);
|
if (import.meta.env.DEV) console.log(`❌ 真正关闭窗口: ${windowId}`);
|
||||||
setWindows(prev => prev.filter(w => w.id !== windowId));
|
setWindows(prev => prev.filter(w => w.id !== windowId));
|
||||||
if (activeWindowId === windowId) {
|
if (activeWindowId === windowId) {
|
||||||
setActiveWindowId(null);
|
setActiveWindowId(null);
|
||||||
@ -93,15 +93,15 @@ export function TerminalWindowManager<TResource = any>({
|
|||||||
|
|
||||||
// 关闭窗口(优雅关闭)
|
// 关闭窗口(优雅关闭)
|
||||||
const closeWindow = useCallback((windowId: string) => {
|
const closeWindow = useCallback((windowId: string) => {
|
||||||
console.log(`🚪 准备关闭窗口: ${windowId}`);
|
if (import.meta.env.DEV) console.log(`🚪 准备关闭窗口: ${windowId}`);
|
||||||
|
|
||||||
// 调用优雅关闭方法
|
// 调用优雅关闭方法
|
||||||
const closeMethod = (window as any)[`__closeSSH_${windowId}`];
|
const closeMethod = (window as any)[`__closeSSH_${windowId}`];
|
||||||
if (closeMethod && typeof closeMethod === 'function') {
|
if (closeMethod && typeof closeMethod === 'function') {
|
||||||
console.log('✅ 调用优雅关闭方法');
|
if (import.meta.env.DEV) console.log('✅ 调用优雅关闭方法');
|
||||||
closeMethod();
|
closeMethod();
|
||||||
} else {
|
} else {
|
||||||
console.warn('⚠️ 未找到优雅关闭方法,直接关闭窗口');
|
if (import.meta.env.DEV) console.warn('⚠️ 未找到优雅关闭方法,直接关闭窗口');
|
||||||
actuallyCloseWindow(windowId);
|
actuallyCloseWindow(windowId);
|
||||||
}
|
}
|
||||||
}, [actuallyCloseWindow]);
|
}, [actuallyCloseWindow]);
|
||||||
@ -113,7 +113,7 @@ export function TerminalWindowManager<TResource = any>({
|
|||||||
w.id === windowId ? { ...w, isMinimized: true } : w
|
w.id === windowId ? { ...w, isMinimized: true } : w
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
console.log(`➖ 最小化窗口: ${windowId}`);
|
if (import.meta.env.DEV) console.log(`➖ 最小化窗口: ${windowId}`);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// 恢复窗口
|
// 恢复窗口
|
||||||
@ -124,7 +124,7 @@ export function TerminalWindowManager<TResource = any>({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
setActiveWindowId(windowId);
|
setActiveWindowId(windowId);
|
||||||
console.log(`⬆️ 恢复窗口: ${windowId}`);
|
if (import.meta.env.DEV) console.log(`⬆️ 恢复窗口: ${windowId}`);
|
||||||
|
|
||||||
// 触发resize事件,确保终端正确调整尺寸
|
// 触发resize事件,确保终端正确调整尺寸
|
||||||
// 延迟100ms等待DOM更新完成
|
// 延迟100ms等待DOM更新完成
|
||||||
@ -186,7 +186,7 @@ export function TerminalWindowManager<TResource = any>({
|
|||||||
const globalKey = `__open${typeName}Window`;
|
const globalKey = `__open${typeName}Window`;
|
||||||
(window as any)[globalKey] = openWindow;
|
(window as any)[globalKey] = openWindow;
|
||||||
|
|
||||||
console.log(`✅ 注册全局方法: ${globalKey}`);
|
if (import.meta.env.DEV) console.log(`✅ 注册全局方法: ${globalKey}`);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
delete (window as any)[globalKey];
|
delete (window as any)[globalKey];
|
||||||
|
|||||||
@ -165,9 +165,9 @@ const LogViewerContent: React.FC<{
|
|||||||
|
|
||||||
// 控制按钮处理函数
|
// 控制按钮处理函数
|
||||||
const handleStart = useCallback(() => {
|
const handleStart = useCallback(() => {
|
||||||
console.log('[LogWindowManager] handleStart called, controlApiRef:', !!controlApiRef.current);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] handleStart called, controlApiRef:', !!controlApiRef.current);
|
||||||
if (!controlApiRef.current) {
|
if (!controlApiRef.current) {
|
||||||
console.log('[LogWindowManager] controlApiRef is null, cannot send START');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] controlApiRef is null, cannot send START');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ const LogViewerContent: React.FC<{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[LogWindowManager] Sending START message:', startMessage);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Sending START message:', startMessage);
|
||||||
controlApiRef.current.send(JSON.stringify(startMessage));
|
controlApiRef.current.send(JSON.stringify(startMessage));
|
||||||
setStatus(LogStreamStatus.STREAMING);
|
setStatus(LogStreamStatus.STREAMING);
|
||||||
}, [lines, app.runtimeType, podName]);
|
}, [lines, app.runtimeType, podName]);
|
||||||
@ -212,7 +212,7 @@ const LogViewerContent: React.FC<{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[LogWindowManager] Pod changed from', prevPodNameRef.current, 'to', podName, '- restarting stream');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Pod changed from', prevPodNameRef.current, 'to', podName, '- restarting stream');
|
||||||
|
|
||||||
// 更新引用
|
// 更新引用
|
||||||
prevPodNameRef.current = podName;
|
prevPodNameRef.current = podName;
|
||||||
@ -241,7 +241,7 @@ const LogViewerContent: React.FC<{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
console.log('[LogWindowManager] Sending START with new pod:', startMessage);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Sending START with new pod:', startMessage);
|
||||||
controlApiRef.current.send(JSON.stringify(startMessage));
|
controlApiRef.current.send(JSON.stringify(startMessage));
|
||||||
setStatus(LogStreamStatus.STREAMING);
|
setStatus(LogStreamStatus.STREAMING);
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ const LogViewerContent: React.FC<{
|
|||||||
|
|
||||||
// 创建WebSocket数据源
|
// 创建WebSocket数据源
|
||||||
const dataSource = useMemo(() => {
|
const dataSource = useMemo(() => {
|
||||||
console.log('[LogWindowManager] Creating new dataSource for app:', app.teamApplicationId, app.runtimeType);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Creating new dataSource for app:', app.teamApplicationId, app.runtimeType);
|
||||||
|
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const host = window.location.host;
|
const host = window.location.host;
|
||||||
@ -283,19 +283,19 @@ const LogViewerContent: React.FC<{
|
|||||||
|
|
||||||
// 注册状态变化回调
|
// 注册状态变化回调
|
||||||
source.onStatusChange((newStatus) => {
|
source.onStatusChange((newStatus) => {
|
||||||
console.log('[LogWindowManager] Status changed to:', newStatus);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Status changed to:', newStatus);
|
||||||
setStatus(newStatus);
|
setStatus(newStatus);
|
||||||
|
|
||||||
// 收到CONNECTED状态后自动发送START消息
|
// 收到CONNECTED状态后自动发送START消息
|
||||||
if (newStatus === LogStreamStatus.CONNECTED) {
|
if (newStatus === LogStreamStatus.CONNECTED) {
|
||||||
// K8S应用需要等待Pod列表加载完成
|
// K8S应用需要等待Pod列表加载完成
|
||||||
if (app.runtimeType === 'K8S' && loadingPodsRef.current) {
|
if (app.runtimeType === 'K8S' && loadingPodsRef.current) {
|
||||||
console.log('[LogWindowManager] K8S waiting for pods, skip START');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] K8S waiting for pods, skip START');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 延迟发送START消息,确保controlApiRef已设置
|
// 延迟发送START消息,确保controlApiRef已设置
|
||||||
console.log('[LogWindowManager] CONNECTED received, sending START in 100ms...');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] CONNECTED received, sending START in 100ms...');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
handleStartRef.current?.();
|
handleStartRef.current?.();
|
||||||
}, 100);
|
}, 100);
|
||||||
@ -614,22 +614,22 @@ const LogViewerContent: React.FC<{
|
|||||||
|
|
||||||
// API就绪后,检查连接状态并自动启动
|
// API就绪后,检查连接状态并自动启动
|
||||||
const currentStatus = controlApi.getStatus();
|
const currentStatus = controlApi.getStatus();
|
||||||
console.log('[LogWindowManager] onReady triggered, status:', currentStatus, 'runtimeType:', app.runtimeType);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] onReady triggered, status:', currentStatus, 'runtimeType:', app.runtimeType);
|
||||||
|
|
||||||
if (currentStatus === LogStreamStatus.CONNECTED) {
|
if (currentStatus === LogStreamStatus.CONNECTED) {
|
||||||
// K8S应用需要等待Pod列表加载完成
|
// K8S应用需要等待Pod列表加载完成
|
||||||
if (app.runtimeType === 'K8S' && loadingPodsRef.current) {
|
if (app.runtimeType === 'K8S' && loadingPodsRef.current) {
|
||||||
console.log('[LogWindowManager] K8S waiting for pods, skip START');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] K8S waiting for pods, skip START');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 自动发送START消息
|
// 自动发送START消息
|
||||||
console.log('[LogWindowManager] Sending START message in 100ms...');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Sending START message in 100ms...');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log('[LogWindowManager] Calling handleStart');
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Calling handleStart');
|
||||||
handleStartRef.current?.();
|
handleStartRef.current?.();
|
||||||
}, 100);
|
}, 100);
|
||||||
} else {
|
} else {
|
||||||
console.log('[LogWindowManager] Status is not CONNECTED, current:', currentStatus);
|
if (import.meta.env.DEV) console.log('[LogWindowManager] Status is not CONNECTED, current:', currentStatus);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className="flex-1"
|
className="flex-1"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user