ソースを参照

:art: 前端用户界面引入后台任务列表 https://github.com/siyuan-note/siyuan/issues/7117

Liang Ding 2 年 前
コミット
d95c6bd467
4 ファイル変更29 行追加0 行削除
  1. 1 0
      kernel/main.go
  2. 1 0
      kernel/mobile/kernel.go
  3. 23 0
      kernel/task/queue.go
  4. 4 0
      kernel/util/websocket.go

+ 1 - 0
kernel/main.go

@@ -44,6 +44,7 @@ func main() {
 	model.LoadAssetsTexts()
 
 	go task.Loop()
+	go task.StatusLoop()
 
 	go model.AutoGenerateDocHistory()
 	go model.AutoSync()

+ 1 - 0
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()

+ 23 - 0
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)

+ 4 - 0
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"`