From d95c6bd467aa75c53c2e1b9b5cd3b36f5dc18966 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 24 Jan 2023 17:40:26 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E5=89=8D=E7=AB=AF=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=BC=95=E5=85=A5=E5=90=8E=E5=8F=B0=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=88=97=E8=A1=A8=20https://github.com/siyuan-note/si?= =?UTF-8?q?yuan/issues/7117?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/main.go | 1 + kernel/mobile/kernel.go | 1 + kernel/task/queue.go | 23 +++++++++++++++++++++++ kernel/util/websocket.go | 4 ++++ 4 files changed, 29 insertions(+) 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"`