Documentation
¶
Overview ¶
Package batteryalert decides when a battery deserves a notification and when the power profile follows the battery: pure functions over consecutive UPower readings, so every transition is a table test.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PeripheralIcon ¶
func PeripheralIcon(p upower.Peripheral) string
PeripheralIcon is the themed icon for the peripheral's kind.
func PeripheralName ¶
func PeripheralName(p upower.Peripheral) string
PeripheralName is the model UPower reports, or the kind's name when it reports none.
func Watch ¶
func Watch(ctx context.Context, battery upower.Source, profiles powerprofiles.Source, notifier Notifier, config func() Config) error
Watch follows the battery and the peripherals until ctx ends: each PropertiesChanged, DeviceAdded and DeviceRemoved is read and stepped through Next and the saver. Nothing runs between signals. profiles may be nil, which leaves the power profile alone.
Types ¶
type Config ¶
Config is what the watcher reads from the user's configuration on every change, so a reload applies to the next reading.
type Level ¶
type Level uint8
Level is what an alert announces.
func Next ¶
Next is the alert the step from prev to cur raises, if any. Low and Critical follow UPower's WarningLevel, so the thresholds are UPower's PercentageLow and PercentageCritical: one alert on entering each, none while staying, and since plugging in clears the warning, unplugging again re-arms both. Charged fires once when a battery charging crosses chargedAt; zero turns it off.
type Notifier ¶
type Notifier interface {
SendCritical(ctx context.Context, appName, summary, body, appIcon string) (uint32, error)
}
Notifier posts a critical notification; desktopnotify's Sender is one.
type Reading ¶
type Reading struct {
Warning upower.WarningLevel
Percentage float64
State upower.DeviceState
}
Reading is the part of a UPower device the alerts follow.
func FromDevice ¶
FromDevice is the DisplayDevice's reading.
func FromPeripheral ¶
func FromPeripheral(p upower.Peripheral) Reading
FromPeripheral is a peripheral's reading.
type Saver ¶
Saver is the automatic power-saver's memory: whether it switched, and the profile it switched away from ("" when power-saver was already active, so there is nothing to give back).