Sfoglia il codice sorgente

:recycle: Implement some delayed kernel events using task queues https://github.com/siyuan-note/siyuan/issues/12393

Daniel 11 mesi fa
parent
commit
50adf9751b

+ 5 - 5
app/src/sync/syncGuide.ts

@@ -246,11 +246,11 @@ const setSync = (key?: string, dialog?: Dialog) => {
     <button class="b3-button" disabled="disabled">${window.siyuan.languages.openSyncTip1}</button>
 </div>`;
         if (dialog) {
-            dialog.element.querySelector(".b3-dialog__header").innerHTML = window.siyuan.languages.cloudSyncDir;
+            dialog.element.querySelector(".b3-dialog__header").innerHTML = "🗂️ " + window.siyuan.languages.cloudSyncDir;
             dialog.element.querySelector(".b3-dialog__body").innerHTML = listHTML;
         } else {
             dialog = new Dialog({
-                title: window.siyuan.languages.cloudSyncDir,
+                title: "🗂️ " + window.siyuan.languages.cloudSyncDir,
                 content: listHTML,
                 width: isMobile() ? "92vw" : "520px",
             });
@@ -277,7 +277,7 @@ const setSync = (key?: string, dialog?: Dialog) => {
             fetchPost("/api/sync/setSyncEnable", {enabled: true}, () => {
                 window.siyuan.config.sync.enabled = true;
                 processSync();
-                confirmDialog(window.siyuan.languages.syncConfGuide4, window.siyuan.languages.syncConfGuide5, () => {
+                confirmDialog("🔄 " + window.siyuan.languages.syncConfGuide4, window.siyuan.languages.syncConfGuide5, () => {
                     syncNow();
                 });
             });
@@ -286,7 +286,7 @@ const setSync = (key?: string, dialog?: Dialog) => {
         if (dialog) {
             dialog.destroy();
         }
-        confirmDialog(window.siyuan.languages.syncConfGuide4, window.siyuan.languages.syncConfGuide5, () => {
+        confirmDialog("🔄 " + window.siyuan.languages.syncConfGuide4, window.siyuan.languages.syncConfGuide5, () => {
             syncNow();
         });
     }
@@ -294,7 +294,7 @@ const setSync = (key?: string, dialog?: Dialog) => {
 
 export const setKey = (isSync: boolean, cb?: () => void) => {
     const dialog = new Dialog({
-        title: window.siyuan.languages.syncConfGuide1,
+        title: "🔑 " + window.siyuan.languages.syncConfGuide1,
         content: `<div class="b3-dialog__content ft__center">
     <img style="width: 260px" src="/stage/images/sync-guide.svg"/>
     <div class="fn__hr--b"></div>

+ 2 - 4
kernel/model/bazzar.go

@@ -19,6 +19,7 @@ package model
 import (
 	"errors"
 	"fmt"
+	"github.com/siyuan-note/siyuan/kernel/task"
 	"path"
 	"path/filepath"
 	"strings"
@@ -104,13 +105,10 @@ func BatchUpdateBazaarPackages(frontend string) {
 	}
 
 	util.ReloadUI()
-
 	go func() {
 		util.WaitForUILoaded()
-		time.Sleep(500)
-		util.PushMsg(fmt.Sprintf(Conf.language(237), total), 5000)
+		task.AppendTaskWithDelay(task.PushMsg, 1*time.Second, util.PushMsg, fmt.Sprintf(Conf.language(237), total), 5000)
 	}()
-
 	return
 }
 

+ 3 - 3
kernel/model/conf.go

@@ -19,6 +19,7 @@ package model
 import (
 	"bytes"
 	"fmt"
+	"github.com/siyuan-note/siyuan/kernel/task"
 	"os"
 	"path/filepath"
 	"runtime"
@@ -468,11 +469,10 @@ func InitConf() {
 		// 上次未正常完成数据索引
 		go func() {
 			util.WaitForUILoaded()
-			time.Sleep(2 * time.Second)
 			if util.ContainerIOS == util.Container || util.ContainerAndroid == util.Container {
-				util.PushMsg(Conf.language(245), 15000)
+				task.AppendTaskWithDelay(task.PushMsg, 2*time.Second, util.PushMsg, Conf.language(245), 15000)
 			} else {
-				util.PushMsg(Conf.language(244), 15000)
+				task.AppendTaskWithDelay(task.PushMsg, 2*time.Second, util.PushMsg, Conf.language(244), 15000)
 			}
 		}()
 	}

+ 1 - 4
kernel/model/repository.go

@@ -477,10 +477,7 @@ func ResetRepo() (err error) {
 	Conf.Save()
 
 	util.PushUpdateMsg(msgId, Conf.Language(145), 3000)
-	go func() {
-		time.Sleep(2 * time.Second)
-		util.ReloadUI()
-	}()
+	task.AppendTaskWithDelay(task.ReloadUI, 2*time.Second, util.ReloadUI)
 	return
 }
 

+ 3 - 6
kernel/model/transaction.go

@@ -810,12 +810,9 @@ func syncDelete2AvBlock(node *ast.Node) {
 	changedAvIDs = append(changedAvIDs, avIDs...)
 	changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
 
-	go func() {
-		time.Sleep(256 * time.Millisecond)
-		for _, avID := range changedAvIDs {
-			ReloadAttrView(avID)
-		}
-	}()
+	for _, avID := range changedAvIDs {
+		ReloadAttrView(avID)
+	}
 }
 
 func syncDelete2Block(node *ast.Node) (changedAvIDs []string) {

+ 2 - 0
kernel/task/queue.go

@@ -131,6 +131,7 @@ const (
 	AssetContentDatabaseIndexCommit = "task.asset.database.index.commit"   // 资源文件数据库索引提交
 	CacheVirtualBlockRef            = "task.cache.virtualBlockRef"         // 缓存虚拟块引用
 	ReloadAttributeView             = "task.reload.attributeView"          // 重新加载属性视图
+	PushMsg                         = "task.push.msg"                      // 推送消息
 )
 
 // uniqueActions 描述了唯一的任务,即队列中只能存在一个在执行的任务。
@@ -144,6 +145,7 @@ var uniqueActions = []string{
 	HistoryDatabaseIndexCommit,
 	AssetContentDatabaseIndexFull,
 	AssetContentDatabaseIndexCommit,
+	ReloadAttributeView,
 }
 
 func ContainIndexTask() bool {