Skip to content

Commit

Permalink
EnableMonoAudio (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengillie authored Sep 10, 2024
1 parent 452ef2a commit dd9fe0f
Show file tree
Hide file tree
Showing 3 changed files with 247 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'Text',
'Magnifier',
'MousePointer',
'VisualEffect'
'VisualEffect',
'Audio'
)
PrivateData = @{
PSData = @{
Expand All @@ -22,7 +23,8 @@
'PSDscResource_Text',
'PSDscResource_Magnifier',
'PSDscResource_MousePointer',
'PSDscResource_VisualEffect'
'PSDscResource_VisualEffect',
'PSDscResource_Audio'
)

# Prerelease string of this module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ if ([string]::IsNullOrEmpty($env:TestRegistryPath)) {
$global:MagnifierRegistryPath = 'HKCU:\Software\Microsoft\ScreenMagnifier\'
$global:PointerRegistryPath = 'HKCU:\Control Panel\Cursors\'
$global:ControlPanelAccessibilityRegistryPath= 'HKCU:\Control Panel\Accessibility\'
$global:AudioRegistryPath = 'HKCU:\Software\Microsoft\Multimedia\Audio\'
}
else {
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $env:TestRegistryPath
$global:AccessibilityRegistryPath = $global:MagnifierRegistryPath = $global:PointerRegistryPath = $global:ControlPanelAccessibilityRegistryPath = $global:AudioRegistryPath = $env:TestRegistryPath
}


Expand Down Expand Up @@ -250,21 +251,25 @@ class VisualEffect
[DscProperty(Key)] [string] $SID
[DscProperty()] [bool] $AlwaysShowScrollbars = $false

hidden [string] $DynamicScrollbarsProperty = 'DynamicScrollbars'
static hidden [string] $DynamicScrollbarsProperty = 'DynamicScrollbars'

[VisualEffect] Get()
static [bool] GetShowDynamicScrollbarsStatus()
{
$currentState = [VisualEffect]::new()

if (-not(DoesRegistryKeyPropertyExist -Path $global:ControlPanelAccessibilityRegistryPath -Name $this.DynamicScrollbarsProperty))
if (-not(DoesRegistryKeyPropertyExist -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty)))
{
$currentState.AlwaysShowScrollbars = $false
return $false
}
else
{
$dynamicScrollbarsValue = (Get-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name $this.DynamicScrollbarsProperty).DynamicScrollbars
$currentState.AlwaysShowScrollbars = ($dynamicScrollbarsValue -eq 0)
}
$dynamicScrollbarsValue = (Get-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty)).DynamicScrollbars
return ($dynamicScrollbarsValue -eq 0)
}
}

[VisualEffect] Get()
{
$currentState = [VisualEffect]::new()
$currentState.AlwaysShowScrollbars = [VisualEffect]::GetShowDynamicScrollbarsStatus()

return $currentState
}
Expand All @@ -289,8 +294,66 @@ class VisualEffect
New-Item -Path $global:ControlPanelAccessibilityRegistryPath -Force | Out-Null
}

$dynamicScrollbarValue = $this.AlwaysShowScrollbars ? 0 : 1
Set-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name $this.DynamicScrollbarsProperty -Value $dynamicScrollbarValue
$dynamicScrollbarValue = if ($this.AlwaysShowScrollbars) { 0 } else { 1 }

Set-ItemProperty -Path $global:ControlPanelAccessibilityRegistryPath -Name ([VisualEffect]::DynamicScrollbarsProperty) -Value $dynamicScrollbarValue
}
}
}

[DSCResource()]
class Audio
{
# Key required. Do not set.
[DscProperty(Key)] [string] $SID
[DscProperty()] [bool] $EnableMonoAudio = $false

static hidden [string] $EnableMonoAudioProperty = 'AccessibilityMonoMixState'

static [bool] GetEnableMonoAudioStatus()
{
if (-not(DoesRegistryKeyPropertyExist -Path $global:AudioRegistryPath -Name ([Audio]::EnableMonoAudioProperty)))
{
return $false
}
else
{
$AudioMonoSetting = (Get-ItemProperty -Path $global:AudioRegistryPath -Name ([Audio]::EnableMonoAudioProperty)).AccessibilityMonoMixState
return ($AudioMonoSetting -eq 0)
}
}

[Audio] Get()
{
$currentState = [Audio]::new()
$currentState.EnableMonoAudio = [Audio]::GetEnableMonoAudioStatus()

return $currentState
}

[bool] Test()
{
$currentState = $this.Get()
if ($this.EnableMonoAudio -ne $currentState.EnableMonoAudio)
{
return $false
}

return $true
}

[void] Set()
{
if (-not $this.Test())
{
if (-not (Test-Path -Path $global:AudioRegistryPath))
{
New-Item -Path $global:AudioRegistryPath -Force | Out-Null
}

$monoAudioValue = if ($this.EnableMonoAudio) { 0 } else { 1 }

Set-ItemProperty -Path $global:AudioRegistryPath -Name ([Audio]::EnableMonoAudioProperty) -Value $monoAudioValue
}
}
}
Expand Down
Loading

0 comments on commit dd9fe0f

Please sign in to comment.