load DLL only once
This commit is contained in:
@@ -2,16 +2,30 @@
|
||||
|
||||
package backend
|
||||
|
||||
import "syscall"
|
||||
import (
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
ES_CONTINUOUS uint = 0x80000000
|
||||
ES_SYSTEM_REQUIRED uint = 0x00000001
|
||||
)
|
||||
|
||||
var (
|
||||
sleepDisabled atomic.Bool
|
||||
executionState *syscall.LazyProc
|
||||
)
|
||||
|
||||
func SetSystemSleepDisabled(disable bool) {
|
||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
executionState := kernel32.NewProc("SetThreadExecutionState")
|
||||
if old := sleepDisabled.Swap(disable); old == disable {
|
||||
return
|
||||
}
|
||||
|
||||
if executionState == nil {
|
||||
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
||||
executionState = kernel32.NewProc("SetThreadExecutionState")
|
||||
}
|
||||
|
||||
uType := ES_CONTINUOUS
|
||||
if disable {
|
||||
|
||||
Reference in New Issue
Block a user