prevent sleep on Windows when playing
This commit is contained in:
@@ -127,6 +127,16 @@ func StartupApp(appName, displayAppName, appVersionTag, latestReleaseURL string)
|
|||||||
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
_, _ = a.ImageManager.GetCoverThumbnail(coverID)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
a.PlaybackManager.OnPlaying(func() {
|
||||||
|
SetSystemSleepDisabled(true)
|
||||||
|
})
|
||||||
|
a.PlaybackManager.OnPaused(func() {
|
||||||
|
SetSystemSleepDisabled(false)
|
||||||
|
})
|
||||||
|
a.PlaybackManager.OnStopped(func() {
|
||||||
|
SetSystemSleepDisabled(false)
|
||||||
|
})
|
||||||
|
|
||||||
// Start IPC server if another not already running in a different instance
|
// Start IPC server if another not already running in a different instance
|
||||||
if cli == nil {
|
if cli == nil {
|
||||||
ipc.DestroyConn() // cleanup socket possibly orphaned by crashed process
|
ipc.DestroyConn() // cleanup socket possibly orphaned by crashed process
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package backend
|
||||||
|
|
||||||
|
func SetSystemSleepDisabled(disable bool) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user