mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
Merge branch 'dev' of https://github.com/hicccc77/WeFlow into dev
This commit is contained in:
@@ -359,16 +359,15 @@ class ChatService {
|
||||
// 这种方式更高效,且不占用 JS 线程,并能直接监听 session/message 目录变更
|
||||
wcdbService.setMonitor((type, json) => {
|
||||
this.handleSessionStatsMonitorChange(type, json)
|
||||
const windows = BrowserWindow.getAllWindows()
|
||||
// 广播给所有渲染进程窗口
|
||||
BrowserWindow.getAllWindows().forEach((win) => {
|
||||
windows.forEach((win) => {
|
||||
if (!win.isDestroyed()) {
|
||||
win.webContents.send('wcdb-change', { type, json })
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 预热 media 数据库列表缓存(后台异步执行)
|
||||
|
||||
@@ -173,7 +173,6 @@ export class WcdbCore {
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
this.connectMonitorPipe(pipePath)
|
||||
return true
|
||||
} catch (e) {
|
||||
@@ -194,8 +193,14 @@ export class WcdbCore {
|
||||
|
||||
let buffer = ''
|
||||
this.monitorPipeClient.on('data', (data: Buffer) => {
|
||||
buffer += data.toString('utf8')
|
||||
const lines = buffer.split('\n')
|
||||
const rawChunk = data.toString('utf8')
|
||||
// macOS 侧可能使用 '\0' 或无换行分隔,统一归一化并兜底拆包
|
||||
const normalizedChunk = rawChunk
|
||||
.replace(/\u0000/g, '\n')
|
||||
.replace(/}\s*{/g, '}\n{')
|
||||
|
||||
buffer += normalizedChunk
|
||||
const lines = buffer.split(/\r?\n/)
|
||||
buffer = lines.pop() || ''
|
||||
for (const line of lines) {
|
||||
if (line.trim()) {
|
||||
@@ -207,9 +212,23 @@ export class WcdbCore {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 兜底:如果没有分隔符但已形成完整 JSON,则直接上报
|
||||
const tail = buffer.trim()
|
||||
if (tail.startsWith('{') && tail.endsWith('}')) {
|
||||
try {
|
||||
const parsed = JSON.parse(tail)
|
||||
this.monitorCallback?.(parsed.action || 'update', tail)
|
||||
buffer = ''
|
||||
} catch {
|
||||
// 不可解析则继续等待下一块数据
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.monitorPipeClient.on('error', () => {})
|
||||
this.monitorPipeClient.on('error', () => {
|
||||
// 保持静默,与现有错误处理策略一致
|
||||
})
|
||||
|
||||
this.monitorPipeClient.on('close', () => {
|
||||
this.monitorPipeClient = null
|
||||
|
||||
@@ -136,7 +136,7 @@ export class WcdbService {
|
||||
*/
|
||||
setMonitor(callback: (type: string, json: string) => void): void {
|
||||
this.monitorListener = callback;
|
||||
this.callWorker('setMonitor').catch(() => { });
|
||||
this.callWorker<{ success?: boolean }>('setMonitor').catch(() => { });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user