battery

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT, Unlicense Imports: 4 Imported by: 0

Documentation

Overview

Package battery provides functions to get the current status of the batteries.

That is useful to change app behavior based on the battery level. You can reduce animations or requests when the battery Level is low or if the user IsSaving battery.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAvailableAPI indicates that the current device/OS doesn't support such function.
	ErrNotAvailableAPI = errors.New("pref: not available api")

	// ErrNoSystemBattery indicates that the current device doesn't use batteries.
	//
	// Some APIs (like Android and JS) don't provide a mechanism to determine whether the machine uses batteries or not.
	// In such a case ErrNoSystemBattery will never be returned.
	ErrNoSystemBattery = errors.New("pref: device isn't battery-powered")
)

Functions

func IsCharging

func IsCharging() (bool, error)

IsCharging returns "true" if the device is charging. If the device doesn't rely on batteries it will be always true.

func IsSaving

func IsSaving() (bool, error)

IsSaving returns "true" if the end-user enables the battery saver on the device.

func Level

func Level() (uint8, error)

Level returns the battery level as percent level, between 0~100.

Types

This section is empty.

Jump to

Keyboard shortcuts

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