mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 The User Guide is no longer opened repeatedly when multiple windows exist https://github.com/siyuan-note/siyuan/issues/11588
This commit is contained in:
parent
564c578369
commit
7b4d297ade
3 changed files with 51 additions and 23 deletions
|
|
@ -19,10 +19,12 @@ package api
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/siyuan-note/siyuan/kernel/model"
|
"github.com/siyuan-note/siyuan/kernel/model"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -222,6 +224,35 @@ func openNotebook(c *gin.Context) {
|
||||||
}
|
}
|
||||||
evt.Callback = arg["callback"]
|
evt.Callback = arg["callback"]
|
||||||
util.PushEvent(evt)
|
util.PushEvent(evt)
|
||||||
|
|
||||||
|
if isUserGuide {
|
||||||
|
appArg := arg["app"]
|
||||||
|
app := ""
|
||||||
|
if nil != appArg {
|
||||||
|
app = appArg.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
var startID string
|
||||||
|
i := 0
|
||||||
|
for ; i < 70; i++ {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
guideStartID := map[string]string{
|
||||||
|
"20210808180117-czj9bvb": "20200812220555-lj3enxa",
|
||||||
|
"20211226090932-5lcq56f": "20211226115423-d5z1joq",
|
||||||
|
"20210808180117-6v0mkxr": "20200923234011-ieuun1p",
|
||||||
|
"20240530133126-axarxgx": "20240530101000-4qitucx",
|
||||||
|
}
|
||||||
|
startID = guideStartID[notebook]
|
||||||
|
if nil != treenode.GetBlockTree(startID) {
|
||||||
|
util.BroadcastByTypeAndApp("main", app, "openFileById", 0, "", map[string]interface{}{
|
||||||
|
"id": startID,
|
||||||
|
})
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func closeNotebook(c *gin.Context) {
|
func closeNotebook(c *gin.Context) {
|
||||||
|
|
|
||||||
|
|
@ -250,29 +250,6 @@ func Mount(boxID string) (alreadyMount bool, err error) {
|
||||||
treenode.SaveBlockTree(false)
|
treenode.SaveBlockTree(false)
|
||||||
util.ClearPushProgress(100)
|
util.ClearPushProgress(100)
|
||||||
|
|
||||||
if isUserGuide {
|
|
||||||
go func() {
|
|
||||||
var startID string
|
|
||||||
i := 0
|
|
||||||
for ; i < 70; i++ {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
guideStartID := map[string]string{
|
|
||||||
"20210808180117-czj9bvb": "20200812220555-lj3enxa",
|
|
||||||
"20211226090932-5lcq56f": "20211226115423-d5z1joq",
|
|
||||||
"20210808180117-6v0mkxr": "20200923234011-ieuun1p",
|
|
||||||
"20240530133126-axarxgx": "20240530101000-4qitucx",
|
|
||||||
}
|
|
||||||
startID = guideStartID[boxID]
|
|
||||||
if nil != treenode.GetBlockTree(startID) {
|
|
||||||
util.BroadcastByType("main", "openFileById", 0, "", map[string]interface{}{
|
|
||||||
"id": startID,
|
|
||||||
})
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
if reMountGuide {
|
if reMountGuide {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,26 @@ var (
|
||||||
sessions = sync.Map{} // {appId, {sessionId, session}}
|
sessions = sync.Map{} // {appId, {sessionId, session}}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func BroadcastByTypeAndApp(typ, app, cmd string, code int, msg string, data interface{}) {
|
||||||
|
appSessions, ok := sessions.Load(app)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
appSessions.(*sync.Map).Range(func(key, value interface{}) bool {
|
||||||
|
session := value.(*melody.Session)
|
||||||
|
if t, ok := session.Get("type"); ok && typ == t {
|
||||||
|
event := NewResult()
|
||||||
|
event.Cmd = cmd
|
||||||
|
event.Code = code
|
||||||
|
event.Msg = msg
|
||||||
|
event.Data = data
|
||||||
|
session.Write(event.Bytes())
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// BroadcastByType 广播所有实例上 typ 类型的会话。
|
// BroadcastByType 广播所有实例上 typ 类型的会话。
|
||||||
func BroadcastByType(typ, cmd string, code int, msg string, data interface{}) {
|
func BroadcastByType(typ, cmd string, code int, msg string, data interface{}) {
|
||||||
typeSessions := SessionsByType(typ)
|
typeSessions := SessionsByType(typ)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue