Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Animation effects #48

Draft
wants to merge 37 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4df9f30
First commit
stephengillie Jul 23, 2024
6391004
Add Set method.
stephengillie Jul 23, 2024
84374c0
Add Set method
stephengillie Jul 23, 2024
4f52ee0
Add tests
stephengillie Jul 23, 2024
cff0bfd
Update testing variables.
stephengillie Jul 24, 2024
63f0fd7
Merge branch 'main' into AnimationEffects
ryfu-msft Jul 24, 2024
ae87b93
Update "alphabet variables" with better names, and also declarations.
stephengillie Jul 24, 2024
629733a
Revert removing clearspace.
stephengillie Jul 24, 2024
3a83f55
Revert tab remvoal.
stephengillie Jul 24, 2024
acf2578
Add AnimationEffects to DscResourcesToExport
stephengillie Jul 24, 2024
e024e9b
Make requested changes to module.
stephengillie Jul 24, 2024
c25637b
Fix bug in helper function
stephengillie Jul 24, 2024
f583f0d
Fix errors when importing.
stephengillie Jul 25, 2024
4a5b8e1
Revert clearspace changes.
stephengillie Jul 25, 2024
3c5b748
Missed one
stephengillie Jul 25, 2024
2d95e2e
Completing Get logic.
stephengillie Jul 25, 2024
76e6693
Fix cast and spread out If statements.
stephengillie Jul 25, 2024
ce66d55
Add tests
stephengillie Jul 25, 2024
67fac23
Remove AnimationEffectsState as requested
stephengillie Jul 29, 2024
67ff10f
Add missing comma.
stephengillie Jul 29, 2024
c7a499a
Unclobber some line breaks.
stephengillie Jul 29, 2024
0cf4736
Unclobber more lines
stephengillie Jul 29, 2024
42613aa
Unclobber more lines
stephengillie Jul 29, 2024
1e3ae98
Unclobber more lines
stephengillie Jul 29, 2024
9d66502
Unclobber more lines
stephengillie Jul 29, 2024
52ae6e6
Move tests to correct file.
stephengillie Jul 29, 2024
58ffd7b
Refactor complex section into simpler function, and remove unnecessar…
stephengillie Aug 1, 2024
dbbed18
Update resources/Microsoft.Windows.Setting.Accessibility/Microsoft.Wi…
stephengillie Aug 2, 2024
1d5eaa8
Requested code changes.
stephengillie Aug 2, 2024
7538bb1
Updates from local testing, and refactor a function.
stephengillie Aug 2, 2024
2aeb4c4
"I would just do a bunch of if statements and at the end return true …
stephengillie Aug 2, 2024
3142de1
Update tests.
stephengillie Aug 2, 2024
97ada82
Rename files to singularize nouns.
stephengillie Aug 2, 2024
7629c1f
Merge branch 'microsoft:main' into AnimationEffects
stephengillie Aug 20, 2024
2498dc3
Merge tests into upstream addition.
stephengillie Aug 20, 2024
14cf9d2
Remove unnecessary resource from PSD.
stephengillie Aug 29, 2024
adbedfb
Revert clearspace change.
stephengillie Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
Tags = @(
'PSDscResource_Text',
'PSDscResource_Magnifier',
'PSDscResource_MousePointer'
'PSDscResource_MousePointer',
'PSDscResource_AnimationEffects'
)

# Prerelease string of this module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\'
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
}
else {
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath
Expand Down Expand Up @@ -231,6 +238,93 @@ 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)] [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
stephengillie marked this conversation as resolved.
Show resolved Hide resolved

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

$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
}

[bool] Test() {
$currentState = $this.Get()
if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue -and $this.AnimationEffectsState -ne $currentState.AnimationEffectsState) {
return $false
}

return $true
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
}

[void] Set() {
if ($this.AnimationEffectsState -ne [AnimationEffectsState]::KeepCurrentValue) {
$desiredValue = switch ([AnimationEffectsState]($this.AnimationEffectsState)) {
Enabled {1}
Disabled {0}
}
stephengillie marked this conversation as resolved.
Show resolved Hide resolved

$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[2] = $AnimationState[2][0..4]+$desiredValue+$AnimationState[0][6..7] -join ""
stephengillie marked this conversation as resolved.
Show resolved Hide resolved

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 | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')})
}
}
}

#region Functions
function DoesRegistryKeyPropertyExist {
param (
Expand All @@ -245,4 +339,4 @@ function DoesRegistryKeyPropertyExist {
$itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
return $null -ne $itemProperty
}
#endregion Functions
#endregion Functions
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @{ 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
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
}
}

AfterAll {
$env:TestRegistryPath = ""
}