import { invoke } from '@tauri-apps/api/core';
|
|
export async function startPipeServer(pipeName: string): Promise<void> {
|
try {
|
await invoke('start_pipe_server_command', { pipeName });
|
console.log(`Pipe server started on \\\.\\pipe\\${pipeName}`);
|
} catch (err) {
|
console.error('Failed to start pipe server:', err);
|
}
|
}
|
|
export async function sendToPipe(pipeName: string, message: string): Promise<string> {
|
// 添加重试机制
|
const maxRetries = 3;
|
let retryCount = 0;
|
let lastError: any;
|
|
while (retryCount < maxRetries) {
|
try {
|
return await invoke('send_pipe_message', { pipeName, message });
|
} catch (err) {
|
lastError = err;
|
console.warn(`管道通信失败,正在重试 (${retryCount + 1}/${maxRetries}):`, err);
|
retryCount++;
|
|
// 等待一段时间再重试
|
if (retryCount < maxRetries) {
|
await new Promise(resolve => setTimeout(resolve, 500 * retryCount));
|
}
|
}
|
}
|
|
// 所有重试都失败,抛出最后一个错误
|
throw lastError;
|
}
|
|
export async function getLatestWsData(): Promise<string | null> {
|
try {
|
const result = await invoke<string | null>('get_latest_ws_data');
|
console.log("getlatestwsData", result);
|
return result;
|
} catch (err) {
|
console.error('获取 WebSocket 数据失败:', err);
|
return null;
|
}
|
}
|