🎨 改进桌面端监控前端界面进程退出钩子
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() {
|
||||
// 如果存在活动的会话则说明 UI 进程还在运行
|
||||
return
|
||||
}
|
||||
|
||||
uiProcNames := []string{"siyuan", "electron"}
|
||||
uiProcessCount := 0
|
||||
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||
// 从 UI 进程 ID 列表中找到 UI 进程
|
||||
|
||||
uiProcessCount++
|
||||
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||
if nil != err {
|
||||
|
@ -89,8 +92,24 @@ func HookDesktopUIProcJob() {
|
|||
}
|
||||
return true
|
||||
})
|
||||
|
||||
if 1 > uiProcessCount {
|
||||
noUIProcCount++
|
||||
// 如果 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 {
|
||||
noUIProcCount++
|
||||
}
|
||||
}
|
||||
|
||||
if 0 < noUIProcCount {
|
||||
|
|
Loading…
Add table
Reference in a new issue