awake

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package awake keeps the computer Exhale runs on from going to sleep, so that reminders go out on time and chat buttons keep answering (ADR 0028).

Each operating system has its own way, none of them needs cgo:

  • macOS runs /usr/bin/caffeinate tied to Exhale's process id;
  • Windows calls SetThreadExecutionState from a thread kept for it;
  • Linux runs systemd-inhibit with a block lock on idle and sleep.

Elsewhere, and inside a container, it is not available.

Index

Constants

This section is empty.

Variables

View Source
var ErrContainer = errors.New("running in a container, which cannot keep the host awake")

ErrContainer is returned by Available when Exhale runs in a container: the machine that sleeps is the host, out of reach.

View Source
var ErrNeedsSetup = errors.New("keeping a closed laptop awake needs the administrator's permission once")

ErrNeedsSetup is returned by Lid.Available on a Mac whose administrator has not allowed Exhale to turn lid sleep off yet (Lid.Setup).

View Source
var ErrUnsupported = errors.New("keeping the computer awake is not supported on this operating system")

ErrUnsupported is returned by Available on an operating system Exhale cannot keep awake.

Functions

This section is empty.

Types

type Keeper

type Keeper interface {
	// Available reports why the machine cannot be kept awake here: nil when
	// it can, ErrContainer, ErrUnsupported or another error (a missing
	// tool).
	Available() error
	// Hold keeps the system awake, and the display too with display, until
	// Release. Calling it while holding replaces the previous hold.
	Hold(display bool) error
	// Release lets the machine sleep again. It does nothing when nothing is
	// held.
	Release()
	// Lost reports why a hold ended on its own (the helper process exited),
	// or nil while it is still in place or nothing is held.
	Lost() error
}

Keeper holds the machine awake. Its methods are safe for one caller at a time (the controller in internal/app serializes them).

func New

func New() Keeper

New returns the keeper of this operating system.

type Lid added in v0.4.0

type Lid interface {
	// Available reports why the lid cannot be held: nil when it can,
	// ErrNeedsSetup, ErrUnsupported, ErrContainer or another error.
	Available() error
	// Setup asks for the permission Available lacks (macOS: the
	// administrator's password, in a dialog on this computer).
	Setup(ctx context.Context) error
	// Hold keeps the computer awake when the lid closes, until Release.
	Hold() error
	// Release lets the lid put the computer to sleep again and, when the
	// lid is already closed, puts it to sleep now: the system does not look
	// at the lid again by itself, so a closed laptop would stay awake in a
	// bag until its battery runs out.
	Release() error
	// Recover undoes a hold that a previous run left in place (a crash, a
	// forced quit). It does nothing when there is none.
	Recover() error
}

Lid keeps the computer awake with its lid closed. Its methods are safe for one caller at a time (the controller in internal/app serializes them).

func NewLid added in v0.4.0

func NewLid(dir string) Lid

NewLid returns the lid switch of this operating system. dir is where its marker is kept: Exhale's data directory.

type Power added in v0.4.0

type Power struct {
	// Known is false when the system did not say (Read failed).
	Known bool `json:"known"`
	// HasBattery is false on a desktop: it never runs on battery.
	HasBattery bool `json:"hasBattery"`
	OnBattery  bool `json:"onBattery"`
	// Percent is the battery's charge, 0 to 100.
	Percent int `json:"percent"`
}

Power is the computer's power source, as the system reports it.

func ReadPower added in v0.4.0

func ReadPower() Power

ReadPower asks the system for its power source.

Jump to

Keyboard shortcuts

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