mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 桌面端内核进程根据 Electron 主进程判断是否自动退出 Fix https://github.com/siyuan-note/siyuan/issues/7002
This commit is contained in:
parent
2296b6dc63
commit
4ba967cc98
2 changed files with 42 additions and 0 deletions
|
|
@ -51,6 +51,7 @@ func main() {
|
||||||
go sql.AutoFlushTreeQueue()
|
go sql.AutoFlushTreeQueue()
|
||||||
go treenode.AutoFlushBlockTree()
|
go treenode.AutoFlushBlockTree()
|
||||||
go cache.LoadAssets()
|
go cache.LoadAssets()
|
||||||
|
go model.HookDesktopUIProc()
|
||||||
model.WatchAssets()
|
model.WatchAssets()
|
||||||
model.HandleSignal()
|
model.HandleSignal()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,14 @@ package model
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
goPS "github.com/mitchellh/go-ps"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
"github.com/siyuan-note/siyuan/kernel/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleSignal() {
|
func HandleSignal() {
|
||||||
|
|
@ -31,3 +36,39 @@ func HandleSignal() {
|
||||||
logging.LogInfof("received os signal [%s], exit kernel process now", s)
|
logging.LogInfof("received os signal [%s], exit kernel process now", s)
|
||||||
Close(false, 1)
|
Close(false, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HookDesktopUIProc() {
|
||||||
|
if util.ContainerStd != util.Container {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
existUIProc := false
|
||||||
|
for range time.Tick(7 * time.Second) {
|
||||||
|
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||||
|
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
proc, err := goPS.FindProcess(uiProcID)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("find UI proc [%d] failed: %s", uiProcID, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(strings.ToLower(proc.Executable()), "siyuan") {
|
||||||
|
existUIProc = true
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if !existUIProc {
|
||||||
|
logging.LogInfof("no active UI proc, exit kernel process now")
|
||||||
|
Close(false, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue