|
|
@ -7,7 +7,12 @@ import { dirname } from 'path' |
|
|
import { IPC_EVENT } from '../renderer/src/common/ipcEvents.js' |
|
|
import { IPC_EVENT } from '../renderer/src/common/ipcEvents.js' |
|
|
import log from 'electron-log' |
|
|
import log from 'electron-log' |
|
|
import ReconnectManager from './reconnectManager.js' |
|
|
import ReconnectManager from './reconnectManager.js' |
|
|
import { getParametersFromDevice, setFirstParameter, disconnect } from './lib/adbClient.js' |
|
|
import { |
|
|
|
|
|
getParametersFromDevice, |
|
|
|
|
|
setFirstParameter, |
|
|
|
|
|
disconnect, |
|
|
|
|
|
syncDeviceDateTime |
|
|
|
|
|
} from './lib/adbClient.js' |
|
|
import fs from 'fs/promises' |
|
|
import fs from 'fs/promises' |
|
|
import path from 'path' |
|
|
import path from 'path' |
|
|
const TIMEOUT = 10000 // 10秒超时
|
|
|
const TIMEOUT = 10000 // 10秒超时
|
|
|
@ -55,22 +60,25 @@ const handleAttemptReconnect = (ip, callback) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
client.connect(Number(storedConnectionData.port), ip, () => { |
|
|
client.connect(Number(storedConnectionData.port), ip, () => { |
|
|
log.info(`Reconnected successfully to ${ip}:${storedConnectionData.port}`) |
|
|
(async () => { |
|
|
|
|
|
log.info(`Reconnected successfully to ${ip}:${storedConnectionData.port}`) |
|
|
|
|
|
await synchronizeDeviceTimeAfterConnect(ip) |
|
|
|
|
|
|
|
|
// 连接成功,保存连接信息
|
|
|
// 连接成功,保存连接信息
|
|
|
tcpClients.set(ip, connectionInfo) |
|
|
tcpClients.set(ip, connectionInfo) |
|
|
|
|
|
|
|
|
// 启动心跳检测
|
|
|
// 启动心跳检测
|
|
|
startHeartbeatCheck(ip) |
|
|
startHeartbeatCheck(ip) |
|
|
|
|
|
|
|
|
// 通知渲染进程重连成功
|
|
|
// 通知渲染进程重连成功
|
|
|
storedConnectionData.eventSender.send(IPC_EVENT.DEVICE_CONNECT_REPLY, { |
|
|
storedConnectionData.eventSender.send(IPC_EVENT.DEVICE_CONNECT_REPLY, { |
|
|
success: true, |
|
|
success: true, |
|
|
ip: ip, |
|
|
ip: ip, |
|
|
reconnected: true |
|
|
reconnected: true |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
callback(true) |
|
|
callback(true) |
|
|
|
|
|
})() |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// 设置数据处理
|
|
|
// 设置数据处理
|
|
|
@ -168,6 +176,15 @@ const logIPCCommand = (ip, command) => { |
|
|
log.info(`IPC Command from renderer - ${eventType} to ${ip}:`, command) |
|
|
log.info(`IPC Command from renderer - ${eventType} to ${ip}:`, command) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const synchronizeDeviceTimeAfterConnect = async (ip) => { |
|
|
|
|
|
try { |
|
|
|
|
|
await syncDeviceDateTime(ip) |
|
|
|
|
|
log.info(`Device time synchronized successfully for ${ip}`) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
log.warn(`Failed to synchronize device time for ${ip}:`, error.message) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export function registerIpRouter() { |
|
|
export function registerIpRouter() { |
|
|
ipcMain.on(IPC_EVENT.DEVICE_SEARCH, searchDevice) |
|
|
ipcMain.on(IPC_EVENT.DEVICE_SEARCH, searchDevice) |
|
|
ipcMain.on(IPC_EVENT.DEVICE_CONNECT, connectDevice) |
|
|
ipcMain.on(IPC_EVENT.DEVICE_CONNECT, connectDevice) |
|
|
@ -481,11 +498,14 @@ const connectDevice = (event, { ip, port }) => { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
client.connect(Number(port), ip, () => { |
|
|
client.connect(Number(port), ip, () => { |
|
|
event.reply(IPC_EVENT.DEVICE_CONNECT_REPLY, { success: true, ip }) |
|
|
(async () => { |
|
|
tcpClients.set(ip, connectionInfo) |
|
|
await synchronizeDeviceTimeAfterConnect(ip) |
|
|
|
|
|
event.reply(IPC_EVENT.DEVICE_CONNECT_REPLY, { success: true, ip }) |
|
|
// 启动心跳检测
|
|
|
tcpClients.set(ip, connectionInfo) |
|
|
startHeartbeatCheck(ip) |
|
|
|
|
|
|
|
|
// 启动心跳检测
|
|
|
|
|
|
startHeartbeatCheck(ip) |
|
|
|
|
|
})() |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
let buffer = '' |
|
|
let buffer = '' |
|
|
|