JosefNemec / Playnite

Video game library manager with support for wide range of 3rd party libraries and game emulation support, providing one unified interface for your games.
https://playnite.link
MIT License
8.66k stars 482 forks source link

Add "Turn off Windows nighlight" toggle in settings #3761

Closed JonathanPitre closed 3 weeks ago

JonathanPitre commented 3 weeks ago

Feature description

It would be cool to disable Windows nightlight automatically when Playnite is launched. I tried to script it but no luck.

The following reg key determines if nightlight is on or off, the binary value of Data changed but it's a random number each time.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Cloud\default$windows.data.bluelightreduction.bluelightreductionstate\windows.data.bluelightreduction.bluelightreductionstate

Screenshots

No response

JosefNemec commented 3 weeks ago

In my opinion, way too niche to be added as a built in feature since it can be done as custom startup script.

If you are having issues making it work, try these that popped up doing quick Google search:

https://superuser.com/a/1724561 https://www.powershellgallery.com/packages/Set-BlueLight/1.0.0/Content/Set-BlueLight.ps1

Second one probably doesn't work since 19H1 Windows 10 update.

JonathanPitre commented 3 weeks ago

I tested both and could not get it to work sadly

JosefNemec commented 3 weeks ago

I couldn't find any public Windows API to control this, everything points to these registry keys and if those no longer work, I have no other option how to implement this. So I can't add this as built-in feature even if I wanted.

JonathanPitre commented 2 weeks ago

I was able to get it working with the following code but I can't change the hours like I want to, something is wrong with the hex value in the function. At least, I'm able to automatically disable nighlight when playnite is launched via application script.

Function Set-BlueLightReductionSettings
{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)] [ValidateRange(0, 23)] [int]$StartHour,
        [Parameter(Mandatory = $true)] [ValidateSet(0, 15, 30, 45)] [int]$StartMinutes,
        [Parameter(Mandatory = $true)] [ValidateRange(0, 23)] [int]$EndHour,
        [Parameter(Mandatory = $true)] [ValidateSet(0, 15, 30, 45)] [int]$EndMinutes,
        [Parameter(Mandatory = $true)] [bool]$Enabled,
        [Parameter(Mandatory = $true)] [ValidateRange(1200, 6500)] [int]$NightColorTemperature
    )
    $data = (0x43, 0x42, 0x01, 0x00, 0x0A, 0x02, 0x01, 0x00, 0x2A, 0x06)
    $epochTime = [System.DateTimeOffset]::new((Get-date)).ToUnixTimeSeconds()
    $data += $epochTime -band 0x7F -bor 0x80
    $data += ($epochTime -shr 7) -band 0x7F -bor 0x80
    $data += ($epochTime -shr 14) -band 0x7F -bor 0x80
    $data += ($epochTime -shr 21) -band 0x7F -bor 0x80
    $data += $epochTime -shr 28
    $data += (0x2A, 0x2B, 0x0E, 0x1D, 0x43, 0x42, 0x01, 0x00)
    If ($Enabled) { $data += (0x02, 0x01) }
    $data += (0xCA, 0x14, 0x0E)
    $data += $StartHour
    $data += 0x2E
    $data += $StartMinutes
    $data += (0x00, 0xCA, 0x1E, 0x0E)
    $data += $EndHour
    $data += 0x2E
    $data += $EndMinutes
    $data += (0x00, 0xCF, 0x28)
    $data += ($NightColorTemperature -band 0x3F) * 2 + 0x80
    $data += ($NightColorTemperature -shr 6)
    $data += (0xCA, 0x32, 0x00, 0xCA, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00)
    Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.settings\windows.data.bluelightreduction.settings' -Name 'Data' -Value ([byte[]]$data) -Type Binary
}

# Disable Windows nightlight
Set-BlueLightReductionSettings -StartHour 8 -StartMinutes 0 -EndHour 8 -EndMinutes 0 -Enabled $False -NightColorTemperature 2500