daemon

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package daemon runs lys-power: one idempotent, side-effecting evaluation of power source, profile and charge thresholds, driven by events rather than a polling loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg config.Config, log *slog.Logger) error

Run evaluates the policy until the context is canceled. It sleeps until something can change the outcome: an AC edge (UPower's OnBattery), a charge-to-full request (inotify on the runtime directory), the next time-based change Eval reports (a wall-clock timer that survives suspend and clock changes), or SIGHUP. Without a system bus it falls back to checking the power source every Tick; losing the bus ends it with an error.

Types

type ProfileClient

type ProfileClient interface {
	Available() ([]string, error)
	Set(name string) error
}

ProfileClient is the slice of power-profiles-daemon the manager needs. A nil client means profile handling is unavailable and is skipped.

type Result

type Result struct {
	OnAC           bool
	ProfileSet     string
	RecordedUnplug bool
	ClearedFullNow bool
	// Applied holds the thresholds written by this evaluation, nil when
	// they were already in place or not managed.
	Applied *supply.Thresholds
	// Recheck is when the outcome next changes with the passage of time
	// alone; zero means only an event can change it.
	Recheck time.Time
}

Result reports what one evaluation observed and changed.

func Eval

func Eval(cfg config.Config, log *slog.Logger, now time.Time, pc ProfileClient) (Result, error)

Eval performs one evaluation of the policy. It is idempotent: nothing at the wanted state is touched, including a profile the user picked by hand between AC edges.

func (Result) Changed

func (r Result) Changed() bool

Changed reports whether the evaluation altered any state.

func (Result) LogValue

func (r Result) LogValue() slog.Value

LogValue renders the result for structured logs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL