From 4df9f30d3b4b7a4f0963759f0c0afecf7dc75b59 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:23:33 -0700 Subject: [PATCH 01/35] First commit --- ...crosoft.Windows.Setting.Accessibility.psd1 | 3 +- ...crosoft.Windows.Setting.Accessibility.psm1 | 70 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index 76d9dab9..d0e5c628 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -20,7 +20,8 @@ Tags = @( 'PSDscResource_Text', 'PSDscResource_Magnifier', - 'PSDscResource_MousePointer' + 'PSDscResource_MousePointer', + 'PSDscResource_AnimationEffects' ) # Prerelease string of this module diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 89aa6613..7519c5e3 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -28,10 +28,17 @@ enum PointerSize { ExtraLarge } +enum AnimationEffectsState { + KeepCurrentValue + Enabled + Disabled +} + if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { $global:AccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Accessibility\' $global:MagnifierRegistryPath = 'HKCU:\Software\Microsoft\ScreenMagnifier\' $global:PointerRegistryPath = 'HKCU:\Control Panel\Cursors\' + $global:AnimationEffectsSettingsRegistryPath = 'HKCU:\Control Panel\Desktop\' } else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath @@ -231,6 +238,69 @@ class MousePointer { } } +[DSCResource()] +class AnimationEffects { + [DscProperty(Key)] [AnimationEffectsState] $AnimationEffectsState = [AnimationEffectsState]::KeepCurrentValue + [DscProperty(NotConfigurable)] [string] $AnimationEffectsValue + + hidden [string] $AnimationEffectsProperty = 'UserPreferencesMask' + #These settings are stored alongside other settings in a bitmask. + + [AnimationEffects] Get() { + $currentState = [AnimationEffectsState]::new() + + $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. + + #Decode bitmask string array as char array grid + #1001ABC0 + #00D1EF10 + #00000G11 + + $A = $AnimationState[0][4] #Smooth-scroll list boxes + $B = $AnimationState[0][5] #Slide open combo boxes + $C = $AnimationState[0][6] #Fade or slide menus into view + + $D = $AnimationState[1][2] #Show shadows under mouse pointer + $E = $AnimationState[1][4] #Fade or slide ToolTips into view + $F = $AnimationState[1][5] #Fade out menu items after clicking + + $G = $AnimationState[2][5] #Show shadows under windows + + if ($A -eq 0 -AND $B -eq 0 -AND $C -eq 0 -AND $D -eq 0 -AND $E -eq 0 -AND $F -eq 0 -AND $G -eq 0) { + $currentState = [AnimationEffectsState]::Disabled + } else { + $currentState = [AnimationEffectsState]::Enabled + } + + return $currentState + } + + [bool] Test() { + $currentState = $this.Get() + if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue -and $this.AnimationEffectsState -ne $currentState.AnimationEffectsState) { + return $false + } + + return $true + } + + [void] Set() { + if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue) { + $desiredValue = switch ([AnimationEffectsState]($this.AnimationEffectsState)) { + Enabled {1} + Disabled {0} + } + + $currentState = [AnimationEffects]::Get() + + if (-not (Test-Path -Path $global:AnimationEffectsSettingsRegistryPath)) { + } + + Set-ItemProperty -Path $global:AnimationEffectsSettingsRegistryPath -Name $this.AnimationEffectsProperty -Value $desiredValue + } + } +} + #region Functions function DoesRegistryKeyPropertyExist { param ( From 6391004d20b319d0330ece80cd2bbbd18ebe3d0c Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:33:21 -0700 Subject: [PATCH 02/35] Add Set method. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 7519c5e3..392af4af 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -291,12 +291,27 @@ class AnimationEffects { Disabled {0} } - $currentState = [AnimationEffects]::Get() + $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. + #Decode bitmask string array as char array grid + #1001ABC0 + #00D1EF10 + #00000G11 + + $AnimationState[0][4] = $desiredValue #A + $AnimationState[0][5] = $desiredValue #B + $AnimationState[0][6] = $desiredValue #C + + $AnimationState[1][2] = $desiredValue #D + $AnimationState[1][4] = $desiredValue #E + $AnimationState[1][5] = $desiredValue #F + + $AnimationState[2][5] = $desiredValue #G if (-not (Test-Path -Path $global:AnimationEffectsSettingsRegistryPath)) { + New-Item -Path $global:AnimationEffectsSettingsRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:AnimationEffectsSettingsRegistryPath -Name $this.AnimationEffectsProperty -Value $desiredValue + Set-ItemProperty -Path $global:AnimationEffectsSettingsRegistryPath -Name $this.AnimationEffectsProperty -Value $AnimationState } } } From 84374c046fb09d7d61f8138f100f95fd79004810 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:57:13 -0700 Subject: [PATCH 03/35] Add Set method --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 392af4af..5a2528e8 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -292,26 +292,22 @@ class AnimationEffects { } $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. - #Decode bitmask string array as char array grid + #Recombine string array with desired state variables. #1001ABC0 #00D1EF10 #00000G11 - $AnimationState[0][4] = $desiredValue #A - $AnimationState[0][5] = $desiredValue #B - $AnimationState[0][6] = $desiredValue #C + $AnimationState[0] = $AnimationState[0][0..3]+$desiredValue+$desiredValue+$desiredValue+$AnimationState[0][7] -join "" - $AnimationState[1][2] = $desiredValue #D - $AnimationState[1][4] = $desiredValue #E - $AnimationState[1][5] = $desiredValue #F - - $AnimationState[2][5] = $desiredValue #G + $AnimationState[1] = $AnimationState[1][0..1]+$desiredValue+$AnimationState[1][3]+$desiredValue+$desiredValue+$AnimationState[1][6..7] -join "" + + $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[0][6..7] -join "" if (-not (Test-Path -Path $global:AnimationEffectsSettingsRegistryPath)) { New-Item -Path $global:AnimationEffectsSettingsRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:AnimationEffectsSettingsRegistryPath -Name $this.AnimationEffectsProperty -Value $AnimationState + Set-ItemProperty -Path $global:AnimationEffectsSettingsRegistryPath -Name $this.AnimationEffectsProperty -Value ($AnimationState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}) } } } From 4f52ee03fc710ce1fe4e3105426f0e8b77a3823f Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:08:32 -0700 Subject: [PATCH 04/35] Add tests --- .../Microsoft.Windows.Developer.Tests.ps1 | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 index a827a985..e5ff9541 100644 --- a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 +++ b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 @@ -145,6 +145,34 @@ Describe 'UserAccessControl'{ } } +Describe 'Animation'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ AdminConsentPromptBehavior = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AdminConsentPromptBehavior | Should -Be $initialState.AdminConsentPromptBehavior + } + + It 'Sets desired value.'{ + # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue + $desiredAdminConsentPromptBehavior = [AdminConsentPromptBehavior]("Enabled","Disabled"|Get-Random) + + $desiredState = @{ AdminConsentPromptBehavior = $desiredAdminConsentPromptBehavior } + + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AdminConsentPromptBehavior | Should -Be $desiredAdminConsentPromptBehavior + } +} + AfterAll { $env:TestRegistryPath = "" } \ No newline at end of file From cff0bfdb8f30c7f4a2cec2d1347b0ce9429690d4 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Tue, 23 Jul 2024 20:36:49 -0700 Subject: [PATCH 05/35] Update testing variables. --- .../Microsoft.Windows.Developer.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 index e5ff9541..6817c168 100644 --- a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 +++ b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 @@ -149,7 +149,7 @@ Describe 'Animation'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $parameters = @{ AdminConsentPromptBehavior = 'KeepCurrentValue' } + $parameters = @{ AnimationBehavior = 'KeepCurrentValue' } $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true @@ -157,19 +157,19 @@ Describe 'Animation'{ # Invoking set should not change these values. Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AdminConsentPromptBehavior | Should -Be $initialState.AdminConsentPromptBehavior + $finalState.AnimationBehavior | Should -Be $initialState.AnimationBehavior } It 'Sets desired value.'{ # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue - $desiredAdminConsentPromptBehavior = [AdminConsentPromptBehavior]("Enabled","Disabled"|Get-Random) + $desiredAnimationBehavior = [AnimationBehavior]("Enabled","Disabled"|Get-Random) - $desiredState = @{ AdminConsentPromptBehavior = $desiredAdminConsentPromptBehavior } + $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AdminConsentPromptBehavior | Should -Be $desiredAdminConsentPromptBehavior + $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior } } From ae87b9384603632449349c1eef4bd7dc19ec783b Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:13:30 -0700 Subject: [PATCH 06/35] Update "alphabet variables" with better names, and also declarations. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 87 +++++++------------ 1 file changed, 31 insertions(+), 56 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 5a2528e8..cf74a23b 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -1,9 +1,8 @@ +@@ -1,37 +1,44 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. - $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest - enum TextSize { KeepCurrentValue Small @@ -11,7 +10,6 @@ enum TextSize { Large ExtraLarge } - enum MagnificationValue { KeepCurrentValue None @@ -19,7 +17,6 @@ enum MagnificationValue { Medium High } - enum PointerSize { KeepCurrentValue Normal @@ -43,18 +40,13 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath } - - [DSCResource()] class Text { [DscProperty(Key)] [TextSize] $Size = [TextSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [int] $SizeValue - hidden [string] $TextScaleFactor = 'TextScaleFactor' - [Text] Get() { $currentState = [Text]::new() - if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { $currentState.Size = [TextSize]::Small $currentState.SizeValue = 96 @@ -67,24 +59,19 @@ class Text { 144 { [TextSize]::Large } 256 { [TextSize]::ExtraLarge } } - if ($null -ne $currentSize) { $currentState.Size = $currentSize } } - return $currentState } - [bool] Test() { $currentState = $this.Get() if ($this.Size -ne [TextSize]::KeepCurrentValue -and $this.Size -ne $currentState.Size) { return $false } - return $true } - [void] Set() { if ($this.Size -ne [TextSize]::KeepCurrentValue) { $desiredSize = switch ([TextSize]($this.Size)) { @@ -93,12 +80,10 @@ class Text { Large { 144 } ExtraLarge { 256 } } - Set-ItemProperty -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor -Value $desiredSize -Type DWORD } } } - [DSCResource()] class Magnifier { [DscProperty(Key)] [MagnificationValue] $Magnification = [MagnificationValue]::KeepCurrentValue @@ -106,13 +91,10 @@ class Magnifier { [DscProperty()] [bool] $StartMagnify = $false [DscProperty(NotConfigurable)] [int] $MagnificationLevel [DscProperty(NotConfigurable)] [int] $ZoomIncrementLevel - hidden [string] $MagnificationProperty = 'Magnification' hidden [string] $ZoomIncrementProperty = 'ZoomIncrement' - [Magnifier] Get() { $currentState = [Magnifier]::new() - if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.Magnification)) { $currentState.Magnification = [MagnificationValue]::None $currentState.MagnificationLevel = 0 @@ -129,7 +111,6 @@ class Magnifier { $currentState.Magnification = $currentMagnification } - if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty)) { $currentState.ZoomIncrement = 25 $currentState.ZoomIncrementLevel = 25 @@ -138,10 +119,8 @@ class Magnifier { $currentState.ZoomIncrementLevel = (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement $currentState.ZoomIncrement = $currentState.ZoomIncrementLevel } - return $currentState } - [bool] Test() { $currentState = $this.Get() if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue -and $this.Magnification -ne $currentState.Magnification) { @@ -150,10 +129,8 @@ class Magnifier { if ($this.ZoomIncrement -ne $currentState.ZoomIncrement) { return $false } - return $false } - [void] Set() { if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue) { $desiredMagnification = switch ([MagnificationValue]($this.Magnification)) { @@ -162,31 +139,24 @@ class Magnifier { Medium { 200 } High { 300 } } - if (-not (Test-Path -Path $global:MagnifierRegistryPath)) { New-Item -Path $global:MagnifierRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.MagnificationProperty -Value $desiredMagnification -Type DWORD } - if ($this.ZoomIncrement -ne (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement) { Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty -Value $this.ZoomIncrement -Type DWORD } - if (($this.StartMagnify) -and (($null -eq (Get-Process -Name 'Magnify' -ErrorAction SilentlyContinue)))) { Start-Process "C:\Windows\System32\Magnify.exe" } } } - [DSCResource()] class MousePointer { [DscProperty(Key)] [PointerSize] $PointerSize = [PointerSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [string] $PointerSizeValue - hidden [string] $PointerSizeProperty = 'CursorBaseSize' - [MousePointer] Get() { $currentState = [MousePointer]::new() @@ -206,19 +176,15 @@ class MousePointer { $currentState.PointerSize = $currentSize } - return $currentState } - [bool] Test() { $currentState = $this.Get() if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue -and $this.PointerSize -ne $currentState.PointerSize) { return $false } - return $true } - [void] Set() { if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue) { $desiredSize = switch ([PointerSize]($this.PointerSize)) { @@ -227,11 +193,9 @@ class MousePointer { Large { '144' } ExtraLarge { '256' } } - if (-not (Test-Path -Path $global:PointerRegistryPath)) { New-Item -Path $global:PointerRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty -Value $desiredSize } @@ -240,8 +204,15 @@ class MousePointer { [DSCResource()] class AnimationEffects { + #Need to verify the Animation Effects setting toggle on the Accessibility page changes when these are updated, or find the setting to update that also. [DscProperty(Key)] [AnimationEffectsState] $AnimationEffectsState = [AnimationEffectsState]::KeepCurrentValue - [DscProperty(NotConfigurable)] [string] $AnimationEffectsValue + [DscProperty(NotConfigurable)] [int] $SmoothScrollListBoxes + [DscProperty(NotConfigurable)] [int] $SlideOpenComboBoxes + [DscProperty(NotConfigurable)] [int] $FadeOrSlideMenusIntoView + [DscProperty(NotConfigurable)] [int] $ShowShadowsUnderMousePointer + [DscProperty(NotConfigurable)] [int] $FadeOrSlideToolTipsIntoView + [DscProperty(NotConfigurable)] [int] $FadeOutMenuItemsAfterClicking + [DscProperty(NotConfigurable)] [int] $ShowShadowsUnderWindows hidden [string] $AnimationEffectsProperty = 'UserPreferencesMask' #These settings are stored alongside other settings in a bitmask. @@ -250,28 +221,34 @@ class AnimationEffects { $currentState = [AnimationEffectsState]::new() $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. - + #Decode bitmask string array as char array grid #1001ABC0 #00D1EF10 #00000G11 - $A = $AnimationState[0][4] #Smooth-scroll list boxes - $B = $AnimationState[0][5] #Slide open combo boxes - $C = $AnimationState[0][6] #Fade or slide menus into view - - $D = $AnimationState[1][2] #Show shadows under mouse pointer - $E = $AnimationState[1][4] #Fade or slide ToolTips into view - $F = $AnimationState[1][5] #Fade out menu items after clicking - - $G = $AnimationState[2][5] #Show shadows under windows - - if ($A -eq 0 -AND $B -eq 0 -AND $C -eq 0 -AND $D -eq 0 -AND $E -eq 0 -AND $F -eq 0 -AND $G -eq 0) { + $SmoothScrollListBoxes = $AnimationState[0][4] #A + $SlideOpenComboBoxes = $AnimationState[0][5] #B + $FadeOrSlideMenusIntoView = $AnimationState[0][6] #C + + $ShowShadowsUnderMousePointer = $AnimationState[1][2] #D + $FadeOrSlideToolTipsIntoView = $AnimationState[1][4] #E + $FadeOutMenuItemsAfterClicking = $AnimationState[1][5] #F + + $ShowShadowsUnderWindows = $AnimationState[2][5] #G + + if ($ShowShadowsUnderWindows -eq 0 + -AND $SlideOpenComboBoxes -eq 0 + -AND $FadeOrSlideMenusIntoView -eq 0 + -AND $ShowShadowsUnderMousePointer -eq 0 + -AND $FadeOrSlideToolTipsIntoView -eq 0 + -AND $FadeOutMenuItemsAfterClicking -eq 0 + -AND $ShowShadowsUnderWindows -eq 0) { $currentState = [AnimationEffectsState]::Disabled } else { $currentState = [AnimationEffectsState]::Enabled } - + return $currentState } @@ -290,7 +267,7 @@ class AnimationEffects { Enabled {1} Disabled {0} } - + $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. #Recombine string array with desired state variables. #1001ABC0 @@ -298,7 +275,7 @@ class AnimationEffects { #00000G11 $AnimationState[0] = $AnimationState[0][0..3]+$desiredValue+$desiredValue+$desiredValue+$AnimationState[0][7] -join "" - + $AnimationState[1] = $AnimationState[1][0..1]+$desiredValue+$AnimationState[1][3]+$desiredValue+$desiredValue+$AnimationState[1][6..7] -join "" $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[0][6..7] -join "" @@ -317,13 +294,11 @@ function DoesRegistryKeyPropertyExist { param ( [Parameter(Mandatory)] [string]$Path, - [Parameter(Mandatory)] [string]$Name ) - # Get-ItemProperty will return $null if the registry key property does not exist. $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue return $null -ne $itemProperty } -#endregion Functions \ No newline at end of file +#endregion Functions From 629733a232e65b56040156a384af242727d83378 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:18:20 -0700 Subject: [PATCH 07/35] Revert removing clearspace. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index cf74a23b..4e0ff4e4 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -1,8 +1,9 @@ -@@ -1,37 +1,44 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. + $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest + enum TextSize { KeepCurrentValue Small @@ -10,6 +11,7 @@ enum TextSize { Large ExtraLarge } + enum MagnificationValue { KeepCurrentValue None @@ -17,6 +19,7 @@ enum MagnificationValue { Medium High } + enum PointerSize { KeepCurrentValue Normal @@ -40,13 +43,18 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath } + + [DSCResource()] class Text { [DscProperty(Key)] [TextSize] $Size = [TextSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [int] $SizeValue + hidden [string] $TextScaleFactor = 'TextScaleFactor' + [Text] Get() { $currentState = [Text]::new() + if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { $currentState.Size = [TextSize]::Small $currentState.SizeValue = 96 @@ -59,19 +67,24 @@ class Text { 144 { [TextSize]::Large } 256 { [TextSize]::ExtraLarge } } + if ($null -ne $currentSize) { $currentState.Size = $currentSize } } + return $currentState } + [bool] Test() { $currentState = $this.Get() if ($this.Size -ne [TextSize]::KeepCurrentValue -and $this.Size -ne $currentState.Size) { return $false } + return $true } + [void] Set() { if ($this.Size -ne [TextSize]::KeepCurrentValue) { $desiredSize = switch ([TextSize]($this.Size)) { @@ -80,10 +93,12 @@ class Text { Large { 144 } ExtraLarge { 256 } } + Set-ItemProperty -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor -Value $desiredSize -Type DWORD } } } + [DSCResource()] class Magnifier { [DscProperty(Key)] [MagnificationValue] $Magnification = [MagnificationValue]::KeepCurrentValue @@ -91,10 +106,13 @@ class Magnifier { [DscProperty()] [bool] $StartMagnify = $false [DscProperty(NotConfigurable)] [int] $MagnificationLevel [DscProperty(NotConfigurable)] [int] $ZoomIncrementLevel + hidden [string] $MagnificationProperty = 'Magnification' hidden [string] $ZoomIncrementProperty = 'ZoomIncrement' + [Magnifier] Get() { $currentState = [Magnifier]::new() + if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.Magnification)) { $currentState.Magnification = [MagnificationValue]::None $currentState.MagnificationLevel = 0 @@ -108,9 +126,10 @@ class Magnifier { 300 { [MagnificationValue]::High } default { [MagnificationValue]::KeepCurrentValue } } - + $currentState.Magnification = $currentMagnification } + if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty)) { $currentState.ZoomIncrement = 25 $currentState.ZoomIncrementLevel = 25 @@ -119,8 +138,10 @@ class Magnifier { $currentState.ZoomIncrementLevel = (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement $currentState.ZoomIncrement = $currentState.ZoomIncrementLevel } + return $currentState } + [bool] Test() { $currentState = $this.Get() if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue -and $this.Magnification -ne $currentState.Magnification) { @@ -129,8 +150,10 @@ class Magnifier { if ($this.ZoomIncrement -ne $currentState.ZoomIncrement) { return $false } + return $false } + [void] Set() { if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue) { $desiredMagnification = switch ([MagnificationValue]($this.Magnification)) { @@ -139,27 +162,34 @@ class Magnifier { Medium { 200 } High { 300 } } + if (-not (Test-Path -Path $global:MagnifierRegistryPath)) { New-Item -Path $global:MagnifierRegistryPath -Force | Out-Null } + Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.MagnificationProperty -Value $desiredMagnification -Type DWORD } + if ($this.ZoomIncrement -ne (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement) { Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty -Value $this.ZoomIncrement -Type DWORD } + if (($this.StartMagnify) -and (($null -eq (Get-Process -Name 'Magnify' -ErrorAction SilentlyContinue)))) { Start-Process "C:\Windows\System32\Magnify.exe" } } } + [DSCResource()] class MousePointer { [DscProperty(Key)] [PointerSize] $PointerSize = [PointerSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [string] $PointerSizeValue + hidden [string] $PointerSizeProperty = 'CursorBaseSize' + [MousePointer] Get() { $currentState = [MousePointer]::new() - + if (-not(DoesRegistryKeyPropertyExist -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty)) { $currentState.PointerSize = [PointerSize]::Normal $currentState.PointerSizeValue = '32' @@ -173,18 +203,22 @@ class MousePointer { '256' { [PointerSize]::ExtraLarge } default { [PointerSize]::KeepCurrentValue } } - + $currentState.PointerSize = $currentSize } + return $currentState } + [bool] Test() { $currentState = $this.Get() if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue -and $this.PointerSize -ne $currentState.PointerSize) { return $false } + return $true } + [void] Set() { if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue) { $desiredSize = switch ([PointerSize]($this.PointerSize)) { @@ -193,11 +227,13 @@ class MousePointer { Large { '144' } ExtraLarge { '256' } } + if (-not (Test-Path -Path $global:PointerRegistryPath)) { New-Item -Path $global:PointerRegistryPath -Force | Out-Null } + Set-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty -Value $desiredSize - + } } } @@ -294,9 +330,11 @@ function DoesRegistryKeyPropertyExist { param ( [Parameter(Mandatory)] [string]$Path, + [Parameter(Mandatory)] [string]$Name ) + # Get-ItemProperty will return $null if the registry key property does not exist. $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue return $null -ne $itemProperty From 3a83f5511a540f8f0b2981bee2bd03e463ce606a Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:20:15 -0700 Subject: [PATCH 08/35] Revert tab remvoal. --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 4e0ff4e4..bee529fc 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -126,7 +126,7 @@ class Magnifier { 300 { [MagnificationValue]::High } default { [MagnificationValue]::KeepCurrentValue } } - + $currentState.Magnification = $currentMagnification } @@ -189,7 +189,7 @@ class MousePointer { [MousePointer] Get() { $currentState = [MousePointer]::new() - + if (-not(DoesRegistryKeyPropertyExist -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty)) { $currentState.PointerSize = [PointerSize]::Normal $currentState.PointerSizeValue = '32' @@ -203,7 +203,7 @@ class MousePointer { '256' { [PointerSize]::ExtraLarge } default { [PointerSize]::KeepCurrentValue } } - + $currentState.PointerSize = $currentSize } @@ -233,7 +233,7 @@ class MousePointer { } Set-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty -Value $desiredSize - + } } } From acf25787c08d55ccc8548255e005fb253cade92d Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:09:32 -0700 Subject: [PATCH 09/35] Add AnimationEffects to DscResourcesToExport --- .../Microsoft.Windows.Setting.Accessibility.psd1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index d0e5c628..2dca3fa9 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -12,7 +12,8 @@ DscResourcesToExport = @( 'Text', 'Magnifier', - 'MousePointer' + 'MousePointer', + 'AnimationEffects' ) PrivateData = @{ PSData = @{ @@ -20,12 +21,12 @@ Tags = @( 'PSDscResource_Text', 'PSDscResource_Magnifier', - 'PSDscResource_MousePointer', + 'PSDscResource_MousePointer' 'PSDscResource_AnimationEffects' ) - + # Prerelease string of this module Prerelease = 'alpha' } } -} +} \ No newline at end of file From e024e9b31e86d76ccd1f00170cad17678e8b2c15 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:10:31 -0700 Subject: [PATCH 10/35] Make requested changes to module. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 146 ++++++++++++------ 1 file changed, 101 insertions(+), 45 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index bee529fc..ea061c6f 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -34,11 +34,17 @@ enum AnimationEffectsState { Disabled } +enum BinarySettingState { + KeepCurrentValue + Enabled + Disabled +} + if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { $global:AccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Accessibility\' $global:MagnifierRegistryPath = 'HKCU:\Software\Microsoft\ScreenMagnifier\' $global:PointerRegistryPath = 'HKCU:\Control Panel\Cursors\' - $global:AnimationEffectsSettingsRegistryPath = 'HKCU:\Control Panel\Desktop\' + $global:AnimationEffectsRegistryPath = 'HKCU:\Control Panel\Desktop\' } else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath @@ -242,44 +248,70 @@ class MousePointer { class AnimationEffects { #Need to verify the Animation Effects setting toggle on the Accessibility page changes when these are updated, or find the setting to update that also. [DscProperty(Key)] [AnimationEffectsState] $AnimationEffectsState = [AnimationEffectsState]::KeepCurrentValue - [DscProperty(NotConfigurable)] [int] $SmoothScrollListBoxes - [DscProperty(NotConfigurable)] [int] $SlideOpenComboBoxes - [DscProperty(NotConfigurable)] [int] $FadeOrSlideMenusIntoView - [DscProperty(NotConfigurable)] [int] $ShowShadowsUnderMousePointer - [DscProperty(NotConfigurable)] [int] $FadeOrSlideToolTipsIntoView - [DscProperty(NotConfigurable)] [int] $FadeOutMenuItemsAfterClicking - [DscProperty(NotConfigurable)] [int] $ShowShadowsUnderWindows + [DscProperty()] [BinarySettingState] $SmoothScrollListBoxes = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $SlideOpenComboBoxes = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $FadeOrSlideMenusIntoView = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $ShowShadowsUnderMousePointer = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $FadeOrSlideToolTipsIntoView = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $FadeOutMenuItemsAfterClicking = [BinarySettingState]::KeepCurrentValue + [DscProperty()] [BinarySettingState] $ShowShadowsUnderWindows = [BinarySettingState]::KeepCurrentValue hidden [string] $AnimationEffectsProperty = 'UserPreferencesMask' - #These settings are stored alongside other settings in a bitmask. [AnimationEffects] Get() { $currentState = [AnimationEffectsState]::new() - $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. + $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} + + If ($AnimationState[0][4] -eq 0) { + $SmoothScrollListBoxes = [BinarySettingState]::Disabled + } else { + $SmoothScrollListBoxes = [BinarySettingState]::Enabled + } + + If ($AnimationState[0][5] -eq 0) { + $SlideOpenComboBoxes = [BinarySettingState]::Disabled + } else { + $SlideOpenComboBoxes = [BinarySettingState]::Enabled + } + + If ($AnimationState[0][6] -eq 0) { + $FadeOrSlideMenusIntoView = [BinarySettingState]::Disabled + } else { + $FadeOrSlideMenusIntoView = [BinarySettingState]::Enabled + } - #Decode bitmask string array as char array grid - #1001ABC0 - #00D1EF10 - #00000G11 + If ($AnimationState[1][2] -eq 0) { + $ShowShadowsUnderMousePointer = [BinarySettingState]::Disabled + } else { + $ShowShadowsUnderMousePointer = [BinarySettingState]::Enabled + } - $SmoothScrollListBoxes = $AnimationState[0][4] #A - $SlideOpenComboBoxes = $AnimationState[0][5] #B - $FadeOrSlideMenusIntoView = $AnimationState[0][6] #C + If ($AnimationState[1][4] -eq 0) { + $FadeOrSlideToolTipsIntoView = [BinarySettingState]::Disabled + } else { + $FadeOrSlideToolTipsIntoView = [BinarySettingState]::Enabled + } - $ShowShadowsUnderMousePointer = $AnimationState[1][2] #D - $FadeOrSlideToolTipsIntoView = $AnimationState[1][4] #E - $FadeOutMenuItemsAfterClicking = $AnimationState[1][5] #F + If ($AnimationState[1][5] -eq 0) {#A + $FadeOutMenuItemsAfterClicking = [BinarySettingState]::Disabled + } else { + $FadeOutMenuItemsAfterClicking = [BinarySettingState]::Enabled + } - $ShowShadowsUnderWindows = $AnimationState[2][5] #G + If ($AnimationState[2][5] -eq 0) {#A + $ShowShadowsUnderWindows = [BinarySettingState]::Disabled + } else { + $ShowShadowsUnderWindows = [BinarySettingState]::Enabled + } - if ($ShowShadowsUnderWindows -eq 0 - -AND $SlideOpenComboBoxes -eq 0 - -AND $FadeOrSlideMenusIntoView -eq 0 - -AND $ShowShadowsUnderMousePointer -eq 0 - -AND $FadeOrSlideToolTipsIntoView -eq 0 - -AND $FadeOutMenuItemsAfterClicking -eq 0 - -AND $ShowShadowsUnderWindows -eq 0) { + if ($SmoothScrollListBoxes -eq [BinarySettingState]::Disabled + -AND $SlideOpenComboBoxes -eq [BinarySettingState]::Disabled + -AND $FadeOrSlideMenusIntoView -eq [BinarySettingState]::Disabled + -AND $ShowShadowsUnderMousePointer -eq [BinarySettingState]::Disabled + -AND $FadeOrSlideToolTipsIntoView -eq [BinarySettingState]::Disabled + -AND $FadeOutMenuItemsAfterClicking -eq [BinarySettingState]::Disabled + -AND $ShowShadowsUnderWindows -eq [BinarySettingState]::Disabled) { $currentState = [AnimationEffectsState]::Disabled } else { $currentState = [AnimationEffectsState]::Enabled @@ -289,8 +321,24 @@ class AnimationEffects { } [bool] Test() { - $currentState = $this.Get() - if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue -and $this.AnimationEffectsState -ne $currentState.AnimationEffectsState) { + if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue + -and $this.SmoothScrollListBoxes -ne $currentState.SmoothScrollListBoxes + -and $this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue + -and $this.SlideOpenComboBoxes -ne $currentState.SlideOpenComboBoxes + -and $this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue + -and $this.FadeOrSlideMenusIntoView -ne $currentState.FadeOrSlideMenusIntoView + -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue + -and $this.ShowShadowsUnderMousePointer -ne $currentState.ShowShadowsUnderMousePointer + -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue + -and $this.ShowShadowsUnderMousePointer -ne $currentState.ShowShadowsUnderMousePointer + -and $this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue + -and $this.FadeOrSlideToolTipsIntoView -ne $currentState.FadeOrSlideToolTipsIntoView + -and $this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue + -and $this.FadeOutMenuItemsAfterClicking -ne $currentState.FadeOutMenuItemsAfterClicking + -and $this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue + -and $this.ShowShadowsUnderWindows -ne $currentState.ShowShadowsUnderWindows) { + -and $this.ShowShadowsUnderWindows -ne $currentState.ShowShadowsUnderWindows) { + return $false } @@ -298,29 +346,20 @@ class AnimationEffects { } [void] Set() { - if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue) { + if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue + -and $this.Test() -eq $false) { $desiredValue = switch ([AnimationEffectsState]($this.AnimationEffectsState)) { Enabled {1} Disabled {0} } - $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsSettingsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} #Get-ItemPropertyValue converts hex to int, so need to complete converting to binary. - #Recombine string array with desired state variables. - #1001ABC0 - #00D1EF10 - #00000G11 - - $AnimationState[0] = $AnimationState[0][0..3]+$desiredValue+$desiredValue+$desiredValue+$AnimationState[0][7] -join "" - - $AnimationState[1] = $AnimationState[1][0..1]+$desiredValue+$AnimationState[1][3]+$desiredValue+$desiredValue+$AnimationState[1][6..7] -join "" + $AnimationState = Get-AnimiationState - $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[0][6..7] -join "" - - if (-not (Test-Path -Path $global:AnimationEffectsSettingsRegistryPath)) { - New-Item -Path $global:AnimationEffectsSettingsRegistryPath -Force | Out-Null + if (-not (Test-Path -Path $global:AnimationEffectsRegistryPath)) { + New-Item -Path $global:AnimationEffectsRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:AnimationEffectsSettingsRegistryPath -Name $this.AnimationEffectsProperty -Value ($AnimationState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}) + Set-ItemProperty -Path $global:AnimationEffectsRegistryPath -Name $this.AnimationEffectsProperty -Value ($AnimationState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}) } } } @@ -339,4 +378,21 @@ function DoesRegistryKeyPropertyExist { $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue return $null -ne $itemProperty } + +function Get-AnimiationState { + param( + [Parameter(Mandatory)] + [int]$desiredValue + ) + + $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} + + $AnimationState[0] = $AnimationState[0][0..3]+$desiredValue+$desiredValue+$desiredValue+$AnimationState[0][7] -join "" + + $AnimationState[1] = $AnimationState[1][0..1]+$desiredValue+$AnimationState[1][3]+$desiredValue+$desiredValue+$AnimationState[1][6..7] -join "" + + $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[0][6..7] -join "" + return $AnimationState +} + #endregion Functions From c25637bd9685741e496628828beabd2155156846 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:14:49 -0700 Subject: [PATCH 11/35] Fix bug in helper function --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index ea061c6f..ffcb6934 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -391,7 +391,7 @@ function Get-AnimiationState { $AnimationState[1] = $AnimationState[1][0..1]+$desiredValue+$AnimationState[1][3]+$desiredValue+$desiredValue+$AnimationState[1][6..7] -join "" - $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[0][6..7] -join "" + $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[2][6..7] -join "" return $AnimationState } From f583f0de792402d4db0261f825e2badecd60e98d Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:31:30 -0700 Subject: [PATCH 12/35] Fix errors when importing. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 95 +++++++------------ 1 file changed, 35 insertions(+), 60 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index ffcb6934..e3b4e4c4 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -255,89 +255,62 @@ class AnimationEffects { [DscProperty()] [BinarySettingState] $FadeOrSlideToolTipsIntoView = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $FadeOutMenuItemsAfterClicking = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $ShowShadowsUnderWindows = [BinarySettingState]::KeepCurrentValue - - hidden [string] $AnimationEffectsProperty = 'UserPreferencesMask' + [DscProperty(NotConfigurable)] [int] $AnimationState + [DscProperty(NotConfigurable)] [AnimationEffects] $currentState [AnimationEffects] Get() { - $currentState = [AnimationEffectsState]::new() + $this.currentState = [AnimationEffectsState]::new() - $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} + $this.AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name 'UserPreferencesMask') | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} - If ($AnimationState[0][4] -eq 0) { - $SmoothScrollListBoxes = [BinarySettingState]::Disabled + If ($this.AnimationState[0][4] -eq 0) { + $this.SmoothScrollListBoxes = [BinarySettingState]::Disabled } else { - $SmoothScrollListBoxes = [BinarySettingState]::Enabled + $this.SmoothScrollListBoxes = [BinarySettingState]::Enabled } - If ($AnimationState[0][5] -eq 0) { - $SlideOpenComboBoxes = [BinarySettingState]::Disabled + If ($this.AnimationState[0][5] -eq 0) { + $this.SlideOpenComboBoxes = [BinarySettingState]::Disabled } else { - $SlideOpenComboBoxes = [BinarySettingState]::Enabled + $this.SlideOpenComboBoxes = [BinarySettingState]::Enabled } - If ($AnimationState[0][6] -eq 0) { - $FadeOrSlideMenusIntoView = [BinarySettingState]::Disabled + If ($this.AnimationState[0][6] -eq 0) { + $this.FadeOrSlideMenusIntoView = [BinarySettingState]::Disabled } else { - $FadeOrSlideMenusIntoView = [BinarySettingState]::Enabled + $this.FadeOrSlideMenusIntoView = [BinarySettingState]::Enabled } - If ($AnimationState[1][2] -eq 0) { - $ShowShadowsUnderMousePointer = [BinarySettingState]::Disabled + If ($this.AnimationState[1][2] -eq 0) { + $this.ShowShadowsUnderMousePointer = [BinarySettingState]::Disabled } else { - $ShowShadowsUnderMousePointer = [BinarySettingState]::Enabled + $this.ShowShadowsUnderMousePointer = [BinarySettingState]::Enabled } - If ($AnimationState[1][4] -eq 0) { - $FadeOrSlideToolTipsIntoView = [BinarySettingState]::Disabled + If ($this.AnimationState[1][4] -eq 0) { + $this.FadeOrSlideToolTipsIntoView = [BinarySettingState]::Disabled } else { - $FadeOrSlideToolTipsIntoView = [BinarySettingState]::Enabled + $this.FadeOrSlideToolTipsIntoView = [BinarySettingState]::Enabled } - If ($AnimationState[1][5] -eq 0) {#A - $FadeOutMenuItemsAfterClicking = [BinarySettingState]::Disabled + If ($this.AnimationState[1][5] -eq 0) { + $this.FadeOutMenuItemsAfterClicking = [BinarySettingState]::Disabled } else { - $FadeOutMenuItemsAfterClicking = [BinarySettingState]::Enabled + $this.FadeOutMenuItemsAfterClicking = [BinarySettingState]::Enabled } - If ($AnimationState[2][5] -eq 0) {#A - $ShowShadowsUnderWindows = [BinarySettingState]::Disabled + If ($this.AnimationState[2][5] -eq 0) { + $this.ShowShadowsUnderWindows = [BinarySettingState]::Disabled } else { - $ShowShadowsUnderWindows = [BinarySettingState]::Enabled + $this.ShowShadowsUnderWindows = [BinarySettingState]::Enabled } - if ($SmoothScrollListBoxes -eq [BinarySettingState]::Disabled - -AND $SlideOpenComboBoxes -eq [BinarySettingState]::Disabled - -AND $FadeOrSlideMenusIntoView -eq [BinarySettingState]::Disabled - -AND $ShowShadowsUnderMousePointer -eq [BinarySettingState]::Disabled - -AND $FadeOrSlideToolTipsIntoView -eq [BinarySettingState]::Disabled - -AND $FadeOutMenuItemsAfterClicking -eq [BinarySettingState]::Disabled - -AND $ShowShadowsUnderWindows -eq [BinarySettingState]::Disabled) { - $currentState = [AnimationEffectsState]::Disabled - } else { - $currentState = [AnimationEffectsState]::Enabled - } - - return $currentState + return $this.currentState } [bool] Test() { - if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue - -and $this.SmoothScrollListBoxes -ne $currentState.SmoothScrollListBoxes - -and $this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue - -and $this.SlideOpenComboBoxes -ne $currentState.SlideOpenComboBoxes - -and $this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue - -and $this.FadeOrSlideMenusIntoView -ne $currentState.FadeOrSlideMenusIntoView - -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue - -and $this.ShowShadowsUnderMousePointer -ne $currentState.ShowShadowsUnderMousePointer - -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue - -and $this.ShowShadowsUnderMousePointer -ne $currentState.ShowShadowsUnderMousePointer - -and $this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue - -and $this.FadeOrSlideToolTipsIntoView -ne $currentState.FadeOrSlideToolTipsIntoView - -and $this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue - -and $this.FadeOutMenuItemsAfterClicking -ne $currentState.FadeOutMenuItemsAfterClicking - -and $this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue - -and $this.ShowShadowsUnderWindows -ne $currentState.ShowShadowsUnderWindows) { - -and $this.ShowShadowsUnderWindows -ne $currentState.ShowShadowsUnderWindows) { + $this.currentState = $this.Get() + if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -and $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes -and $this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -and $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes -and $this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -and $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and $this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -and $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView -and $this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -and $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking -and $this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -and $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { return $false } @@ -346,20 +319,19 @@ class AnimationEffects { } [void] Set() { - if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue - -and $this.Test() -eq $false) { + if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue -and $this.Test() -eq $false) { $desiredValue = switch ([AnimationEffectsState]($this.AnimationEffectsState)) { Enabled {1} Disabled {0} } - $AnimationState = Get-AnimiationState + $this.AnimationState = Get-AnimiationState if (-not (Test-Path -Path $global:AnimationEffectsRegistryPath)) { New-Item -Path $global:AnimationEffectsRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:AnimationEffectsRegistryPath -Name $this.AnimationEffectsProperty -Value ($AnimationState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}) + Set-ItemProperty -Path $global:AnimationEffectsRegistryPath -Name $this.AnimationEffectsProperty -Value ($this.AnimationState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}) } } } @@ -382,7 +354,10 @@ function DoesRegistryKeyPropertyExist { function Get-AnimiationState { param( [Parameter(Mandatory)] - [int]$desiredValue + [int]$desiredValue, + + #Looking for a better way to handle this. + [string] $AnimationEffectsProperty = 'UserPreferencesMask' ) $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} From 4a5b8e13d1252c9882f6a8aede1d717bc6117c87 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:34:19 -0700 Subject: [PATCH 13/35] Revert clearspace changes. --- .../Microsoft.Windows.Setting.Accessibility.psd1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index 2dca3fa9..3ee10c6b 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -13,7 +13,7 @@ 'Text', 'Magnifier', 'MousePointer', - 'AnimationEffects' + 'AnimationEffects' ) PrivateData = @{ PSData = @{ @@ -29,4 +29,4 @@ Prerelease = 'alpha' } } -} \ No newline at end of file +} From 3c5b748f220e2cc061cd5d4fb2a9c43d8b30c44b Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:34:45 -0700 Subject: [PATCH 14/35] Missed one --- .../Microsoft.Windows.Setting.Accessibility.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index 3ee10c6b..a6d79a02 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -24,7 +24,7 @@ 'PSDscResource_MousePointer' 'PSDscResource_AnimationEffects' ) - + # Prerelease string of this module Prerelease = 'alpha' } From 2d95e2ed6263d2f6714cd28b75dcd07687d4be45 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:18:54 -0700 Subject: [PATCH 15/35] Completing Get logic. --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index e3b4e4c4..7aff5052 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -304,6 +304,18 @@ class AnimationEffects { } else { $this.ShowShadowsUnderWindows = [BinarySettingState]::Enabled } + + if ($this.SmoothScrollListBoxes -eq [BinarySettingState]::Disabled -and + $this.SlideOpenComboBoxes -eq [BinarySettingState]::Disabled -and + $this.FadeOrSlideMenusIntoView -eq [BinarySettingState]::Disabled -and + $this.ShowShadowsUnderMousePointer -eq [BinarySettingState]::Disabled -and + $this.FadeOrSlideToolTipsIntoView -eq [BinarySettingState]::Disabled -and + $this.FadeOutMenuItemsAfterClicking -eq [BinarySettingState]::Disabled -and + $this.ShowShadowsUnderWindows -eq [BinarySettingState]::Disabled ) { + $this.currentState = [AnimationEffectsState]::Disabled + } else { + $this.currentState = [AnimationEffectsState]::Disabled + } return $this.currentState } From 76e6693d0b1d851136cb2be6b9dbaef3730a54f3 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:47:33 -0700 Subject: [PATCH 16/35] Fix cast and spread out If statements. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 7aff5052..0d9f8445 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -259,7 +259,7 @@ class AnimationEffects { [DscProperty(NotConfigurable)] [AnimationEffects] $currentState [AnimationEffects] Get() { - $this.currentState = [AnimationEffectsState]::new() + $this.currentState = [AnimationEffects]::new() $this.AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name 'UserPreferencesMask') | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} @@ -322,7 +322,22 @@ class AnimationEffects { [bool] Test() { $this.currentState = $this.Get() - if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -and $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes -and $this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -and $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes -and $this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -and $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and $this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -and $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView -and $this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -and $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking -and $this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -and $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { + if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -and + $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes -and + $this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -and + $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes -and + $this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -and + $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView -and + $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and + $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and + $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and + $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and + $this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -and + $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView -and + $this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -and + $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking -and + $this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -and + $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { return $false } From ce66d55348478610e8b91e81e1cee963fc31fb4f Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Thu, 25 Jul 2024 13:15:27 -0700 Subject: [PATCH 17/35] Add tests --- .../Microsoft.Windows.Developer.Tests.ps1 | 36 ++++++------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 index 6817c168..55637285 100644 --- a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 +++ b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 @@ -1,25 +1,20 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. using module Microsoft.Windows.Developer - $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest - <# .Synopsis Pester tests related to the Microsoft.WinGet.Developer PowerShell module. #> - BeforeAll { Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck Import-Module Microsoft.Windows.Developer - # Create test registry path. New-Item -Path TestRegistry:\ -Name TestKey # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") } - Describe 'List available DSC resources'{ It 'Shows DSC Resources'{ $expectedDSCResources = "DeveloperMode", "OsVersion", "ShowSecondsInClock", "EnableDarkMode", "Taskbar", "UserAccessControl", "WindowsExplorer" @@ -28,21 +23,17 @@ Describe 'List available DSC resources'{ $availableDSCResources | Where-Object {$expectedDSCResources -notcontains $_} | Should -BeNullOrEmpty -ErrorAction Stop } } - Describe 'Taskbar'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $parameters = @{ Alignment = 'KeepCurrentValue'; HideLabelsMode = 'KeepCurrentValue'; SearchboxMode = 'KeepCurrentValue'; TaskViewButton = 'KeepCurrentValue'; WidgetsButton = 'KeepCurrentValue'} - $testResult = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true - # Invoking set should not change these values. Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters $finalState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} @@ -51,7 +42,6 @@ Describe 'Taskbar'{ $finalState.SearchboxMode | Should -Be $initialState.SearchboxMode $finalState.TaskViewButton | Should -Be $initialState.WidgetsButton } - It 'Sets desired value' { # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue $desiredAlignment = [Alignment](Get-Random -Maximum 3 -Minimum 1) @@ -59,7 +49,6 @@ Describe 'Taskbar'{ $desiredSearchboxMode = [SearchBoxMode](Get-Random -Maximum 5 -Minimum 1) $desiredTaskViewButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) $desiredWidgetsButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredState = @{ Alignment = $desiredAlignment; HideLabelsMode = $desiredHideLabelsMode; SearchboxMode = $desiredSearchboxMode; @@ -76,16 +65,13 @@ Describe 'Taskbar'{ $finalState.WidgetsButton | Should -Be $desiredWidgetsButton } } - Describe 'WindowsExplorer'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $parameters = @{ FileExtensions = 'KeepCurrentValue'; HiddenFiles = 'KeepCurrentValue'; ItemCheckBoxes = 'KeepCurrentValue' } - $testResult = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true @@ -96,13 +82,11 @@ Describe 'WindowsExplorer'{ $finalState.HiddenFiles | Should -Be $initialState.HiddenFiles $finalState.ItemCheckBoxes | Should -Be $initialState.ItemCheckBoxes } - It 'Sets desired value' { # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue $desiredFileExtensions = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) $desiredHiddenFiles = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) $desiredItemCheckBoxes = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredState = @{ FileExtensions = $desiredFileExtensions; HiddenFiles = $desiredHiddenFiles; @@ -116,13 +100,10 @@ Describe 'WindowsExplorer'{ $finalState.ItemCheckBoxes | Should -Be $desiredItemCheckBoxes } } - Describe 'UserAccessControl'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $parameters = @{ AdminConsentPromptBehavior = 'KeepCurrentValue' } - $testResult = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true @@ -131,11 +112,9 @@ Describe 'UserAccessControl'{ $finalState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} $finalState.AdminConsentPromptBehavior | Should -Be $initialState.AdminConsentPromptBehavior } - It 'Sets desired value.'{ # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue $desiredAdminConsentPromptBehavior = [AdminConsentPromptBehavior](Get-Random -Maximum 6 -Minimum 1) - $desiredState = @{ AdminConsentPromptBehavior = $desiredAdminConsentPromptBehavior } Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState @@ -144,7 +123,6 @@ Describe 'UserAccessControl'{ $finalState.AdminConsentPromptBehavior | Should -Be $desiredAdminConsentPromptBehavior } } - Describe 'Animation'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} @@ -153,7 +131,7 @@ Describe 'Animation'{ $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true - + # Invoking set should not change these values. Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} @@ -165,11 +143,19 @@ Describe 'Animation'{ $desiredAnimationBehavior = [AnimationBehavior]("Enabled","Disabled"|Get-Random) $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } - + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState - + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior + $finalState.SmoothScrollListBoxes | Should -Be $desiredAnimationBehavior + $finalState.SlideOpenComboBoxes | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideMenusIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderMousePointer | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderWindows | Should -Be $desiredAnimationBehavior + } } From 67fac23e349b9a7e53154f62eccb1bedcd2567cc Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:14:20 -0700 Subject: [PATCH 18/35] Remove AnimationEffectsState as requested --- ...crosoft.Windows.Setting.Accessibility.psm1 | 68 +++---------------- 1 file changed, 11 insertions(+), 57 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 0d9f8445..79f2b8ee 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -1,9 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. - $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest - enum TextSize { KeepCurrentValue Small @@ -11,7 +9,6 @@ enum TextSize { Large ExtraLarge } - enum MagnificationValue { KeepCurrentValue None @@ -19,7 +16,6 @@ enum MagnificationValue { Medium High } - enum PointerSize { KeepCurrentValue Normal @@ -28,12 +24,6 @@ enum PointerSize { ExtraLarge } -enum AnimationEffectsState { - KeepCurrentValue - Enabled - Disabled -} - enum BinarySettingState { KeepCurrentValue Enabled @@ -49,18 +39,13 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath } - - [DSCResource()] class Text { [DscProperty(Key)] [TextSize] $Size = [TextSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [int] $SizeValue - hidden [string] $TextScaleFactor = 'TextScaleFactor' - [Text] Get() { $currentState = [Text]::new() - if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { $currentState.Size = [TextSize]::Small $currentState.SizeValue = 96 @@ -73,24 +58,19 @@ class Text { 144 { [TextSize]::Large } 256 { [TextSize]::ExtraLarge } } - if ($null -ne $currentSize) { $currentState.Size = $currentSize } } - return $currentState } - [bool] Test() { $currentState = $this.Get() if ($this.Size -ne [TextSize]::KeepCurrentValue -and $this.Size -ne $currentState.Size) { return $false } - return $true } - [void] Set() { if ($this.Size -ne [TextSize]::KeepCurrentValue) { $desiredSize = switch ([TextSize]($this.Size)) { @@ -99,12 +79,10 @@ class Text { Large { 144 } ExtraLarge { 256 } } - Set-ItemProperty -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor -Value $desiredSize -Type DWORD } } } - [DSCResource()] class Magnifier { [DscProperty(Key)] [MagnificationValue] $Magnification = [MagnificationValue]::KeepCurrentValue @@ -112,13 +90,10 @@ class Magnifier { [DscProperty()] [bool] $StartMagnify = $false [DscProperty(NotConfigurable)] [int] $MagnificationLevel [DscProperty(NotConfigurable)] [int] $ZoomIncrementLevel - hidden [string] $MagnificationProperty = 'Magnification' hidden [string] $ZoomIncrementProperty = 'ZoomIncrement' - [Magnifier] Get() { $currentState = [Magnifier]::new() - if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.Magnification)) { $currentState.Magnification = [MagnificationValue]::None $currentState.MagnificationLevel = 0 @@ -135,7 +110,6 @@ class Magnifier { $currentState.Magnification = $currentMagnification } - if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty)) { $currentState.ZoomIncrement = 25 $currentState.ZoomIncrementLevel = 25 @@ -144,10 +118,8 @@ class Magnifier { $currentState.ZoomIncrementLevel = (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement $currentState.ZoomIncrement = $currentState.ZoomIncrementLevel } - return $currentState } - [bool] Test() { $currentState = $this.Get() if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue -and $this.Magnification -ne $currentState.Magnification) { @@ -156,10 +128,8 @@ class Magnifier { if ($this.ZoomIncrement -ne $currentState.ZoomIncrement) { return $false } - return $false } - [void] Set() { if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue) { $desiredMagnification = switch ([MagnificationValue]($this.Magnification)) { @@ -168,31 +138,24 @@ class Magnifier { Medium { 200 } High { 300 } } - if (-not (Test-Path -Path $global:MagnifierRegistryPath)) { New-Item -Path $global:MagnifierRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.MagnificationProperty -Value $desiredMagnification -Type DWORD } - if ($this.ZoomIncrement -ne (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement) { Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty -Value $this.ZoomIncrement -Type DWORD } - if (($this.StartMagnify) -and (($null -eq (Get-Process -Name 'Magnify' -ErrorAction SilentlyContinue)))) { Start-Process "C:\Windows\System32\Magnify.exe" } } } - [DSCResource()] class MousePointer { [DscProperty(Key)] [PointerSize] $PointerSize = [PointerSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [string] $PointerSizeValue - hidden [string] $PointerSizeProperty = 'CursorBaseSize' - [MousePointer] Get() { $currentState = [MousePointer]::new() @@ -212,19 +175,15 @@ class MousePointer { $currentState.PointerSize = $currentSize } - return $currentState } - [bool] Test() { $currentState = $this.Get() if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue -and $this.PointerSize -ne $currentState.PointerSize) { return $false } - return $true } - [void] Set() { if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue) { $desiredSize = switch ([PointerSize]($this.PointerSize)) { @@ -233,11 +192,9 @@ class MousePointer { Large { '144' } ExtraLarge { '256' } } - if (-not (Test-Path -Path $global:PointerRegistryPath)) { New-Item -Path $global:PointerRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty -Value $desiredSize } @@ -247,22 +204,20 @@ class MousePointer { [DSCResource()] class AnimationEffects { #Need to verify the Animation Effects setting toggle on the Accessibility page changes when these are updated, or find the setting to update that also. - [DscProperty(Key)] [AnimationEffectsState] $AnimationEffectsState = [AnimationEffectsState]::KeepCurrentValue - [DscProperty()] [BinarySettingState] $SmoothScrollListBoxes = [BinarySettingState]::KeepCurrentValue + [DscProperty(Key)] [BinarySettingState] $SmoothScrollListBoxes = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $SlideOpenComboBoxes = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $FadeOrSlideMenusIntoView = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $ShowShadowsUnderMousePointer = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $FadeOrSlideToolTipsIntoView = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $FadeOutMenuItemsAfterClicking = [BinarySettingState]::KeepCurrentValue [DscProperty()] [BinarySettingState] $ShowShadowsUnderWindows = [BinarySettingState]::KeepCurrentValue - [DscProperty(NotConfigurable)] [int] $AnimationState [DscProperty(NotConfigurable)] [AnimationEffects] $currentState [AnimationEffects] Get() { $this.currentState = [AnimationEffects]::new() $this.AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name 'UserPreferencesMask') | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} - + If ($this.AnimationState[0][4] -eq 0) { $this.SmoothScrollListBoxes = [BinarySettingState]::Disabled } else { @@ -304,7 +259,7 @@ class AnimationEffects { } else { $this.ShowShadowsUnderWindows = [BinarySettingState]::Enabled } - + if ($this.SmoothScrollListBoxes -eq [BinarySettingState]::Disabled -and $this.SlideOpenComboBoxes -eq [BinarySettingState]::Disabled -and $this.FadeOrSlideMenusIntoView -eq [BinarySettingState]::Disabled -and @@ -312,9 +267,9 @@ class AnimationEffects { $this.FadeOrSlideToolTipsIntoView -eq [BinarySettingState]::Disabled -and $this.FadeOutMenuItemsAfterClicking -eq [BinarySettingState]::Disabled -and $this.ShowShadowsUnderWindows -eq [BinarySettingState]::Disabled ) { - $this.currentState = [AnimationEffectsState]::Disabled + $this.currentState = [BinarySettingState]::Disabled } else { - $this.currentState = [AnimationEffectsState]::Disabled + $this.currentState = [BinarySettingState]::Enabled } return $this.currentState @@ -346,13 +301,13 @@ class AnimationEffects { } [void] Set() { - if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue -and $this.Test() -eq $false) { - $desiredValue = switch ([AnimationEffectsState]($this.AnimationEffectsState)) { + if ($this.Test() -eq $false) { + $SmoothScrollListBoxesDesiredValue = switch ([BinarySettingState]($this.SmoothScrollListBoxes)) { Enabled {1} Disabled {0} } - $this.AnimationState = Get-AnimiationState + $this.AnimationState = Get-AnimiationState -desiredValue $SmoothScrollListBoxesDesiredValue if (-not (Test-Path -Path $global:AnimationEffectsRegistryPath)) { New-Item -Path $global:AnimationEffectsRegistryPath -Force | Out-Null @@ -368,21 +323,20 @@ function DoesRegistryKeyPropertyExist { param ( [Parameter(Mandatory)] [string]$Path, - [Parameter(Mandatory)] [string]$Name ) - # Get-ItemProperty will return $null if the registry key property does not exist. $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue return $null -ne $itemProperty } +#endregion Functions function Get-AnimiationState { param( [Parameter(Mandatory)] [int]$desiredValue, - + #Looking for a better way to handle this. [string] $AnimationEffectsProperty = 'UserPreferencesMask' ) @@ -397,4 +351,4 @@ function Get-AnimiationState { return $AnimationState } -#endregion Functions +#endregion Functions \ No newline at end of file From 67ff10f5ca7c56d87cd92049753f80955d5578d9 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:15:35 -0700 Subject: [PATCH 19/35] Add missing comma. --- .../Microsoft.Windows.Setting.Accessibility.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index a6d79a02..9737001b 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -21,7 +21,7 @@ Tags = @( 'PSDscResource_Text', 'PSDscResource_Magnifier', - 'PSDscResource_MousePointer' + 'PSDscResource_MousePointer', 'PSDscResource_AnimationEffects' ) From c7a499aeb5df7cb8a40c00871bc1bdb4c2e000e0 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:18:24 -0700 Subject: [PATCH 20/35] Unclobber some line breaks. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 79f2b8ee..5cb67d6a 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -1,7 +1,9 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. + $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest + enum TextSize { KeepCurrentValue Small @@ -9,6 +11,7 @@ enum TextSize { Large ExtraLarge } + enum MagnificationValue { KeepCurrentValue None @@ -16,6 +19,7 @@ enum MagnificationValue { Medium High } + enum PointerSize { KeepCurrentValue Normal @@ -39,14 +43,19 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { else { $global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath } + + [DSCResource()] class Text { [DscProperty(Key)] [TextSize] $Size = [TextSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [int] $SizeValue + hidden [string] $TextScaleFactor = 'TextScaleFactor' - [Text] Get() { + + [Text] Get() { $currentState = [Text]::new() - if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { + + if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { $currentState.Size = [TextSize]::Small $currentState.SizeValue = 96 } @@ -58,19 +67,24 @@ class Text { 144 { [TextSize]::Large } 256 { [TextSize]::ExtraLarge } } + if ($null -ne $currentSize) { $currentState.Size = $currentSize } } + return $currentState } + [bool] Test() { $currentState = $this.Get() if ($this.Size -ne [TextSize]::KeepCurrentValue -and $this.Size -ne $currentState.Size) { return $false } + return $true } + [void] Set() { if ($this.Size -ne [TextSize]::KeepCurrentValue) { $desiredSize = switch ([TextSize]($this.Size)) { @@ -78,11 +92,13 @@ class Text { Medium { 120 } Large { 144 } ExtraLarge { 256 } + } Set-ItemProperty -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor -Value $desiredSize -Type DWORD } } } + [DSCResource()] class Magnifier { [DscProperty(Key)] [MagnificationValue] $Magnification = [MagnificationValue]::KeepCurrentValue @@ -151,6 +167,7 @@ class Magnifier { } } } + [DSCResource()] class MousePointer { [DscProperty(Key)] [PointerSize] $PointerSize = [PointerSize]::KeepCurrentValue From 0cf47369f67df2d9e0ed87cd4eb58682720a2d05 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:20:06 -0700 Subject: [PATCH 21/35] Unclobber more lines --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 5cb67d6a..c5fbc178 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -51,11 +51,11 @@ class Text { [DscProperty(NotConfigurable)] [int] $SizeValue hidden [string] $TextScaleFactor = 'TextScaleFactor' - + [Text] Get() { $currentState = [Text]::new() - if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { + if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { $currentState.Size = [TextSize]::Small $currentState.SizeValue = 96 } @@ -92,8 +92,8 @@ class Text { Medium { 120 } Large { 144 } ExtraLarge { 256 } - } + Set-ItemProperty -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor -Value $desiredSize -Type DWORD } } From 42613aad6458affeac7588a7e9932ad0aa8319c1 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:21:55 -0700 Subject: [PATCH 22/35] Unclobber more lines --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index c5fbc178..12c840e2 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -49,13 +49,13 @@ else { class Text { [DscProperty(Key)] [TextSize] $Size = [TextSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [int] $SizeValue - + hidden [string] $TextScaleFactor = 'TextScaleFactor' - [Text] Get() { + [Text] Get() { $currentState = [Text]::new() - - if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { + + if (-not(DoesRegistryKeyPropertyExist -Path $global:AccessibilityRegistryPath -Name $this.TextScaleFactor)) { $currentState.Size = [TextSize]::Small $currentState.SizeValue = 96 } @@ -106,10 +106,13 @@ class Magnifier { [DscProperty()] [bool] $StartMagnify = $false [DscProperty(NotConfigurable)] [int] $MagnificationLevel [DscProperty(NotConfigurable)] [int] $ZoomIncrementLevel + hidden [string] $MagnificationProperty = 'Magnification' hidden [string] $ZoomIncrementProperty = 'ZoomIncrement' + [Magnifier] Get() { $currentState = [Magnifier]::new() + if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.Magnification)) { $currentState.Magnification = [MagnificationValue]::None $currentState.MagnificationLevel = 0 @@ -126,6 +129,7 @@ class Magnifier { $currentState.Magnification = $currentMagnification } + if (-not(DoesRegistryKeyPropertyExist -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty)) { $currentState.ZoomIncrement = 25 $currentState.ZoomIncrementLevel = 25 @@ -136,6 +140,7 @@ class Magnifier { } return $currentState } + [bool] Test() { $currentState = $this.Get() if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue -and $this.Magnification -ne $currentState.Magnification) { @@ -143,9 +148,11 @@ class Magnifier { } if ($this.ZoomIncrement -ne $currentState.ZoomIncrement) { return $false + } return $false } + [void] Set() { if ($this.Magnification -ne [MagnificationValue]::KeepCurrentValue) { $desiredMagnification = switch ([MagnificationValue]($this.Magnification)) { From 1e3ae9850e780a5eeb6e19382d288bc80d8d8b40 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:24:23 -0700 Subject: [PATCH 23/35] Unclobber more lines --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 12c840e2..0c13e6e8 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -138,6 +138,7 @@ class Magnifier { $currentState.ZoomIncrementLevel = (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement $currentState.ZoomIncrement = $currentState.ZoomIncrementLevel } + return $currentState } @@ -148,8 +149,8 @@ class Magnifier { } if ($this.ZoomIncrement -ne $currentState.ZoomIncrement) { return $false - } + return $false } @@ -161,14 +162,18 @@ class Magnifier { Medium { 200 } High { 300 } } + if (-not (Test-Path -Path $global:MagnifierRegistryPath)) { New-Item -Path $global:MagnifierRegistryPath -Force | Out-Null } + Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.MagnificationProperty -Value $desiredMagnification -Type DWORD } + if ($this.ZoomIncrement -ne (Get-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty).ZoomIncrement) { Set-ItemProperty -Path $global:MagnifierRegistryPath -Name $this.ZoomIncrementProperty -Value $this.ZoomIncrement -Type DWORD } + if (($this.StartMagnify) -and (($null -eq (Get-Process -Name 'Magnify' -ErrorAction SilentlyContinue)))) { Start-Process "C:\Windows\System32\Magnify.exe" } @@ -179,7 +184,9 @@ class Magnifier { class MousePointer { [DscProperty(Key)] [PointerSize] $PointerSize = [PointerSize]::KeepCurrentValue [DscProperty(NotConfigurable)] [string] $PointerSizeValue + hidden [string] $PointerSizeProperty = 'CursorBaseSize' + [MousePointer] Get() { $currentState = [MousePointer]::new() @@ -199,15 +206,19 @@ class MousePointer { $currentState.PointerSize = $currentSize } + return $currentState } + [bool] Test() { $currentState = $this.Get() if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue -and $this.PointerSize -ne $currentState.PointerSize) { return $false } + return $true } + [void] Set() { if ($this.PointerSize -ne [PointerSize]::KeepCurrentValue) { $desiredSize = switch ([PointerSize]($this.PointerSize)) { @@ -216,9 +227,11 @@ class MousePointer { Large { '144' } ExtraLarge { '256' } } + if (-not (Test-Path -Path $global:PointerRegistryPath)) { New-Item -Path $global:PointerRegistryPath -Force | Out-Null } + Set-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty -Value $desiredSize } From 9d66502a648a55fa519d26fc61f5d77c4d9a8514 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:25:07 -0700 Subject: [PATCH 24/35] Unclobber more lines --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 0c13e6e8..30eac53f 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -360,14 +360,15 @@ function DoesRegistryKeyPropertyExist { param ( [Parameter(Mandatory)] [string]$Path, + [Parameter(Mandatory)] [string]$Name ) + # Get-ItemProperty will return $null if the registry key property does not exist. $itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue return $null -ne $itemProperty } -#endregion Functions function Get-AnimiationState { param( From 52ae6e6531ee38c3f479226944612ea1825ecc26 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Mon, 29 Jul 2024 10:30:53 -0700 Subject: [PATCH 25/35] Move tests to correct file. --- .../Microsoft.Windows.Developer.Tests.ps1 | 56 +++--- ...ft.Windows.Settings.Accessiblity.Tests.ps1 | 164 ++++++++++++++++++ 2 files changed, 185 insertions(+), 35 deletions(-) create mode 100644 tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 diff --git a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 index 55637285..a827a985 100644 --- a/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 +++ b/tests/Microsoft.Windows.Developer/Microsoft.Windows.Developer.Tests.ps1 @@ -1,20 +1,25 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. using module Microsoft.Windows.Developer + $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest + <# .Synopsis Pester tests related to the Microsoft.WinGet.Developer PowerShell module. #> + BeforeAll { Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck Import-Module Microsoft.Windows.Developer + # Create test registry path. New-Item -Path TestRegistry:\ -Name TestKey # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") } + Describe 'List available DSC resources'{ It 'Shows DSC Resources'{ $expectedDSCResources = "DeveloperMode", "OsVersion", "ShowSecondsInClock", "EnableDarkMode", "Taskbar", "UserAccessControl", "WindowsExplorer" @@ -23,17 +28,21 @@ Describe 'List available DSC resources'{ $availableDSCResources | Where-Object {$expectedDSCResources -notcontains $_} | Should -BeNullOrEmpty -ErrorAction Stop } } + Describe 'Taskbar'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $parameters = @{ Alignment = 'KeepCurrentValue'; HideLabelsMode = 'KeepCurrentValue'; SearchboxMode = 'KeepCurrentValue'; TaskViewButton = 'KeepCurrentValue'; WidgetsButton = 'KeepCurrentValue'} + $testResult = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true + # Invoking set should not change these values. Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters $finalState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} @@ -42,6 +51,7 @@ Describe 'Taskbar'{ $finalState.SearchboxMode | Should -Be $initialState.SearchboxMode $finalState.TaskViewButton | Should -Be $initialState.WidgetsButton } + It 'Sets desired value' { # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue $desiredAlignment = [Alignment](Get-Random -Maximum 3 -Minimum 1) @@ -49,6 +59,7 @@ Describe 'Taskbar'{ $desiredSearchboxMode = [SearchBoxMode](Get-Random -Maximum 5 -Minimum 1) $desiredTaskViewButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) $desiredWidgetsButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredState = @{ Alignment = $desiredAlignment; HideLabelsMode = $desiredHideLabelsMode; SearchboxMode = $desiredSearchboxMode; @@ -65,13 +76,16 @@ Describe 'Taskbar'{ $finalState.WidgetsButton | Should -Be $desiredWidgetsButton } } + Describe 'WindowsExplorer'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $parameters = @{ FileExtensions = 'KeepCurrentValue'; HiddenFiles = 'KeepCurrentValue'; ItemCheckBoxes = 'KeepCurrentValue' } + $testResult = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true @@ -82,11 +96,13 @@ Describe 'WindowsExplorer'{ $finalState.HiddenFiles | Should -Be $initialState.HiddenFiles $finalState.ItemCheckBoxes | Should -Be $initialState.ItemCheckBoxes } + It 'Sets desired value' { # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue $desiredFileExtensions = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) $desiredHiddenFiles = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) $desiredItemCheckBoxes = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredState = @{ FileExtensions = $desiredFileExtensions; HiddenFiles = $desiredHiddenFiles; @@ -100,10 +116,13 @@ Describe 'WindowsExplorer'{ $finalState.ItemCheckBoxes | Should -Be $desiredItemCheckBoxes } } + Describe 'UserAccessControl'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $parameters = @{ AdminConsentPromptBehavior = 'KeepCurrentValue' } + $testResult = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters $testResult.InDesiredState | Should -Be $true @@ -112,9 +131,11 @@ Describe 'UserAccessControl'{ $finalState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} $finalState.AdminConsentPromptBehavior | Should -Be $initialState.AdminConsentPromptBehavior } + It 'Sets desired value.'{ # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue $desiredAdminConsentPromptBehavior = [AdminConsentPromptBehavior](Get-Random -Maximum 6 -Minimum 1) + $desiredState = @{ AdminConsentPromptBehavior = $desiredAdminConsentPromptBehavior } Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState @@ -123,41 +144,6 @@ Describe 'UserAccessControl'{ $finalState.AdminConsentPromptBehavior | Should -Be $desiredAdminConsentPromptBehavior } } -Describe 'Animation'{ - It 'Keeps current value.'{ - $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - - $parameters = @{ AnimationBehavior = 'KeepCurrentValue' } - - $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AnimationBehavior | Should -Be $initialState.AnimationBehavior - } - - It 'Sets desired value.'{ - # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue - $desiredAnimationBehavior = [AnimationBehavior]("Enabled","Disabled"|Get-Random) - - $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } - - Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior - $finalState.SmoothScrollListBoxes | Should -Be $desiredAnimationBehavior - $finalState.SlideOpenComboBoxes | Should -Be $desiredAnimationBehavior - $finalState.FadeOrSlideMenusIntoView | Should -Be $desiredAnimationBehavior - $finalState.ShowShadowsUnderMousePointer | Should -Be $desiredAnimationBehavior - $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior - $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior - $finalState.ShowShadowsUnderWindows | Should -Be $desiredAnimationBehavior - - } -} AfterAll { $env:TestRegistryPath = "" diff --git a/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 b/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 new file mode 100644 index 00000000..cd8a58dc --- /dev/null +++ b/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 @@ -0,0 +1,164 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +using module Microsoft.Windows.Developer +$ErrorActionPreference = "Stop" +Set-StrictMode -Version Latest +<# +.Synopsis + Pester tests related to the Microsoft.WinGet.Developer PowerShell module. +#> +BeforeAll { + Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck + Import-Module Microsoft.Windows.Developer + # Create test registry path. + New-Item -Path TestRegistry:\ -Name TestKey + # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. + $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") +} +Describe 'List available DSC resources'{ + It 'Shows DSC Resources'{ + $expectedDSCResources = "DeveloperMode", "OsVersion", "ShowSecondsInClock", "EnableDarkMode", "Taskbar", "UserAccessControl", "WindowsExplorer" + $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Developer).Name + $availableDSCResources.length | Should -Be 7 + $availableDSCResources | Where-Object {$expectedDSCResources -notcontains $_} | Should -BeNullOrEmpty -ErrorAction Stop + } +} +Describe 'Taskbar'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $parameters = @{ + Alignment = 'KeepCurrentValue'; + HideLabelsMode = 'KeepCurrentValue'; + SearchboxMode = 'KeepCurrentValue'; + TaskViewButton = 'KeepCurrentValue'; + WidgetsButton = 'KeepCurrentValue'} + $testResult = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + # Invoking set should not change these values. + Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $finalState.Alignment | Should -Be $initialState.Alignment + $finalState.HideLabelsMode | Should -Be $initialState.HideLabelsMode + $finalState.SearchboxMode | Should -Be $initialState.SearchboxMode + $finalState.TaskViewButton | Should -Be $initialState.WidgetsButton + } + It 'Sets desired value' { + # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue + $desiredAlignment = [Alignment](Get-Random -Maximum 3 -Minimum 1) + $desiredHideLabelsMode = [HideTaskBarLabelsBehavior](Get-Random -Maximum 4 -Minimum 1) + $desiredSearchboxMode = [SearchBoxMode](Get-Random -Maximum 5 -Minimum 1) + $desiredTaskViewButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredWidgetsButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredState = @{ Alignment = $desiredAlignment; + HideLabelsMode = $desiredHideLabelsMode; + SearchboxMode = $desiredSearchboxMode; + TaskViewButton = $desiredTaskViewButton; + WidgetsButton = $desiredWidgetsButton} + + Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $finalState.Alignment | Should -Be $desiredAlignment + $finalState.HideLabelsMode | Should -Be $desiredHideLabelsMode + $finalState.SearchboxMode | Should -Be $desiredSearchboxMode + $finalState.TaskViewButton | Should -Be $desiredTaskViewButton + $finalState.WidgetsButton | Should -Be $desiredWidgetsButton + } +} +Describe 'WindowsExplorer'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $parameters = @{ + FileExtensions = 'KeepCurrentValue'; + HiddenFiles = 'KeepCurrentValue'; + ItemCheckBoxes = 'KeepCurrentValue' } + $testResult = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $finalState.FileExtensions | Should -Be $initialState.FileExtensions + $finalState.HiddenFiles | Should -Be $initialState.HiddenFiles + $finalState.ItemCheckBoxes | Should -Be $initialState.ItemCheckBoxes + } + It 'Sets desired value' { + # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue + $desiredFileExtensions = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredHiddenFiles = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredItemCheckBoxes = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) + $desiredState = @{ + FileExtensions = $desiredFileExtensions; + HiddenFiles = $desiredHiddenFiles; + ItemCheckBoxes = $desiredItemCheckBoxes} + + Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $finalState.FileExtensions | Should -Be $desiredFileExtensions + $finalState.HiddenFiles | Should -Be $desiredHiddenFiles + $finalState.ItemCheckBoxes | Should -Be $desiredItemCheckBoxes + } +} +Describe 'UserAccessControl'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $parameters = @{ AdminConsentPromptBehavior = 'KeepCurrentValue' } + $testResult = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $finalState.AdminConsentPromptBehavior | Should -Be $initialState.AdminConsentPromptBehavior + } + It 'Sets desired value.'{ + # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue + $desiredAdminConsentPromptBehavior = [AdminConsentPromptBehavior](Get-Random -Maximum 6 -Minimum 1) + $desiredState = @{ AdminConsentPromptBehavior = $desiredAdminConsentPromptBehavior } + + Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} + $finalState.AdminConsentPromptBehavior | Should -Be $desiredAdminConsentPromptBehavior + } +} +Describe 'Animation'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ AnimationBehavior = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AnimationBehavior | Should -Be $initialState.AnimationBehavior + } + + It 'Sets desired value.'{ + # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue + $desiredAnimationBehavior = [AnimationBehavior](Get-Random -Maximum 2 -Minimum 1) + + $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } + + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior + $finalState.SmoothScrollListBoxes | Should -Be $desiredAnimationBehavior + $finalState.SlideOpenComboBoxes | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideMenusIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderMousePointer | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderWindows | Should -Be $desiredAnimationBehavior + + } +} + +AfterAll { + $env:TestRegistryPath = "" +} \ No newline at end of file From 58ffd7b5c9402ab4e13de13f70802ccc808f0e03 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:07:34 -0700 Subject: [PATCH 26/35] Refactor complex section into simpler function, and remove unnecessary variables. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 131 +++++++++--------- 1 file changed, 67 insertions(+), 64 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 30eac53f..744def49 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -34,6 +34,16 @@ enum BinarySettingState { Disabled } +enum AnimationEffectsSettings { + SmoothScrollListBoxes + SlideOpenComboBoxes + FadeOrSlideMenusIntoView + ShowShadowsUnderMousePointer + FadeOrSlideToolTipsIntoView + FadeOutMenuItemsAfterClicking + ShowShadowsUnderWindows +} + if ([string]::IsNullOrEmpty($env:TestRegistryPath)) { $global:AccessibilityRegistryPath = 'HKCU:\Software\Microsoft\Accessibility\' $global:MagnifierRegistryPath = 'HKCU:\Software\Microsoft\ScreenMagnifier\' @@ -253,60 +263,13 @@ class AnimationEffects { [AnimationEffects] Get() { $this.currentState = [AnimationEffects]::new() - $this.AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name 'UserPreferencesMask') | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} - - If ($this.AnimationState[0][4] -eq 0) { - $this.SmoothScrollListBoxes = [BinarySettingState]::Disabled - } else { - $this.SmoothScrollListBoxes = [BinarySettingState]::Enabled - } - - If ($this.AnimationState[0][5] -eq 0) { - $this.SlideOpenComboBoxes = [BinarySettingState]::Disabled - } else { - $this.SlideOpenComboBoxes = [BinarySettingState]::Enabled - } - - If ($this.AnimationState[0][6] -eq 0) { - $this.FadeOrSlideMenusIntoView = [BinarySettingState]::Disabled - } else { - $this.FadeOrSlideMenusIntoView = [BinarySettingState]::Enabled - } - - If ($this.AnimationState[1][2] -eq 0) { - $this.ShowShadowsUnderMousePointer = [BinarySettingState]::Disabled - } else { - $this.ShowShadowsUnderMousePointer = [BinarySettingState]::Enabled - } - - If ($this.AnimationState[1][4] -eq 0) { - $this.FadeOrSlideToolTipsIntoView = [BinarySettingState]::Disabled - } else { - $this.FadeOrSlideToolTipsIntoView = [BinarySettingState]::Enabled - } - - If ($this.AnimationState[1][5] -eq 0) { - $this.FadeOutMenuItemsAfterClicking = [BinarySettingState]::Disabled - } else { - $this.FadeOutMenuItemsAfterClicking = [BinarySettingState]::Enabled - } + $this.currentState = "Disabled" - If ($this.AnimationState[2][5] -eq 0) { - $this.ShowShadowsUnderWindows = [BinarySettingState]::Disabled - } else { - $this.ShowShadowsUnderWindows = [BinarySettingState]::Enabled - } - - if ($this.SmoothScrollListBoxes -eq [BinarySettingState]::Disabled -and - $this.SlideOpenComboBoxes -eq [BinarySettingState]::Disabled -and - $this.FadeOrSlideMenusIntoView -eq [BinarySettingState]::Disabled -and - $this.ShowShadowsUnderMousePointer -eq [BinarySettingState]::Disabled -and - $this.FadeOrSlideToolTipsIntoView -eq [BinarySettingState]::Disabled -and - $this.FadeOutMenuItemsAfterClicking -eq [BinarySettingState]::Disabled -and - $this.ShowShadowsUnderWindows -eq [BinarySettingState]::Disabled ) { - $this.currentState = [BinarySettingState]::Disabled - } else { - $this.currentState = [BinarySettingState]::Enabled + foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { + $thisState = Get-AnimationState $enum + if ($thisState -eq [BinarySettingState]::Enabled) { + $this.currentState = "Enabled" + } } return $this.currentState @@ -344,13 +307,20 @@ class AnimationEffects { Disabled {0} } - $this.AnimationState = Get-AnimiationState -desiredValue $SmoothScrollListBoxesDesiredValue + $this.currentState = Get-CombinedState ` + -SmoothScrollListBoxesDesiredValue $SmoothScrollListBoxes ` + -SlideOpenComboBoxesDesiredValue $SlideOpenComboBoxes ` + -FadeOrSlideMenusIntoViewDesiredValue $FadeOrSlideMenusIntoView ` + -ShowShadowsUnderMousePointerDesiredValue $ShowShadowsUnderMousePointer ` + -FadeOrSlideToolTipsIntoViewDesiredValue $FadeOrSlideToolTipsIntoView ` + -FadeOutMenuItemsAfterClickingDesiredValue $FadeOutMenuItemsAfterClicking ` + -ShowShadowsUnderWindowsDesiredValue $ShowShadowsUnderWindows if (-not (Test-Path -Path $global:AnimationEffectsRegistryPath)) { New-Item -Path $global:AnimationEffectsRegistryPath -Force | Out-Null } - Set-ItemProperty -Path $global:AnimationEffectsRegistryPath -Name $this.AnimationEffectsProperty -Value ($this.AnimationState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}) + Set-ItemProperty -Path $global:AnimationEffectsRegistryPath -Name $this.AnimationEffectsProperty -Value $this.currentState } } } @@ -370,23 +340,56 @@ function DoesRegistryKeyPropertyExist { return $null -ne $itemProperty } -function Get-AnimiationState { +function Get-CombinedState { param( [Parameter(Mandatory)] - [int]$desiredValue, - - #Looking for a better way to handle this. + [BinarySettingState]$SmoothScrollListBoxes, + [BinarySettingState]$SlideOpenComboBoxes, + [BinarySettingState]$FadeOrSlideMenusIntoView, + [BinarySettingState]$ShowShadowsUnderMousePointer, + [BinarySettingState]$FadeOrSlideToolTipsIntoView, + [BinarySettingState]$FadeOutMenuItemsAfterClicking, + [BinarySettingState]$ShowShadowsUnderWindows, [string] $AnimationEffectsProperty = 'UserPreferencesMask' ) - $AnimationState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')} + $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. - $AnimationState[0] = $AnimationState[0][0..3]+$desiredValue+$desiredValue+$desiredValue+$AnimationState[0][7] -join "" + $OverallState[0] = $OverallState[0][0..3]+$SmoothScrollListBoxes+$SlideOpenComboBoxes+$FadeOrSlideMenusIntoView+$OverallState[0][7] -join "" -replace "Enabled",1 -replace "Disabled",0 - $AnimationState[1] = $AnimationState[1][0..1]+$desiredValue+$AnimationState[1][3]+$desiredValue+$desiredValue+$AnimationState[1][6..7] -join "" + $OverallState[1] = $OverallState[1][0..1]+$ShowShadowsUnderMousePointer+$OverallState[1][3]+$FadeOrSlideToolTipsIntoView+$FadeOutMenuItemsAfterClicking+$OverallState[1][6..7] -join "" -replace "Enabled",1 -replace "Disabled",0 - $AnimationState[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[2][6..7] -join "" - return $AnimationState + $OverallState[2] = $OverallState[2][0..4]+$ShowShadowsUnderWindows+$OverallState[2][6..7] -join "" -replace "Enabled",1 -replace "Disabled",0 + $OverallState = $OverallState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}#Converts from binary back to hex. + return $OverallState } + +Function Get-AnimationState { + param( + [Parameter(Mandatory)] + [AnimationEffectsSettings]$enum, + [string] $AnimationEffectsProperty = 'UserPreferencesMask' + ) + + $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. + + $IndividualState = switch ([AnimationEffectsSettings]$enum) { + SmoothScrollListBoxes {$OverallState[0][4]} + SlideOpenComboBoxes {$OverallState[0][5]} + FadeOrSlideMenusIntoView {$OverallState[0][6]} + ShowShadowsUnderMousePointer {$OverallState[1][2]} + FadeOrSlideToolTipsIntoView {$OverallState[1][4]} + FadeOutMenuItemsAfterClicking {$OverallState[1][5]} + ShowShadowsUnderWindows {$OverallState[2][5]} + } + + if ($IndividualState -eq [BinarySettingState]::Disabled) { + $currentState = [BinarySettingState]::Disabled + } else { + $currentState = [BinarySettingState]::Enabled + } + + return $currentState +} #endregion Functions \ No newline at end of file From dbbed18e95ff44f68676ce204b64fd8c341bac69 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:45:46 -0700 Subject: [PATCH 27/35] Update resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 Co-authored-by: Ryan <69221034+ryfu-msft@users.noreply.github.com> --- .../Microsoft.Windows.Setting.Accessibility.psm1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 744def49..64e4143d 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -263,7 +263,8 @@ class AnimationEffects { [AnimationEffects] Get() { $this.currentState = [AnimationEffects]::new() - $this.currentState = "Disabled" + $this.currentState = [BinarySettingState]::Disabled + foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { $thisState = Get-AnimationState $enum From 1d5eaa8d6ecc6083804e9fc17c7838b1896b2685 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:03:54 -0700 Subject: [PATCH 28/35] Requested code changes. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 89 +++++++++++++------ 1 file changed, 63 insertions(+), 26 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 64e4143d..fed50e87 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -265,11 +265,10 @@ class AnimationEffects { $this.currentState = [BinarySettingState]::Disabled - foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { $thisState = Get-AnimationState $enum if ($thisState -eq [BinarySettingState]::Enabled) { - $this.currentState = "Enabled" + $this.currentState = [BinarySettingState]::Enabled } } @@ -278,27 +277,56 @@ class AnimationEffects { [bool] Test() { $this.currentState = $this.Get() - if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -and - $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes -and - $this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -and - $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes -and - $this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -and - $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView -and - $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and - $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and - $this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -and - $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer -and - $this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -and - $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView -and - $this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -and - $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking -and - $this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -and - $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { + if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -or + $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes) { + + return $false + } + + else if ($this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -or + $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes) { + + return $false + } + + else if ($this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -or + $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView) { + + return $false + } + + else if ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or + $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + + return $false + } + + else if ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or + $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { return $false } + + else if ($this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -or + $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView) { + + return $false + } + + else if ($this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -or + $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking) { + + return $false + } + + else if ($this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -or + $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { + return $false + } else { + return $true + } } [void] Set() { @@ -308,7 +336,7 @@ class AnimationEffects { Disabled {0} } - $this.currentState = Get-CombinedState ` + $this.currentState = GetAnimationEffectsStateHexValue ` -SmoothScrollListBoxesDesiredValue $SmoothScrollListBoxes ` -SlideOpenComboBoxesDesiredValue $SlideOpenComboBoxes ` -FadeOrSlideMenusIntoViewDesiredValue $FadeOrSlideMenusIntoView ` @@ -327,6 +355,8 @@ class AnimationEffects { } #region Functions +[string] $AnimationEffectsProperty = 'UserPreferencesMask' + function DoesRegistryKeyPropertyExist { param ( [Parameter(Mandatory)] @@ -341,7 +371,7 @@ function DoesRegistryKeyPropertyExist { return $null -ne $itemProperty } -function Get-CombinedState { +function GetAnimationEffectsStateHexValue { param( [Parameter(Mandatory)] [BinarySettingState]$SmoothScrollListBoxes, @@ -351,16 +381,24 @@ function Get-CombinedState { [BinarySettingState]$FadeOrSlideToolTipsIntoView, [BinarySettingState]$FadeOutMenuItemsAfterClicking, [BinarySettingState]$ShowShadowsUnderWindows, - [string] $AnimationEffectsProperty = 'UserPreferencesMask' ) $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. - $OverallState[0] = $OverallState[0][0..3]+$SmoothScrollListBoxes+$SlideOpenComboBoxes+$FadeOrSlideMenusIntoView+$OverallState[0][7] -join "" -replace "Enabled",1 -replace "Disabled",0 - $OverallState[1] = $OverallState[1][0..1]+$ShowShadowsUnderMousePointer+$OverallState[1][3]+$FadeOrSlideToolTipsIntoView+$FadeOutMenuItemsAfterClicking+$OverallState[1][6..7] -join "" -replace "Enabled",1 -replace "Disabled",0 - - $OverallState[2] = $OverallState[2][0..4]+$ShowShadowsUnderWindows+$OverallState[2][6..7] -join "" -replace "Enabled",1 -replace "Disabled",0 + foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { + switch ([AnimationEffectsSettings]$enum) { + SmoothScrollListBoxes {$OverallState[0][4] = $SmoothScrollListBoxes} + SlideOpenComboBoxes {$OverallState[0][5] = $SlideOpenComboBoxes} + FadeOrSlideMenusIntoView {$OverallState[0][6] = $FadeOrSlideMenusIntoView} + ShowShadowsUnderMousePointer {$OverallState[1][2] = $ShowShadowsUnderMousePointer} + FadeOrSlideToolTipsIntoView {$OverallState[1][4] = $FadeOrSlideToolTipsIntoView} + FadeOutMenuItemsAfterClicking {$OverallState[1][5] = $FadeOutMenuItemsAfterClicking} + ShowShadowsUnderWindows {$OverallState[2][5] = $ShowShadowsUnderWindows} + } + } + + $OverallState = $OverallState -replace "Enabled",1 -replace "Disabled",0 $OverallState = $OverallState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}#Converts from binary back to hex. return $OverallState } @@ -370,7 +408,6 @@ Function Get-AnimationState { param( [Parameter(Mandatory)] [AnimationEffectsSettings]$enum, - [string] $AnimationEffectsProperty = 'UserPreferencesMask' ) $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. From 7538bb1d416b4ecdf66dabad678b59f8c0370098 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:42:06 -0700 Subject: [PATCH 29/35] Updates from local testing, and refactor a function. --- ...crosoft.Windows.Setting.Accessibility.psm1 | 109 +++++++++++------- 1 file changed, 65 insertions(+), 44 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index fed50e87..378a4fc0 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -207,7 +207,7 @@ class MousePointer { else { $currentState.PointerSizeValue = (Get-ItemProperty -Path $global:PointerRegistryPath -Name $this.PointerSizeProperty).CursorBaseSize $currentSize = switch ($currentState.PointerSizeValue) { - '32' { [PointerSize]::Normal } + '32' { [PointerSize]::Normal } '96' { [PointerSize]::Medium } '144' { [PointerSize]::Large } '256' { [PointerSize]::ExtraLarge } @@ -276,74 +276,69 @@ class AnimationEffects { } [bool] Test() { - $this.currentState = $this.Get() + $this.currentState = $this.Get() if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -or $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes) { return $false } - else if ($this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -or $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes) { return $false } - else if ($this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -or $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView) { return $false } - else if ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { return $false } - else if ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { return $false } - else if ($this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -or $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView) { return $false } - else if ($this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -or $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking) { return $false } - else if ($this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -or + elseif ($this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -or $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { return $false - } else { - + }else { + return $true } } [void] Set() { if ($this.Test() -eq $false) { - $SmoothScrollListBoxesDesiredValue = switch ([BinarySettingState]($this.SmoothScrollListBoxes)) { - Enabled {1} - Disabled {0} - } - $this.currentState = GetAnimationEffectsStateHexValue ` - -SmoothScrollListBoxesDesiredValue $SmoothScrollListBoxes ` - -SlideOpenComboBoxesDesiredValue $SlideOpenComboBoxes ` - -FadeOrSlideMenusIntoViewDesiredValue $FadeOrSlideMenusIntoView ` - -ShowShadowsUnderMousePointerDesiredValue $ShowShadowsUnderMousePointer ` - -FadeOrSlideToolTipsIntoViewDesiredValue $FadeOrSlideToolTipsIntoView ` - -FadeOutMenuItemsAfterClickingDesiredValue $FadeOutMenuItemsAfterClicking ` - -ShowShadowsUnderWindowsDesiredValue $ShowShadowsUnderWindows + $this.currentState = GetAnimationEffectsStateHexValue # -SmoothScrollListBoxesDesiredValue $SmoothScrollListBoxes + # -SlideOpenComboBoxesDesiredValue $SlideOpenComboBoxes ` + # -FadeOrSlideMenusIntoViewDesiredValue $FadeOrSlideMenusIntoView ` + # -ShowShadowsUnderMousePointerDesiredValue $ShowShadowsUnderMousePointer ` + # -FadeOrSlideToolTipsIntoViewDesiredValue $FadeOrSlideToolTipsIntoView ` + # -FadeOutMenuItemsAfterClickingDesiredValue $FadeOutMenuItemsAfterClicking ` + # -ShowShadowsUnderWindowsDesiredValue $ShowShadowsUnderWindows if (-not (Test-Path -Path $global:AnimationEffectsRegistryPath)) { New-Item -Path $global:AnimationEffectsRegistryPath -Force | Out-Null @@ -374,40 +369,66 @@ function DoesRegistryKeyPropertyExist { function GetAnimationEffectsStateHexValue { param( [Parameter(Mandatory)] - [BinarySettingState]$SmoothScrollListBoxes, - [BinarySettingState]$SlideOpenComboBoxes, - [BinarySettingState]$FadeOrSlideMenusIntoView, - [BinarySettingState]$ShowShadowsUnderMousePointer, - [BinarySettingState]$FadeOrSlideToolTipsIntoView, - [BinarySettingState]$FadeOutMenuItemsAfterClicking, - [BinarySettingState]$ShowShadowsUnderWindows, + [BinarySettingState]$SmoothScrollListBoxesDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$SlideOpenComboBoxesDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$FadeOrSlideMenusIntoViewDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$ShowShadowsUnderMousePointerDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$FadeOrSlideToolTipsIntoViewDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$FadeOutMenuItemsAfterClickingDesiredValue, + + [Parameter(Mandatory)] + [BinarySettingState]$ShowShadowsUnderWindowsDesiredValue ) - $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. + [array]$OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) { + $StateValue = switch ([AnimationEffectsSettings]$enum) { + SmoothScrollListBoxes {$OverallState[0][4]} + SlideOpenComboBoxes {$OverallState[0][5]} + FadeOrSlideMenusIntoView {$OverallState[0][6]} + ShowShadowsUnderMousePointer {$OverallState[1][2]} + FadeOrSlideToolTipsIntoView {$OverallState[1][4]} + FadeOutMenuItemsAfterClicking {$OverallState[1][5]} + ShowShadowsUnderWindows {$OverallState[2][5]} + } + if ($StateValue -eq 1) { + $OutputValue = [BinarySettingState]::Enabled + }else { + $OutputValue = [BinarySettingState]::Disabled + } switch ([AnimationEffectsSettings]$enum) { - SmoothScrollListBoxes {$OverallState[0][4] = $SmoothScrollListBoxes} - SlideOpenComboBoxes {$OverallState[0][5] = $SlideOpenComboBoxes} - FadeOrSlideMenusIntoView {$OverallState[0][6] = $FadeOrSlideMenusIntoView} - ShowShadowsUnderMousePointer {$OverallState[1][2] = $ShowShadowsUnderMousePointer} - FadeOrSlideToolTipsIntoView {$OverallState[1][4] = $FadeOrSlideToolTipsIntoView} - FadeOutMenuItemsAfterClicking {$OverallState[1][5] = $FadeOutMenuItemsAfterClicking} - ShowShadowsUnderWindows {$OverallState[2][5] = $ShowShadowsUnderWindows} - } + SmoothScrollListBoxes {$SmoothScrollListBoxesDesiredValue = $OutputValue} + SlideOpenComboBoxes {$SlideOpenComboBoxesDesiredValue = $OutputValue} + FadeOrSlideMenusIntoView {$FadeOrSlideMenusIntoViewDesiredValue = $OutputValue} + ShowShadowsUnderMousePointer {$ShowShadowsUnderMousePointerDesiredValue = $OutputValue} + FadeOrSlideToolTipsIntoView {$FadeOrSlideToolTipsIntoViewDesiredValue = $OutputValue} + FadeOutMenuItemsAfterClicking {$FadeOutMenuItemsAfterClickingDesiredValue = $OutputValue} + ShowShadowsUnderWindows {$ShowShadowsUnderWindowsDesiredValue = $OutputValue} + } } - $OverallState = $OverallState -replace "Enabled",1 -replace "Disabled",0 + $OverallState = $OverallState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}#Converts from binary back to hex. - return $OverallState + return $OverallState } Function Get-AnimationState { param( [Parameter(Mandatory)] - [AnimationEffectsSettings]$enum, + [AnimationEffectsSettings]$enum ) $OverallState = (Get-ItemPropertyValue -Path $global:AnimationEffectsRegistryPath -Name $AnimationEffectsProperty) | %{[System.Convert]::ToString($_,2).PadLeft(8,'0')}#Registry converts from hex to int, so this converts from int to binary. @@ -420,11 +441,11 @@ Function Get-AnimationState { FadeOrSlideToolTipsIntoView {$OverallState[1][4]} FadeOutMenuItemsAfterClicking {$OverallState[1][5]} ShowShadowsUnderWindows {$OverallState[2][5]} - } + } if ($IndividualState -eq [BinarySettingState]::Disabled) { $currentState = [BinarySettingState]::Disabled - } else { + }else { $currentState = [BinarySettingState]::Enabled } From 2aeb4c4ac37c353f94e7cf1ad662bd1e00714cd5 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:44:33 -0700 Subject: [PATCH 30/35] "I would just do a bunch of if statements and at the end return true if none of the conditions were satisfied." --- ...crosoft.Windows.Setting.Accessibility.psm1 | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 index 378a4fc0..aab3bd3d 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psm1 @@ -277,50 +277,82 @@ class AnimationEffects { [bool] Test() { $this.currentState = $this.Get() - if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue -or - $this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes) { + if ($this.SmoothScrollListBoxes -ne [BinarySettingState]::KeepCurrentValue) { return $false } - elseif ($this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue -or - $this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes) { + elseif ($this.SmoothScrollListBoxes -ne $this.currentState.SmoothScrollListBoxes) { return $false } - elseif ($this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue -or - $this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView) { + elseif ($this.SlideOpenComboBoxes -ne [BinarySettingState]::KeepCurrentValue) { return $false } - elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or - $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + elseif ($this.SlideOpenComboBoxes -ne $this.currentState.SlideOpenComboBoxes) { return $false } - elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue -or - $this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + elseif ($this.FadeOrSlideMenusIntoView -ne [BinarySettingState]::KeepCurrentValue) { return $false } - elseif ($this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue -or - $this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView) { + elseif ($this.FadeOrSlideMenusIntoView -ne $this.currentState.FadeOrSlideMenusIntoView) { return $false } - elseif ($this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue -or - $this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking) { + elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue) { return $false } - elseif ($this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue -or - $this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { + elseif ($this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + + return $false + } + + elseif ($this.ShowShadowsUnderMousePointer -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.ShowShadowsUnderMousePointer -ne $this.currentState.ShowShadowsUnderMousePointer) { + + return $false + } + + elseif ($this.FadeOrSlideToolTipsIntoView -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.FadeOrSlideToolTipsIntoView -ne $this.currentState.FadeOrSlideToolTipsIntoView) { + + return $false + } + + elseif ($this.FadeOutMenuItemsAfterClicking -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.FadeOutMenuItemsAfterClicking -ne $this.currentState.FadeOutMenuItemsAfterClicking) { + + return $false + } + + elseif ($this.ShowShadowsUnderWindows -ne [BinarySettingState]::KeepCurrentValue) { + + return $false + } + + elseif ($this.ShowShadowsUnderWindows -ne $this.currentState.ShowShadowsUnderWindows) { return $false }else { From 3142de1e681bd70b42f432f96eb47e5e2a50e50c Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:47:22 -0700 Subject: [PATCH 31/35] Update tests. --- ...ft.Windows.Settings.Accessiblity.Tests.ps1 | 112 +----------------- 1 file changed, 2 insertions(+), 110 deletions(-) diff --git a/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 b/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 index cd8a58dc..c01fcf43 100644 --- a/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 +++ b/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 @@ -1,6 +1,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -using module Microsoft.Windows.Developer +using module Microsoft.Windows.Setting.Accessibility $ErrorActionPreference = "Stop" Set-StrictMode -Version Latest <# @@ -9,120 +9,12 @@ Set-StrictMode -Version Latest #> BeforeAll { Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck - Import-Module Microsoft.Windows.Developer + Import-Module Microsoft.Windows.Accessibility # Create test registry path. New-Item -Path TestRegistry:\ -Name TestKey # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") } -Describe 'List available DSC resources'{ - It 'Shows DSC Resources'{ - $expectedDSCResources = "DeveloperMode", "OsVersion", "ShowSecondsInClock", "EnableDarkMode", "Taskbar", "UserAccessControl", "WindowsExplorer" - $availableDSCResources = (Get-DscResource -Module Microsoft.Windows.Developer).Name - $availableDSCResources.length | Should -Be 7 - $availableDSCResources | Where-Object {$expectedDSCResources -notcontains $_} | Should -BeNullOrEmpty -ErrorAction Stop - } -} -Describe 'Taskbar'{ - It 'Keeps current value.'{ - $initialState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $parameters = @{ - Alignment = 'KeepCurrentValue'; - HideLabelsMode = 'KeepCurrentValue'; - SearchboxMode = 'KeepCurrentValue'; - TaskViewButton = 'KeepCurrentValue'; - WidgetsButton = 'KeepCurrentValue'} - $testResult = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - # Invoking set should not change these values. - Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $finalState.Alignment | Should -Be $initialState.Alignment - $finalState.HideLabelsMode | Should -Be $initialState.HideLabelsMode - $finalState.SearchboxMode | Should -Be $initialState.SearchboxMode - $finalState.TaskViewButton | Should -Be $initialState.WidgetsButton - } - It 'Sets desired value' { - # Randomly generate desired state. Minimum is set to 1 to avoid KeepCurrentValue - $desiredAlignment = [Alignment](Get-Random -Maximum 3 -Minimum 1) - $desiredHideLabelsMode = [HideTaskBarLabelsBehavior](Get-Random -Maximum 4 -Minimum 1) - $desiredSearchboxMode = [SearchBoxMode](Get-Random -Maximum 5 -Minimum 1) - $desiredTaskViewButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredWidgetsButton = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredState = @{ Alignment = $desiredAlignment; - HideLabelsMode = $desiredHideLabelsMode; - SearchboxMode = $desiredSearchboxMode; - TaskViewButton = $desiredTaskViewButton; - WidgetsButton = $desiredWidgetsButton} - - Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name Taskbar -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $finalState.Alignment | Should -Be $desiredAlignment - $finalState.HideLabelsMode | Should -Be $desiredHideLabelsMode - $finalState.SearchboxMode | Should -Be $desiredSearchboxMode - $finalState.TaskViewButton | Should -Be $desiredTaskViewButton - $finalState.WidgetsButton | Should -Be $desiredWidgetsButton - } -} -Describe 'WindowsExplorer'{ - It 'Keeps current value.'{ - $initialState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $parameters = @{ - FileExtensions = 'KeepCurrentValue'; - HiddenFiles = 'KeepCurrentValue'; - ItemCheckBoxes = 'KeepCurrentValue' } - $testResult = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $finalState.FileExtensions | Should -Be $initialState.FileExtensions - $finalState.HiddenFiles | Should -Be $initialState.HiddenFiles - $finalState.ItemCheckBoxes | Should -Be $initialState.ItemCheckBoxes - } - It 'Sets desired value' { - # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue - $desiredFileExtensions = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredHiddenFiles = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredItemCheckBoxes = [ShowHideFeature](Get-Random -Maximum 3 -Minimum 1) - $desiredState = @{ - FileExtensions = $desiredFileExtensions; - HiddenFiles = $desiredHiddenFiles; - ItemCheckBoxes = $desiredItemCheckBoxes} - - Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name WindowsExplorer -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $finalState.FileExtensions | Should -Be $desiredFileExtensions - $finalState.HiddenFiles | Should -Be $desiredHiddenFiles - $finalState.ItemCheckBoxes | Should -Be $desiredItemCheckBoxes - } -} -Describe 'UserAccessControl'{ - It 'Keeps current value.'{ - $initialState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $parameters = @{ AdminConsentPromptBehavior = 'KeepCurrentValue' } - $testResult = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $finalState.AdminConsentPromptBehavior | Should -Be $initialState.AdminConsentPromptBehavior - } - It 'Sets desired value.'{ - # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue - $desiredAdminConsentPromptBehavior = [AdminConsentPromptBehavior](Get-Random -Maximum 6 -Minimum 1) - $desiredState = @{ AdminConsentPromptBehavior = $desiredAdminConsentPromptBehavior } - - Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name UserAccessControl -ModuleName Microsoft.Windows.Developer -Method Get -Property @{} - $finalState.AdminConsentPromptBehavior | Should -Be $desiredAdminConsentPromptBehavior - } -} Describe 'Animation'{ It 'Keeps current value.'{ $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} From 97ada826f37b204fc52449a9f08a946abadaee9d Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:51:55 -0700 Subject: [PATCH 32/35] Rename files to singularize nouns. --- .../Microsoft.Windows.Setting.Accessiblity.Tests.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 => Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1} (100%) diff --git a/tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1 similarity index 100% rename from tests/Microsoft.Windows.Settings.Accessiblity/Microsoft.Windows.Settings.Accessiblity.Tests.ps1 rename to tests/Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1 From 2498dc303244ac77c5092176e0bd986a28d5ae54 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:14:32 -0700 Subject: [PATCH 33/35] Merge tests into upstream addition. --- ...ft.Windows.Setting.Accessibility.Tests.ps1 | 36 ++++++++++++ ...oft.Windows.Setting.Accessiblity.Tests.ps1 | 56 ------------------- 2 files changed, 36 insertions(+), 56 deletions(-) delete mode 100644 tests/Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1 diff --git a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 index a99398fd..2d68d910 100644 --- a/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 +++ b/tests/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.Tests.ps1 @@ -114,6 +114,42 @@ Describe 'MousePointer' { } } +Describe 'Animation'{ + It 'Keeps current value.'{ + $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + + $parameters = @{ AnimationBehavior = 'KeepCurrentValue' } + + $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters + $testResult.InDesiredState | Should -Be $true + + # Invoking set should not change these values. + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AnimationBehavior | Should -Be $initialState.AnimationBehavior + } + + It 'Sets desired value.'{ + # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue + $desiredAnimationBehavior = [AnimationBehavior](Get-Random -Maximum 2 -Minimum 1) + + $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } + + Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState + + $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} + $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior + $finalState.SmoothScrollListBoxes | Should -Be $desiredAnimationBehavior + $finalState.SlideOpenComboBoxes | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideMenusIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderMousePointer | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior + $finalState.ShowShadowsUnderWindows | Should -Be $desiredAnimationBehavior + + } +} + AfterAll { $env:TestRegistryPath = "" } \ No newline at end of file diff --git a/tests/Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1 b/tests/Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1 deleted file mode 100644 index c01fcf43..00000000 --- a/tests/Microsoft.Windows.Setting.Accessiblity/Microsoft.Windows.Setting.Accessiblity.Tests.ps1 +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. -using module Microsoft.Windows.Setting.Accessibility -$ErrorActionPreference = "Stop" -Set-StrictMode -Version Latest -<# -.Synopsis - Pester tests related to the Microsoft.WinGet.Developer PowerShell module. -#> -BeforeAll { - Install-Module -Name PSDesiredStateConfiguration -Force -SkipPublisherCheck - Import-Module Microsoft.Windows.Accessibility - # Create test registry path. - New-Item -Path TestRegistry:\ -Name TestKey - # Set-ItemProperty requires the PSDrive to be in the format 'HKCU:'. - $env:TestRegistryPath = ((Get-Item -Path TestRegistry:\).Name).replace("HKEY_CURRENT_USER", "HKCU:") -} -Describe 'Animation'{ - It 'Keeps current value.'{ - $initialState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - - $parameters = @{ AnimationBehavior = 'KeepCurrentValue' } - - $testResult = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Test -Property $parameters - $testResult.InDesiredState | Should -Be $true - - # Invoking set should not change these values. - Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $parameters - $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AnimationBehavior | Should -Be $initialState.AnimationBehavior - } - - It 'Sets desired value.'{ - # Randomly generate desired state. Minimum is set to 1 to avoid using KeepCurrentValue - $desiredAnimationBehavior = [AnimationBehavior](Get-Random -Maximum 2 -Minimum 1) - - $desiredState = @{ AnimationBehavior = $desiredAnimationBehavior } - - Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Set -Property $desiredState - - $finalState = Invoke-DscResource -Name AnimationEffects -ModuleName Microsoft.Windows.Setting.Accessibility -Method Get -Property @{} - $finalState.AnimationBehavior | Should -Be $desiredAnimationBehavior - $finalState.SmoothScrollListBoxes | Should -Be $desiredAnimationBehavior - $finalState.SlideOpenComboBoxes | Should -Be $desiredAnimationBehavior - $finalState.FadeOrSlideMenusIntoView | Should -Be $desiredAnimationBehavior - $finalState.ShowShadowsUnderMousePointer | Should -Be $desiredAnimationBehavior - $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior - $finalState.FadeOrSlideToolTipsIntoView | Should -Be $desiredAnimationBehavior - $finalState.ShowShadowsUnderWindows | Should -Be $desiredAnimationBehavior - - } -} - -AfterAll { - $env:TestRegistryPath = "" -} \ No newline at end of file From 14cf9d220d5fca53470c353b0096b676f91d0ed0 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:15:19 -0700 Subject: [PATCH 34/35] Remove unnecessary resource from PSD. --- .../Microsoft.Windows.Setting.Accessibility.psd1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index 9737001b..93fb4cc8 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -12,8 +12,7 @@ DscResourcesToExport = @( 'Text', 'Magnifier', - 'MousePointer', - 'AnimationEffects' + 'MousePointer' ) PrivateData = @{ PSData = @{ @@ -21,8 +20,7 @@ Tags = @( 'PSDscResource_Text', 'PSDscResource_Magnifier', - 'PSDscResource_MousePointer', - 'PSDscResource_AnimationEffects' + 'PSDscResource_MousePointer' ) # Prerelease string of this module From adbedfb84e96228c205aa267ba30633353cd38d1 Mon Sep 17 00:00:00 2001 From: Stephen Gillie <114952565+stephengillie@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:24:16 -0700 Subject: [PATCH 35/35] Revert clearspace change. --- .../Microsoft.Windows.Setting.Accessibility.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 index 93fb4cc8..76d9dab9 100644 --- a/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 +++ b/resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Windows.Setting.Accessibility.psd1 @@ -20,7 +20,7 @@ Tags = @( 'PSDscResource_Text', 'PSDscResource_Magnifier', - 'PSDscResource_MousePointer' + 'PSDscResource_MousePointer' ) # Prerelease string of this module