♻️ 桌面端内核进程端口号写入文件 port.json
https://github.com/siyuan-note/siyuan/issues/6337
This commit is contained in:
parent
2c785fda93
commit
69ed492679
1 changed files with 34 additions and 1 deletions
|
@ -17,6 +17,7 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
@ -94,7 +95,12 @@ func Serve(fastMode bool) {
|
|||
}
|
||||
}
|
||||
|
||||
logging.LogInfof("kernel is booting [%s]", "http://"+host+":"+port)
|
||||
pid := fmt.Sprintf("%d", os.Getpid())
|
||||
if !fastMode {
|
||||
rewritePortJSON(pid, port)
|
||||
}
|
||||
|
||||
logging.LogInfof("kernel [pid=%s] is booting [%s]", pid, "http://"+host+":"+port)
|
||||
util.HttpServing = true
|
||||
|
||||
if err = http.Serve(ln, ginServer); nil != err {
|
||||
|
@ -105,6 +111,33 @@ func Serve(fastMode bool) {
|
|||
}
|
||||
}
|
||||
|
||||
func rewritePortJSON(pid, port string) {
|
||||
portJSON := filepath.Join(util.HomeDir, ".config", "siyuan", "port.json")
|
||||
pidPorts := map[string]string{}
|
||||
var data []byte
|
||||
var err error
|
||||
|
||||
if gulu.File.IsExist(portJSON) {
|
||||
data, err = os.ReadFile(portJSON)
|
||||
if nil != err {
|
||||
logging.LogWarnf("read port.json failed: %s", err)
|
||||
} else {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &pidPorts); nil != err {
|
||||
logging.LogWarnf("unmarshal port.json failed: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pidPorts[pid] = port
|
||||
if data, err = gulu.JSON.MarshalIndentJSON(pidPorts, "", " "); nil != err {
|
||||
logging.LogWarnf("marshal port.json failed: %s", err)
|
||||
} else {
|
||||
if err = os.WriteFile(portJSON, data, 0644); nil != err {
|
||||
logging.LogWarnf("write port.json failed: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func serveExport(ginServer *gin.Engine) {
|
||||
ginServer.Static("/export/", filepath.Join(util.TempDir, "export"))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue