prevent sleep on Windows when playing

This commit is contained in:
Drew Weymouth
2024-07-18 18:25:14 -07:00
parent 867e2c44b6
commit bc89cc20fc
3 changed files with 39 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
//go:build windows
package backend
import "syscall"
const (
ES_CONTINUOUS uint = 0x80000000
ES_SYSTEM_REQUIRED uint = 0x00000001
)
func SetSystemSleepDisabled(disable bool) {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
executionState := kernel32.NewProc("SetThreadExecutionState")
uType := ES_CONTINUOUS
if disable {
uType |= ES_SYSTEM_REQUIRED
}
syscall.SyscallN(executionState.Addr(), 1, uintptr(uType), 0, 0)
}