Skip to content

Commit

Permalink
Disallow sleep while application is running
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigal committed May 30, 2024
1 parent 61163cc commit e94d5a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ var (
func main() {
checkDebugParam()
loaded := loadSettings()
preventSleep()

window := g.NewMasterWindow("Anime4K-GUI", 1600, 950, g.MasterWindowFlagsNotResizable)
searchHardwareAcceleration()
Expand Down
27 changes: 27 additions & 0 deletions sleep.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"
"syscall"
)

var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procSetThreadExecutionState = kernel32.NewProc("SetThreadExecutionState")
)

const (
ES_CONTINUOUS = 0x80000000
ES_SYSTEM_REQUIRED = 0x00000001
ES_DISPLAY_REQUIRED = 0x00000002
)

func preventSleep() {
ret, _, err := procSetThreadExecutionState.Call(
uintptr(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED),
)

if ret == 0 {
logMessage(fmt.Sprintf("Failed to block sleep/hibernation: %v\n", err), false)
}
}

0 comments on commit e94d5a7

Please sign in to comment.