Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EyeControl to Microsoft.Windows.Setting.Accessibility #127

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -18,7 +18,8 @@
'TextCursor',
'StickyKeys',
'ToggleKeys',
'FilterKeys'
'FilterKeys',
'EyeControl'
)
PrivateData = @{
PSData = @{
Expand All @@ -32,7 +33,8 @@
'PSDscResource_TextCursor',
'PSDscResource_StickyKeys',
'PSDscResource_ToggleKeys',
'PSDscResource_FilterKeys'
'PSDscResource_FilterKeys',
'PSDscResource_EyeControl'
)

# Prerelease string of this module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest

enum Ensure {
Absent
Present
}

enum TextSize {
KeepCurrentValue
Small
Expand Down Expand Up @@ -78,8 +83,9 @@
$global:StickyKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\StickyKeys'
$global:ToggleKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\ToggleKeys'
$global:FilterKeysRegistryPath = 'HKCU:\Control Panel\Accessibility\Keyboard Response'
$global:EyeControlRegistryPath = 'HKCU:\Software\Microsoft\input\EC\'
} else {
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $global:NTAccessibilityRegistryPath = $global:CursorIndicatorAccessibilityRegistryPath = $global:ControlPanelDesktopRegistryPath = $global:StickyKeysRegistryPath = $global:ToggleKeysRegistryPath = $global:FilterKeysRegistryPath = $env:TestRegistryPath
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $global:PersonalizationRegistryPath = $global:NTAccessibilityRegistryPath = $global:CursorIndicatorAccessibilityRegistryPath = $global:ControlPanelDesktopRegistryPath = $global:StickyKeysRegistryPath = $global:ToggleKeysRegistryPath = $global:FilterKeysRegistryPath = $global:EyeControlRegistryPath = $env:TestRegistryPath
}

[DSCResource()]
Expand Down Expand Up @@ -289,7 +295,7 @@
static hidden [string] $MessageDurationProperty = 'MessageDuration'

static [bool] GetShowDynamicScrollbarsStatus() {
if (-not(DoesRegistryKeyPropertyExist -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty))) {

Check notice on line 298 in resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1

View workflow job for this annotation

GitHub Actions / Check Spelling

`Line` matches candidate pattern `(?:^|[\t ,"'`=(])-[DPWXYLlf](?=[A-Z]{2,}|[A-Z][a-z]|[a-z]{2,})` (candidate-pattern)
return $false
} else {
$dynamicScrollbarsValue = (Get-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty)).DynamicScrollbars
Expand Down Expand Up @@ -891,6 +897,37 @@
}
}

[DscResource()]
class EyeControl {
[DscProperty(Key)] [Ensure] $Ensure
Trenly marked this conversation as resolved.
Show resolved Hide resolved
hidden [string] $SettingsProperty = 'Enabled'

[EyeControl] Get() {
$currentState = [EyeControl]::new()

if (-not(DoesRegistryKeyPropertyExist -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty)) {
$currentState.Ensure = [Ensure]::Absent
} else {
$currentState.Ensure = [int]((Get-ItemPropertyValue -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty) -eq 1)
}

return $currentState
}

[bool] Test() {
return $this.Get().Ensure -eq $this.Ensure
}

[void] Set() {
# Only make changes if changes are needed
if ($this.Test()) { return }
if (-not (DoesRegistryKeyPropertyExist -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty)) {
New-ItemProperty -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty -PropertyType DWord
}
Set-ItemProperty -Path $global:EyeControlRegistryPath -Name $this.SettingsProperty -Value $([int]$this.Ensure)
}
}

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

Describe 'List available DSC resources' {
It 'Shows DSC Resources' {
$expectedDSCResources = 'Text', 'Magnifier', 'MousePointer', 'VisualEffect', 'Audio', 'TextCursor', 'StickyKeys', 'ToggleKeys', 'FilterKeys'
$expectedDSCResources = 'Text', 'Magnifier', 'MousePointer', 'VisualEffect', 'Audio', 'TextCursor', 'StickyKeys', 'ToggleKeys', 'FilterKeys', 'EyeControl'
$availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Setting.Accessibility).Name
$availableDSCResources.length | Should -Be 9
$availableDSCResources.length | Should -Be 10
$availableDSCResources | Where-Object { $expectedDSCResources -notcontains $_ } | Should -BeNullOrEmpty -ErrorAction Stop
}
}
Expand Down Expand Up @@ -401,6 +401,28 @@ Describe 'FilterKeys' {
}
}

Describe 'EyeControl' {
It 'Enable EyeControl.' {
Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property @{ Ensure = 'Absent' }

$initialState = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$initialState.Ensure | Should -Be 'Absent'

# Test enabled
$parameters = @{ Ensure = 'Present' }
$testResult = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters
$testResult.InDesiredState | Should -Be $false

# Set enabled
Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters
$finalState = Invoke-DscResource -Name EyeControl -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{}
$finalState.Ensure | Should -Be 'Present'

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

AfterAll {
$env:TestRegistryPath = ''
}
Loading