Documentation
¶
Overview ¶
Package power provides cgo-free control over system power behavior.
Today it does one thing: keep the system awake. PreventSleep asks the OS not to idle-sleep until the returned Token is released — the keep-awake you want around a long copy, a build, or media playback. Each platform binds the API the OS already ships, with no cgo and no bundled native libraries.
tok, err := power.PreventSleep("ripping a disc")
if err != nil {
// errors.Is(err, power.ErrUnsupported) on platforms with no backend
}
defer tok.Release()
Backends: macOS uses an IOKit power-management assertion, Windows uses SetThreadExecutionState. Linux has no portable cgo-free path (the systemd login1 inhibitor needs D-Bus, which this module deliberately avoids), so it returns ErrUnsupported.
Battery / power-source state is intentionally out of scope for now; it is a separate, side-effect-free concern and is not needed yet.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("power: not supported on this platform")
ErrUnsupported is returned by PreventSleep on a platform that has no backend.
Functions ¶
This section is empty.
Types ¶
type Token ¶
type Token struct {
// contains filtered or unexported fields
}
Token represents one active sleep inhibition. Release it to let the system idle-sleep normally again.
func PreventSleep ¶
PreventSleep asks the OS to keep the system from idle-sleeping until the returned Token is released.
reason is a short human-readable label some platforms surface in their power tooling (it becomes the macOS assertion name) and others ignore. On a platform with no backend it returns ErrUnsupported and a nil Token.