🎨 Data synchronization supports the multi-kernel online perception https://github.com/siyuan-note/siyuan/issues/8518

This commit is contained in:
Daniel 2023-06-11 23:29:09 +08:00
parent 3579a45831
commit 49499e13b6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 17 additions and 1 deletions

View file

@ -509,7 +509,7 @@ func Close(force bool, execInstallPkg int) (exitCode int) {
time.Sleep(4 * time.Second)
}
logging.LogInfof("exited kernel")
webSocketConn.Close()
closeSyncWebSocket()
util.WebSocketServer.Close()
go func() {
time.Sleep(500 * time.Millisecond)

View file

@ -372,6 +372,12 @@ func SetSyncEnable(b bool) {
func SetSyncPerception(b bool) {
Conf.Sync.Perception = b
Conf.Save()
if b {
connectSyncWebSocket()
} else {
closeSyncWebSocket()
}
return
}
@ -641,6 +647,16 @@ var (
onlineKernelsLock = sync.Mutex{}
)
func closeSyncWebSocket() {
webSocketConnLock.Lock()
defer webSocketConnLock.Unlock()
if nil != webSocketConn {
webSocketConn.Close()
webSocketConn = nil
}
}
func connectSyncWebSocket() {
defer logging.Recover()