Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'MousePointer',
'VisualEffect',
'Audio',
'TextCursor'
'TextCursor',
'ColorFilter'
)
PrivateData = @{
PSData = @{
Expand All @@ -26,7 +27,8 @@
'PSDscResource_MousePointer',
'PSDscResource_VisualEffect',
'PSDscResource_Audio',
'PSDscResource_TextCursor'
'PSDscResource_TextCursor',
'PSDscResource_ColorFilter'
)

# Prerelease string of this module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ enum PointerSize {
ExtraLarge
}

enum ColorFilters {
KeepCurrentValue
Greyscale
Inverted
GreyscaleInverted
Deuteranopia
Protanopia
Tritanopia
}

if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
$global:AccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Accessibility\'
$global:MagnifierRegistryPath = 'HKCU:\Software\Microsoft\ScreenMagnifier\'
Expand All @@ -37,10 +47,11 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
$global:PersonalizationRegistryPath = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\'
$global:NTAccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Accessibility\'
$global:CursorIndicatorAccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Accessibility\CursorIndicator\'
$global:ControlPanelDesktopRegistryPath= 'HKCU:\Control Panel\Desktop'
$global:ControlPanelDesktopRegistryPath = 'HKCU:\Control Panel\Desktop'
$global:ColorFilteringRegistryPath = 'HKCU:\Software\Microsoft\ColorFiltering'
}
else {
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $global:NTAccessibilityRegistryPath = $global:CursorIndicatorAccessibilityRegistryPath = $global:ControlPanelDesktopRegistryPath = $env:TestRegistryPath
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $global:NTAccessibilityRegistryPath = $global:CursorIndicatorAccessibilityRegistryPath = $global:ControlPanelDesktopRegistryPath = $global:ColorFilteringRegistryPath = $env:TestRegistryPath
}

[DSCResource()]
Expand Down Expand Up @@ -584,6 +595,128 @@ class TextCursor
}
}

[DSCResource()]
class ColorFilter
{
# Key required. Do not set.
[DscProperty(Key)] [string] $SID
[DscProperty()] [nullable[bool]] $FilterStatus
Comment thread
stephengillie marked this conversation as resolved.
Outdated
[DscProperty()] [ColorFilters] $FilterColor
[DscProperty()] [nullable[bool]] $KeyboardShortcutStatus
Comment thread
stephengillie marked this conversation as resolved.
Outdated

static hidden [string] $FilterStatusProperty = 'Configuration'
Comment thread
stephengillie marked this conversation as resolved.
Outdated
static hidden [string] $FilterStatusActiveProperty = 'Active'
Comment thread
stephengillie marked this conversation as resolved.
Outdated
static hidden [string] $FilterStatusValue = 'colorfiltering'
Comment thread
stephengillie marked this conversation as resolved.
Outdated
static hidden [string] $FilterColorProperty = 'FilterType'
static hidden [string] $KeyboardShortcutStatusProperty = 'HotkeyEnabled'
Comment thread
stephengillie marked this conversation as resolved.
Outdated

static [bool] GetStatus()
{
$FilterStatusArgs = @{ Path = $global:NTAccessibilityRegistryPath; Name = ([ColorFilter]::FilterStatusProperty)}
Comment thread
stephengillie marked this conversation as resolved.
Outdated
if (-not(DoesRegistryKeyPropertyExist @FilterStatusArgs))
{
return $false
}
else
{
$colorFilterSetting = (Get-ItemProperty @FilterStatusArgs).Configuration
Comment thread
stephengillie marked this conversation as resolved.
Outdated
return ($colorFilterSetting -eq ([ColorFilter]::FilterStatusValue))
Comment thread
stephengillie marked this conversation as resolved.
Outdated
}
}

static [int] GetColor()
Comment thread
stephengillie marked this conversation as resolved.
Outdated
{
$FilterColorArgs = @{ Path = $global:ColorFilteringRegistryPath; Name = ([ColorFilter]::FilterColorProperty)}
if (-not(DoesRegistryKeyPropertyExist @FilterColorArgs))
{
return $false
Comment thread
stephengillie marked this conversation as resolved.
}
else
{
$colorFilterSetting = (Get-ItemProperty @FilterColorArgs).FilterType
return $colorFilterSetting
}
}

static [nullable[bool]] GetKeyboardShortcutStatus()
Comment thread
stephengillie marked this conversation as resolved.
Outdated
{
$KeyboardShortcutStatusArgs = @{ Path = $global:ColorFilteringRegistryPath; Name = ([ColorFilter]::KeyboardShortcutStatusProperty); }
if (-not(DoesRegistryKeyPropertyExist @KeyboardShortcutStatusArgs))
{
return $false
}
else
{
$colorFilterSetting = (Get-ItemProperty @KeyboardShortcutStatusArgs).HotkeyEnabled
return $colorFilterSetting
}
}

[ColorFilter] Get()
{
$currentState = [ColorFilter]::new()
$currentState.FilterStatus = [ColorFilter]::GetStatus()
$currentState.FilterColor = [ColorFilter]::GetColor()
$currentState.KeyboardShortcutStatus = [ColorFilter]::GetKeyboardShortcutStatus()

return $currentState
}

[bool] Test()
{
$currentState = $this.Get()
if (($null -ne $this.FilterStatus) -and ($this.FilterStatus -ne $currentState.FilterStatus))
{
return $false
}
if ((0 -ne $this.FilterColor) -and ($this.FilterColor -ne $currentState.FilterColor))
{
return $false
}
if (($null -ne $this.KeyboardShortcutStatus) -and ($this.KeyboardShortcutStatus -ne $currentState.KeyboardShortcutStatus))
{
return $false
}

return $true
}

[void] Set()
{
if (-not $this.Test())
{
if ($null -ne $this.FilterStatus)
{
$FilterStatusArgs = @{ Path = $global:NTAccessibilityRegistryPath; Name = ([ColorFilter]::FilterStatusProperty); }
$ColorFilterValue = if ($this.FilterStatus) { ([ColorFilter]::FilterStatusValue) } else { "" }
Set-ItemProperty @FilterStatusArgs -Value $ColorFilterValue
}

if (0 -ne $this.FilterColor)
Comment thread
stephengillie marked this conversation as resolved.
Outdated
{
$FilterColorArgs = @{ Path = $global:ColorFilteringRegistryPath; Name = ([ColorFilter]::FilterColorProperty)}
$min = 1
$max = 99999999
if ($this.FilterColor -notin $min..$max)
{
throw "FilterColor must be between $min and $max. Value $($this.FilterColor) was provided."
}
Comment thread
stephengillie marked this conversation as resolved.
Outdated
if (-not (DoesRegistryKeyPropertyExist @FilterColorArgs)) {
New-ItemProperty @FilterColorArgs -Value $this.FilterColor -PropertyType DWord
}
Comment thread
stephengillie marked this conversation as resolved.
Outdated
Set-ItemProperty @FilterColorArgs -Value $this.FilterColor
Comment thread
stephengillie marked this conversation as resolved.
Outdated
}

if ($null -ne $this.KeyboardShortcutStatus)
{
$KeyboardShortcutStatusArgs = @{ Path = $global:ColorFilteringRegistryPath; Name = ([ColorFilter]::KeyboardShortcutStatusProperty); }
Comment thread
stephengillie marked this conversation as resolved.
Outdated
$ColorFilterValue = if ($this.KeyboardShortcutStatus) { ([ColorFilter]::KeyboardShortcutStatusProperty) } else { "" }
Comment thread
stephengillie marked this conversation as resolved.
Outdated
Set-ItemProperty @KeyboardShortcutStatusArgs -Value $ColorFilterValue
}
}
}
}

#region Functions
function DoesRegistryKeyPropertyExist {
param (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ BeforeAll {

Describe 'List available DSC resources' {
It 'Shows DSC Resources' {
$expectedDSCResources = "Text", "Magnifier", "MousePointer", "VisualEffect", "Audio", "TextCursor"
$expectedDSCResources = "Text", "Magnifier", "MousePointer", "VisualEffect", "Audio", "TextCursor", "ColorFilter"
$availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Accessibility).Name
$availableDSCResources.length | Should -Be 6
$availableDSCResources.length | Should -Be 7
$availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop
}
}
Expand Down Expand Up @@ -279,6 +279,62 @@ Describe 'TextCursor'{
}
}

Describe 'ColorFilter'{
It 'FilterStatus.'{
$initialState = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$initialState.FilterStatus # Should -Be $false

# Set 'FilterStatus' to true.
$parameters = @{ FilterStatus = $true }
$testResult = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult.InDesiredState | Should -Be $false

# Verify the changes are correct.
Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters
$finalState = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$finalState.FilterStatus | Should -Be $true

$testResult2 = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult2.InDesiredState | Should -Be $true
}
It 'FilterColor.'{
Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ FilterColor = 2 }
Comment thread
stephengillie marked this conversation as resolved.
Outdated

$initialState = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$initialState.FilterColor | Should -Be 2

# Set 'FilterColor' to 3.
$parameters = @{ FilterColor = 3 } #Increment default by 1
$testResult = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult.InDesiredState | Should -Be $false

# Verify the changes are correct.
Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters
$finalState = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$finalState.FilterColor | Should -Be 3

$testResult2 = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult2.InDesiredState | Should -Be $true
}
It 'KeyboardShortcutStatus.'{
$initialState = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$initialState.KeyboardShortcutStatus # Should -Be $false

# Set 'KeyboardShortcutStatus' to true.
$parameters = @{ KeyboardShortcutStatus = $true }
$testResult = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult.InDesiredState | Should -Be $false

# Verify the changes are correct.
Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters
$finalState = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$finalState.KeyboardShortcutStatus | Should -Be $true

$testResult2 = Invoke-DscResource -Name ColorFilter -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult2.InDesiredState | Should -Be $true
}
}

AfterAll {
$env:TestRegistryPath = ""
}