Skip to content

Commit e94d5a7

Browse files
committed
Disallow sleep while application is running
1 parent 61163cc commit e94d5a7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ var (
9898
func main() {
9999
checkDebugParam()
100100
loaded := loadSettings()
101+
preventSleep()
101102

102103
window := g.NewMasterWindow("Anime4K-GUI", 1600, 950, g.MasterWindowFlagsNotResizable)
103104
searchHardwareAcceleration()

sleep.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"syscall"
6+
)
7+
8+
var (
9+
kernel32 = syscall.NewLazyDLL("kernel32.dll")
10+
procSetThreadExecutionState = kernel32.NewProc("SetThreadExecutionState")
11+
)
12+
13+
const (
14+
ES_CONTINUOUS = 0x80000000
15+
ES_SYSTEM_REQUIRED = 0x00000001
16+
ES_DISPLAY_REQUIRED = 0x00000002
17+
)
18+
19+
func preventSleep() {
20+
ret, _, err := procSetThreadExecutionState.Call(
21+
uintptr(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED),
22+
)
23+
24+
if ret == 0 {
25+
logMessage(fmt.Sprintf("Failed to block sleep/hibernation: %v\n", err), false)
26+
}
27+
}

0 commit comments

Comments
 (0)