mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🐛 桌面端系统睡眠唤醒后内核可能会自动退出 Fix https://github.com/siyuan-note/siyuan/issues/7314
This commit is contained in:
parent
9044438108
commit
6a5617dcc1
1 changed files with 46 additions and 37 deletions
|
|
@ -39,7 +39,6 @@ func HandleSignal() {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
firstRunHookDesktopUIProcJob = true
|
firstRunHookDesktopUIProcJob = true
|
||||||
noUIProcCount int
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func HookDesktopUIProcJob() {
|
func HookDesktopUIProcJob() {
|
||||||
|
|
@ -59,12 +58,34 @@ func HookDesktopUIProcJob() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uiProcNames := []string{"siyuan", "electron"}
|
uiProcCount := getAttachedUIProcCount()
|
||||||
uiProcessCount := 0
|
if 0 < uiProcCount {
|
||||||
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
return
|
||||||
// 从 UI 进程 ID 列表中找到 UI 进程
|
}
|
||||||
|
|
||||||
uiProcessCount++
|
logging.LogWarnf("no active UI proc, continue to check from attached ui processes after 15s")
|
||||||
|
time.Sleep(15 * time.Second)
|
||||||
|
uiProcCount = getAttachedUIProcCount()
|
||||||
|
if 0 < uiProcCount {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logging.LogWarnf("no active UI proc, continue to check from all processes after 15s")
|
||||||
|
time.Sleep(15 * time.Second)
|
||||||
|
uiProcCount = getUIProcCount()
|
||||||
|
if 0 < uiProcCount {
|
||||||
|
logging.LogInfof("active UI proc count [%d]", uiProcCount)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
logging.LogWarnf("confirmed no active UI proc, exit kernel process now")
|
||||||
|
Close(false, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var uiProcNames = []string{"siyuan", "electron"}
|
||||||
|
|
||||||
|
// getAttachedUIProcCount 获取已经附加的 UI 进程数。
|
||||||
|
func getAttachedUIProcCount() (ret int) {
|
||||||
|
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||||
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
|
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
|
||||||
|
|
@ -78,7 +99,6 @@ func HookDesktopUIProcJob() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil == proc {
|
if nil == proc {
|
||||||
noUIProcCount++
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,14 +107,16 @@ func HookDesktopUIProcJob() {
|
||||||
for _, name := range uiProcNames {
|
for _, name := range uiProcNames {
|
||||||
uiProcOk = strings.Contains(procName, name)
|
uiProcOk = strings.Contains(procName, name)
|
||||||
}
|
}
|
||||||
if !uiProcOk {
|
if uiProcOk {
|
||||||
noUIProcCount++
|
ret++
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if 1 > uiProcessCount {
|
// getUIProcCount 获取 UI 进程数。
|
||||||
// 如果 UI 进程 ID 列表中没有找到 UI 进程则从完整的进程列表中找
|
func getUIProcCount() (ret int) {
|
||||||
procs, _ := goPS.Processes()
|
procs, _ := goPS.Processes()
|
||||||
for _, proc := range procs {
|
for _, proc := range procs {
|
||||||
procName := strings.ToLower(proc.Executable())
|
procName := strings.ToLower(proc.Executable())
|
||||||
|
|
@ -103,21 +125,8 @@ func HookDesktopUIProcJob() {
|
||||||
uiProcOk = strings.Contains(procName, name)
|
uiProcOk = strings.Contains(procName, name)
|
||||||
}
|
}
|
||||||
if uiProcOk {
|
if uiProcOk {
|
||||||
uiProcessCount++
|
ret++
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if 1 > uiProcessCount {
|
|
||||||
noUIProcCount++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if 0 < noUIProcCount {
|
|
||||||
logging.LogInfof("no active UI proc count [%d]", noUIProcCount)
|
|
||||||
if 1 < noUIProcCount {
|
|
||||||
logging.LogInfof("confirmed no active UI proc, exit kernel process now")
|
|
||||||
Close(false, 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue