Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

duenight

Automatic Windows Night Light recovery for blue light at night.

When Night Light is turned OFF manually, duenight waits a configurable timer (default: 5 minutes), then turns it back ON and fades in over a configurable fade duration (default: 15 seconds), so blue light at night feels right.

Features

  • Main script: duenight.ps1
  • Windows-only
  • Uses native Night Light settings (reads current strength each restore)
  • Interactive menu:
    • Install (when not installed)
    • Reinstall (when installed)
    • Uninstall (when installed)
    • Change timer (default 5 minutes)
    • Change fade (default 15 seconds)
    • Toggle schedule-follow mode (true/false)
  • Auto-start at login (per-user HKCU\...\Run) via a tiny VBScript launcher so no PowerShell console window flashes at sign-in
  • Notification-area tray icon (sleek crescent moon as duenight-tray.ico) while the service runs; hover shows live status (including fade countdown). The service starts PowerShell with -STA so WinForms can host the icon reliably. If the service runs under pwsh, the .ico is generated by a short Windows PowerShell 5.1 child process (pwsh’s GDI+ compile chain is unreliable for this). On first tray startup, Lucide moon.svg may be downloaded once into %LOCALAPPDATA%\duenight\third-party\ for attribution only (ISC).
  • No NuGet/npm dependencies (optional one-time HTTPS fetch for the reference SVG)

Requirements

  • Windows 10/11 with Night Light support
  • PowerShell 5+ (Windows PowerShell) or PowerShell 7 (pwsh)

Usage

Open PowerShell in this folder and run:

.\duenight.ps1

You will get a menu that shows install status and available actions.

How install works

Install adds this startup entry:

  • Registry path: HKCU:\Software\Microsoft\Windows\CurrentVersion\Run
  • Value name: duenight
  • Command: wscript.exe //B "%LOCALAPPDATA%\duenight\duenight-run.vbs" — the VBS starts PowerShell with -WindowStyle Hidden and window style 0 (fully hidden)

Install also launches the background service immediately, so protection starts right away.

Already installed from an older build? Open .\duenight.ps1 once (menu); it refreshes duenight-run.vbs and the Run key if needed. Or choose Reinstall.

No admin rights are required for per-user startup install.

Config

Settings are stored in the registry:

  • Key: HKCU\Software\duenight
  • Values: TimerMinutes (string, any decimal in range 0.1240, e.g. 0.1, 1.25), FadeSeconds (DWORD, range 0300), PollSeconds, FollowSchedule (DWORD 0/1)

Defaults: 5 minutes, 15 seconds fade, 2 seconds poll, FollowSchedule = true. Timer range: 0.1240 minutes (decimals allowed).

Use menu option Change timer to update the timer.

Use menu option Change fade to update the fade duration (0300 seconds, whole numbers).

Use menu option Follow schedule (true/false) to control schedule behavior:

  • false: always turn Night Light back on after the timer.
  • true (default): only turn Night Light back on if current time is inside the active Night Light schedule window.

Behavior details

  • Monitors Night Light state continuously in service mode.
  • Only reacts when user turns Night Light OFF.
  • Starts the OFF timer.
  • If user turns Night Light back ON before timer ends, timer is canceled.
  • If timer expires while still OFF:
    • If FollowSchedule is false, always restore.
    • If FollowSchedule is true, restore only when inside schedule; otherwise skip restore.
    • When restoring, re-reads current Night Light strength from Windows settings.
    • Enables Night Light.
    • Fades from 0 to target strength over the configured fade duration (time-based ramp; at most one registry write per strength percent).
    • After a successful restore (and on fade-recovery), applies a tiny strength “nudge” (e.g. 45% → 46% → 45%) so Windows actually applies the blue-light filter when the registry already looked correct (same idea as moving the slider one notch).
  • Registry writes carry a proper CloudStore timestamp (epoch-seconds VLQ, always ≥ the value Windows holds); writes with an older timestamp would be silently reverted by Windows.
  • If Windows rejects a write and replaces the settings value with a stub, the service restores it from the last known-good backup (HKCU\Software\duenight, value SettingsBackup).
  • On service start, an interrupted fade (crash/shutdown mid-fade) is detected and the configured strength is restored immediately.
  • Night Light on/off detection reads the 10 00 active marker in the state blob, so schedule-driven transitions are recognized correctly (the old byte-18 check missed them).

Optional logs

Service writes basic logs to:

  • duenight.log (rotates to duenight.log.old at 512 KB)

Uninstall

Run:

.\duenight.ps1

Then choose Uninstall from the menu.

Uninstall stops the background service, removes the startup entry, the installed script, launcher VBS, and duenight-tray.ico under %LOCALAPPDATA%\duenight\. It does not delete HKCU\Software\duenight (so your timer and other settings survive a reinstall). To wipe settings too, delete that registry key manually in regedit.

About

Automatic Windows Night Light recovery for blue light at night.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages