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