This commit is contained in:
Liang Ding 2023-01-26 23:30:29 +08:00
parent 78ed38a33a
commit df9122b664
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
16 changed files with 175 additions and 197 deletions

View file

@ -37,45 +37,51 @@ func HandleSignal() {
Close(false, 1)
}
func HookDesktopUIProc() {
var firstRunHookDesktopUIProcJob = true
func HookDesktopUIProcJob() {
if util.ContainerStd != util.Container || "dev" == util.Mode {
return
}
time.Sleep(30 * time.Second)
if firstRunHookDesktopUIProcJob {
// 等待启动结束再
time.Sleep(30 * time.Second)
firstRunHookDesktopUIProcJob = false
return
}
uiProcNames := []string{"siyuan", "electron"}
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 nil == proc {
return true
}
procName := strings.ToLower(proc.Executable())
for _, name := range uiProcNames {
if strings.Contains(procName, name) {
existUIProc = true
return false
}
}
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
})
if !existUIProc {
logging.LogInfof("no active UI proc, exit kernel process now")
Close(false, 1)
}
proc, err := goPS.FindProcess(uiProcID)
if nil != err {
logging.LogErrorf("find UI proc [%d] failed: %s", uiProcID, err)
return true
}
if nil == proc {
return true
}
procName := strings.ToLower(proc.Executable())
for _, name := range uiProcNames {
if strings.Contains(procName, name) {
existUIProc = true
return false
}
}
return true
})
if !existUIProc {
logging.LogInfof("no active UI proc, exit kernel process now")
Close(false, 1)
}
}