mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
fix sleep win
This commit is contained in:
@@ -12,8 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EsSystemRequired = 0x00000001
|
EsSystemRequired = 0x00000001
|
||||||
EsContinuous = 0x80000000
|
EsAwaymodeRequired = 0x00000040 // Added for future improvements
|
||||||
|
EsContinuous = 0x80000000
|
||||||
)
|
)
|
||||||
|
|
||||||
var pulseTime = 1 * time.Minute
|
var pulseTime = 1 * time.Minute
|
||||||
@@ -23,20 +24,32 @@ func Preconfig(kill bool) {
|
|||||||
// don't sleep/hibernate windows
|
// don't sleep/hibernate windows
|
||||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||||
setThreadExecStateProc := kernel32.NewProc("SetThreadExecutionState")
|
setThreadExecStateProc := kernel32.NewProc("SetThreadExecutionState")
|
||||||
|
currentExecState := uintptr(EsContinuous)
|
||||||
|
normalExecutionState := uintptr(EsContinuous)
|
||||||
|
systemRequireState := uintptr(EsSystemRequired | EsContinuous)
|
||||||
pulse := time.NewTicker(pulseTime)
|
pulse := time.NewTicker(pulseTime)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-pulse.C:
|
case <-pulse.C:
|
||||||
{
|
{
|
||||||
send := false
|
systemRequired := false
|
||||||
for _, torrent := range torr.ListTorrent() {
|
for _, torrent := range torr.ListTorrent() {
|
||||||
if torrent.Stat != state.TorrentInDB {
|
if torrent.Stat != state.TorrentInDB {
|
||||||
send = true
|
systemRequired = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if send {
|
if systemRequired && currentExecState != systemRequireState {
|
||||||
setThreadExecStateProc.Call(uintptr(EsSystemRequired))
|
// Looks like sending just EsSystemRequired to clear timer is broken in Win11.
|
||||||
|
// Enable system required to avoid the system to idle to sleep.
|
||||||
|
currentExecState = systemRequireState
|
||||||
|
setThreadExecStateProc.Call(systemRequireState)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !systemRequired && currentExecState != normalExecutionState {
|
||||||
|
// Clear EXECUTION_STATE flags to disable away mode and allow the system to idle to sleep normally.
|
||||||
|
currentExecState = normalExecutionState
|
||||||
|
setThreadExecStateProc.Call(normalExecutionState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user