chore: remote forwarding integration

This commit is contained in:
2026-07-17 18:16:11 +08:00
parent d12c74649a
commit ec9f854136
14 changed files with 1660 additions and 77 deletions
+22 -3
View File
@@ -14,8 +14,11 @@ import { Discovery } from './discovery'
import { ChatServer } from './chat-server'
import { ChatClient } from './chat-client'
import { FileServer } from './file-server'
import { TerminalManager } from './remote/terminal'
import { ForwardManager } from './remote/forward'
import { UsbBridgeManager } from './remote/usb'
import { registerIpc, bindNetworkContext } from './ipc'
import { listDevices, totalUnread, getUnread } from './db'
import { listDevices, totalUnread, getUnread, pruneAudit } from './db'
import { setBadgeCount } from './notify'
import { DEFAULT_PORTS, PROTOCOL_VERSION } from './protocol'
import type { DeviceInfo } from './protocol'
@@ -58,6 +61,9 @@ async function main() {
const chatServer = new ChatServer(DEFAULT_PORTS.chat)
const chatClient = new ChatClient(self)
const fileServer = new FileServer(DEFAULT_PORTS.file, ensureDownloadDir())
const terminal = new TerminalManager(chatClient, self.deviceId)
const forward = new ForwardManager(chatClient)
const usb = new UsbBridgeManager(chatClient)
const chatPort = await chatServer.start()
const filePort = await fileServer.start()
@@ -65,10 +71,18 @@ async function main() {
self.filePort = filePort
// 后台清理 24h+ 残留 .tmp (不阻塞启动)
fileServer.cleanupStaleTmp().catch(() => {})
stopFns.push(() => chatServer.stop(), () => chatClient.stop(), () => discovery.stop(), () => fileServer.stop())
stopFns.push(
() => chatServer.stop(),
() => chatClient.stop(),
() => discovery.stop(),
() => fileServer.stop(),
() => terminal.stop(),
() => forward.stop(),
() => usb.stop(),
)
await discovery.start()
bindNetworkContext({ self, discovery, chatServer, chatClient, fileServer })
bindNetworkContext({ self, discovery, chatServer, chatClient, fileServer, terminal, forward, usb })
// 已入库的设备: 启动后主动尝试连接
for (const d of listDevices()) {
@@ -91,6 +105,11 @@ async function main() {
createTray()
registerIpc()
// 启动时按 auditRetentionDays 清理一次旧审计
const s = getSettings()
const retentionMs = Math.max(1, s.auditRetentionDays) * 24 * 3600 * 1000
pruneAudit(retentionMs)
setTimeout(pushInitialState, 400)
}