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 27 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 @@ -12,15 +12,17 @@
DscResourcesToExport = @(
'Text',
'Magnifier',
'MousePointer'
'MousePointer',
'AnimationEffects'
)
PrivateData = @{
PSData = @{
# Tags applied to this module. These help with module discovery in online galleries.
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,27 @@ enum PointerSize {
ExtraLarge
}

enum BinarySettingState {
KeepCurrentValue
Enabled
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\'
$global:PointerRegistryPath = 'HKCU:\Control Panel\Cursors\'
$global:AnimationEffectsRegistryPath = 'HKCU:\Control Panel\Desktop\'
}
else {
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $env:TestRegistryPath
Expand Down Expand Up @@ -231,6 +248,83 @@ 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)] [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)] [AnimationEffects] $currentState

[AnimationEffects] Get() {
$this.currentState = [AnimationEffects]::new()

$this.currentState = "Disabled"
stephengillie marked this conversation as resolved.
Show resolved Hide resolved

foreach ($enum in [AnimationEffectsSettings].GetEnumNames()) {
$thisState = Get-AnimationState $enum
if ($thisState -eq [BinarySettingState]::Enabled) {
$this.currentState = "Enabled"
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
}
}

return $this.currentState
}

[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) {
stephengillie marked this conversation as resolved.
Show resolved Hide resolved

return $false
}

return $true
}

[void] Set() {
if ($this.Test() -eq $false) {
$SmoothScrollListBoxesDesiredValue = switch ([BinarySettingState]($this.SmoothScrollListBoxes)) {
Enabled {1}
Disabled {0}
}
stephengillie marked this conversation as resolved.
Show resolved Hide resolved

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

#region Functions
function DoesRegistryKeyPropertyExist {
param (
Expand All @@ -245,4 +339,57 @@ function DoesRegistryKeyPropertyExist {
$itemProperty = Get-ItemProperty -Path $Path -Name $Name -ErrorAction SilentlyContinue
return $null -ne $itemProperty
}

function Get-CombinedState {
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
param(
[Parameter(Mandatory)]
[BinarySettingState]$SmoothScrollListBoxes,
[BinarySettingState]$SlideOpenComboBoxes,
[BinarySettingState]$FadeOrSlideMenusIntoView,
[BinarySettingState]$ShowShadowsUnderMousePointer,
[BinarySettingState]$FadeOrSlideToolTipsIntoView,
[BinarySettingState]$FadeOutMenuItemsAfterClicking,
[BinarySettingState]$ShowShadowsUnderWindows,
[string] $AnimationEffectsProperty = 'UserPreferencesMask'
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
)

$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
$OverallState = $OverallState | %{[convert]::ToInt32($_,2).ToString("X").PadLeft(2,'0')}#Converts from binary back to hex.
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
using module Microsoft.Windows.Developer
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
$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
stephengillie marked this conversation as resolved.
Show resolved Hide resolved
# 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 = ""
}
Loading