diff --git a/kernel/main.go b/kernel/main.go index d0f6dcc12..07b943a2f 100644 --- a/kernel/main.go +++ b/kernel/main.go @@ -44,6 +44,7 @@ func main() { model.LoadAssetsTexts() go task.Loop() + go task.StatusLoop() go model.AutoGenerateDocHistory() go model.AutoSync() diff --git a/kernel/mobile/kernel.go b/kernel/mobile/kernel.go index 58c3d9019..5a5fa4f83 100644 --- a/kernel/mobile/kernel.go +++ b/kernel/mobile/kernel.go @@ -58,6 +58,7 @@ func StartKernel(container, appDir, workspaceBaseDir, timezoneID, localIPs, lang model.LoadAssetsTexts() go task.Loop() + go task.StatusLoop() go model.AutoGenerateDocHistory() go model.AutoSync() diff --git a/kernel/task/queue.go b/kernel/task/queue.go index cab4f41db..2426fd89e 100644 --- a/kernel/task/queue.go +++ b/kernel/task/queue.go @@ -110,6 +110,29 @@ const ( DatabaseIndexEmbedBlock = "task.database.index.embedBlock" // 数据库索引嵌入块 ) +func StatusLoop() { + for { + time.Sleep(1000 * time.Millisecond) + tasks := taskQueue + data := map[string]interface{}{} + var items []map[string]interface{} + for _, task := range tasks { + if OCRImage == task.Action || DatabaseIndexEmbedBlock == task.Action { + continue + } + + item := map[string]interface{}{ + "action": task.Action, + } + items = append(items, item) + } + util.PushBackgroundTask(data) + if 0 < len(tasks) { + time.Sleep(1000 * time.Millisecond) + } + } +} + func Loop() { for { time.Sleep(10 * time.Millisecond) diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index ef1f05691..8892f2bb7 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -151,6 +151,10 @@ func PushStatusBar(msg string) { BroadcastByType("main", "statusbar", 0, msg, nil) } +func PushBackgroundTask(data map[string]interface{}) { + BroadcastByType("main", "backgroundtask", 0, "", data) +} + type BlockStatResult struct { RuneCount int `json:"runeCount"` WordCount int `json:"wordCount"`