Skip to content

Repository files navigation

WakeLock

Build Test Abstractions Windows macOS Linux .NET 10

WakeLock use-case doodle

Cross-platform .NET wake lock libraries for preventing system sleep and, optionally, display sleep.

Examples

Windows

Install:

dotnet add package Capjan.WakeLock.Windows

Use:

using Capjan.WakeLock;

using var wakeLock = new WindowsWakeLockService();
using var handle = wakeLock.Acquire(WakeLockLevel.PreventSleep);
macOS

Install:

dotnet add package Capjan.WakeLock.MacOS

Use:

using Capjan.WakeLock;

using var wakeLock = new MacOSWakeLockService();
using var handle = wakeLock.Acquire(WakeLockLevel.PreventSleep);
Linux

Install:

dotnet add package Capjan.WakeLock.Linux

Use:

using Capjan.WakeLock;

using var wakeLock = new LinuxWakeLockService();
using var handle = wakeLock.Acquire(WakeLockLevel.PreventSleep);

Note

  • Keep the returned handle alive as long as you want the wake lock active.
  • Dispose the handle to release one acquisition.
  • Dispose the service to release all active acquisitions.
  • Use WakeLockLevel.PreventSleepAndDisplay if display sleep should be prevented too.
  • Use Capjan.WakeLock.Abstractions if you only want the shared API (IWakeLockService, WakeLockLevel).

Samples

.NET Tool

A simple cross-platform dotnet tool that prevents your machine from sleeping until you press a key.

Source: samples/Capjan.WakeLock.Tool

Install:

dotnet tool install --global Capjan.WakeLock.Tool

Run:

wakelock

Add --help to see all options.

Building

dotnet build WakeLock.slnx
dotnet pack WakeLock.slnx --configuration Release

Release Policy

  • All packable projects in this repository (libraries and Capjan.WakeLock.Tool) must share one identical version.
  • Versioning is derived from the Git tag via MinVer (v<semver> tags).
  • Releases are published from one repository release so all NuGet artifacts stay aligned.
  • CI enforces version consistency across all packable projects.

License

Permissive MIT license (see LICENSE) that allows commercial and open-source use with minimal obligations.

About

.NET wake lock libraries for Windows, macOS, and Linux.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages