hostPowerRunner function

PowerAssertionRunner hostPowerRunner({
  1. required int pid,
  2. String? os,
  3. PowerProcessLauncher? launcher,
})

The platform runner: caffeinate on macOS, systemd-inhibit on Linux, a no-op with an explicit note everywhere else. os overrides the detected platform (tests); launcher overrides the spawn (tests).

Implementation

PowerAssertionRunner hostPowerRunner({
  required int pid,
  String? os,
  PowerProcessLauncher? launcher,
}) => switch (os ?? Platform.operatingSystem) {
  'macos' => CaffeinatePowerRunner(pid: pid, launcher: launcher),
  'linux' => SystemdInhibitPowerRunner(pid: pid, launcher: launcher),
  final other => NoopPowerAssertionRunner(
    'sleep prevention is not implemented on $other yet',
  ),
};