disable hibernate on open torrents

This commit is contained in:
YouROK
2021-09-08 11:45:52 +03:00
parent 8f38a35b0f
commit 42434c2f46

View File

@@ -6,6 +6,9 @@ package main
import ( import (
"syscall" "syscall"
"time" "time"
"server/torr"
"server/torr/state"
) )
const ( const (
@@ -16,6 +19,7 @@ const (
var pulseTime = 1 * time.Minute var pulseTime = 1 * time.Minute
func Preconfig(kill bool) { func Preconfig(kill bool) {
go func() {
// 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")
@@ -23,7 +27,19 @@ func Preconfig(kill bool) {
for { for {
select { select {
case <-pulse.C: case <-pulse.C:
{
send := false
for i, torrent := range torr.ListTorrent() {
if torrent.Stat != state.TorrentInDB {
send = true
break
}
}
if send {
setThreadExecStateProc.Call(uintptr(EsSystemRequired)) setThreadExecStateProc.Call(uintptr(EsSystemRequired))
} }
} }
} }
}
}()
}