mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
feat: 一些非常帅气的优化
This commit is contained in:
@@ -23,6 +23,7 @@ export class WcdbService {
|
||||
private resourcesPath: string | null = null
|
||||
private userDataPath: string | null = null
|
||||
private logEnabled = false
|
||||
private monitorListener: ((type: string, json: string) => void) | null = null
|
||||
|
||||
constructor() {
|
||||
this.initWorker()
|
||||
@@ -47,8 +48,16 @@ export class WcdbService {
|
||||
try {
|
||||
this.worker = new Worker(finalPath)
|
||||
|
||||
this.worker.on('message', (msg: WorkerMessage) => {
|
||||
const { id, result, error } = msg
|
||||
this.worker.on('message', (msg: any) => {
|
||||
const { id, result, error, type, payload } = msg
|
||||
|
||||
if (type === 'monitor') {
|
||||
if (this.monitorListener) {
|
||||
this.monitorListener(payload.type, payload.json)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const p = this.pending.get(id)
|
||||
if (p) {
|
||||
this.pending.delete(id)
|
||||
@@ -122,6 +131,15 @@ export class WcdbService {
|
||||
this.callWorker('setLogEnabled', { enabled }).catch(() => { })
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置数据库监控回调
|
||||
*/
|
||||
setMonitor(callback: (type: string, json: string) => void): void {
|
||||
this.monitorListener = callback;
|
||||
// Notify worker to enable monitor
|
||||
this.callWorker('setMonitor').catch(() => { });
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查服务是否就绪
|
||||
*/
|
||||
@@ -187,6 +205,13 @@ export class WcdbService {
|
||||
return this.callWorker('getMessages', { sessionId, limit, offset })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取新消息(增量刷新)
|
||||
*/
|
||||
async getNewMessages(sessionId: string, minTime: number, limit: number = 1000): Promise<{ success: boolean; messages?: any[]; error?: string }> {
|
||||
return this.callWorker('getNewMessages', { sessionId, minTime, limit })
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息总数
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user