mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 改进桌面端监控前端界面进程退出钩子
This commit is contained in:
parent
4602976a8a
commit
eea6c9468a
1 changed files with 20 additions and 1 deletions
|
|
@ -55,12 +55,15 @@ func HookDesktopUIProcJob() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 < util.CountSessions() {
|
if 0 < util.CountSessions() {
|
||||||
|
// 如果存在活动的会话则说明 UI 进程还在运行
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uiProcNames := []string{"siyuan", "electron"}
|
uiProcNames := []string{"siyuan", "electron"}
|
||||||
uiProcessCount := 0
|
uiProcessCount := 0
|
||||||
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||||
|
// 从 UI 进程 ID 列表中找到 UI 进程
|
||||||
|
|
||||||
uiProcessCount++
|
uiProcessCount++
|
||||||
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
|
|
@ -89,9 +92,25 @@ func HookDesktopUIProcJob() {
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if 1 > uiProcessCount {
|
||||||
|
// 如果 UI 进程 ID 列表中没有找到 UI 进程则从完整的进程列表中找
|
||||||
|
procs, _ := goPS.Processes()
|
||||||
|
for _, proc := range procs {
|
||||||
|
procName := strings.ToLower(proc.Executable())
|
||||||
|
uiProcOk := false
|
||||||
|
for _, name := range uiProcNames {
|
||||||
|
uiProcOk = strings.Contains(procName, name)
|
||||||
|
}
|
||||||
|
if uiProcOk {
|
||||||
|
uiProcessCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if 1 > uiProcessCount {
|
if 1 > uiProcessCount {
|
||||||
noUIProcCount++
|
noUIProcCount++
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if 0 < noUIProcCount {
|
if 0 < noUIProcCount {
|
||||||
logging.LogInfof("no active UI proc count [%d]", noUIProcCount)
|
logging.LogInfof("no active UI proc count [%d]", noUIProcCount)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue