Skip to content

TheNolle/CaffeineTray

Repository files navigation

CaffeineTray

Ultra-light Windows tray app that prevents idle sleep. Left-click toggles. Right-click shows menu, Settings, and About. Dark/light follows system theme.

Features

  • Prevents idle system sleep
  • Optional display stay-on
  • Single-instance guard
  • Auto-start toggle (HKCU\Run)
  • Theme-aware Settings + About
  • Pure .NET 8 WinForms

Supported Windows

  • Windows 11
  • Windows 10 (1607+)
    Requires x64

Download

  • Releases: single portable CaffeineTray.exe
    No installer. No extra files.

Run

Double-click CaffeineTray.exe.
Tray icon appears.
Left-click: toggle on/off.
Right-click: menu -> Settings..., About..., Exit.

Build from source

Only needed if you want to build; running the release EXE does not need .NET.

Prereqs

winget install Microsoft.DotNet.SDK.8           # Install .NET 8
winget install Microsoft.VisualStudioCode       # Install Visual Studio Code
code --install-extension ms-dotnettools.csharp  # Install C# vscode extension

Clone and build

git clone https://github.com/TheNolle/CaffeineTray.git
cd CaffeineTray
dotnet build

Publish portable single-file

dotnet publish -c Release -r win-x64 `
  -p:SelfContained=true -p:PublishSingleFile=true `
  -p:TrimMode=link -p:InvariantGlobalization=true
# output:
# .\bin\Release\net8.0-windows\win-x64\publish\CaffeineTray.exe

Usage

  • ON blocks idle sleep.
  • Also keep display awake blocks screen-off due to idle.
  • Battery saver does not disable this. Manual sleep, lid-close, group policy, or critical battery can still suspend the PC.

Quick test (30 seconds)

powercfg /requests

Expect

SYSTEM:
  [PROCESS] CaffeineTray.exe
DISPLAY:                      # only if display option enabled
  [PROCESS] CaffeineTray.exe

Settings

  • Start enabled: app starts ON
  • Also keep display awake: blocks screen-off
  • Run at Windows startup: toggles HKCU...\Run

Autostart (alt method)

Copy a shortcut to:

%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

Theming

Follows Windows Apps theme:

  • Light: standard WinForms palette
  • Dark: dark content colors + DWM dark titlebar
    Auto-updates on theme change.

Single instance

A global mutex prevents multiple instances. Second launch exits immediately.

Power behavior details

  • Uses SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED*)
  • Re-applies after resume and unlock
  • Does not override:
    • Manual Sleep/Shutdown/Restart
    • Lid close policy
    • Critical battery actions
    • Admin/Group Policy timers
    • OEM power tools

Troubleshooting

  • No tray icon: Explorer may have restarted. Unlock or re-login, or right-click -> Exit then relaunch. Icons are embedded; the EXE alone is sufficient.
  • Double-click does nothing: an instance is already running in tray (single-instance guard).
  • powercfg /requests shows nothing: ensure app is ON. Left-click the icon to toggle.

Development notes

Project targets net8.0-windows. Pure WinForms. Icons embedded as resources. No external deps.

Build scripts (optional defaults in csproj)

  • Single-file self-contained publish:
dotnet publish -c Release -r win-x64 -p:SelfContained=true -p:PublishSingleFile=true -p:TrimMode=link -p:InvariantGlobalization=true
  • Framework-dependent publish (tiny, needs .NET Desktop Runtime):
dotnet publish -c Release -r win-x64 -p:SelfContained=false -p:PublishSingleFile=false

Contributing

Privacy

  • No telemetry
  • No network calls
  • collected

License

NFE-OSL v1.0

Credits

  • Author: Nolly @ Nolly's Holding
  • Versioning: 1.0.0 (Major.Minor.Hotfix)