Skip to content

Commit

Permalink
May Update Hotfix 2 (#170)
Browse files Browse the repository at this point in the history
* Removing all the properties changed to **Enable-WindowsSpotlight**
- Fix Remove-ItemPropertyVerified

* Add warning when path was not found using Remove-ItemPropertyVerified

* Fixed `Remove-ItemPropertyVerified` inaccurately reporting success
- The property is now removed correctly, accepting more paths

* Change resolution check to use the primary monitor's working area. (#168)

Fixes oversized windows on multiple monitor setups when using dpi scaling.

* Use Pascal Casing inside Get-CurrentResolution.psm1
- Remove unused variable $bounds

---------

Co-authored-by: Haxy <[email protected]>
  • Loading branch information
LeDragoX and clienthax authored May 28, 2024
1 parent d43f8b7 commit 5fe5fc9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 73 deletions.
80 changes: 43 additions & 37 deletions src/lib/debloat-helper/Remove-ItemPropertyVerified.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,55 @@ function Remove-ItemPropertyVerified() {
}

Process {
If ((Get-Item -Path "$Path").Property -ccontains $Name) {
Write-Status -Types "-", $TweakType -Status "Removing: `"$Path>$Name`""
ForEach ($DirectoryPath in $Path) {
If (Test-Path "$DirectoryPath") {
If ((Get-Item -Path "$DirectoryPath").Property -ccontains $Name) {
Write-Status -Types "-", $TweakType -Status "Removing: `"$DirectoryPath>$Name`""

If ($null -ne $Path) {
$ScriptBlock += " -Path "
ForEach ($PathParam in $Path) {
$ScriptBlock += "`"$PathParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}
If ($null -ne $DirectoryPath) {
$ScriptBlock += " -Path "
$ScriptBlock += "`"$DirectoryPath`", "
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Name) {
$ScriptBlock += " -Name "
ForEach ($NameParam in $Name) {
$ScriptBlock += "`"$NameParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}
If ($null -ne $Name) {
$ScriptBlock += " -Name "
ForEach ($NameParam in $Name) {
$ScriptBlock += "`"$NameParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Include) {
$ScriptBlock += " -Include "
ForEach ($IncludeParam in $Include) {
$ScriptBlock += "`"$IncludeParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}
If ($null -ne $Include) {
$ScriptBlock += " -Include "
ForEach ($IncludeParam in $Include) {
$ScriptBlock += "`"$IncludeParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Exclude) {
$ScriptBlock += " -Exclude "
ForEach ($ExcludeParam in $Exclude) {
$ScriptBlock += "`"$ExcludeParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}
If ($null -ne $Exclude) {
$ScriptBlock += " -Exclude "
ForEach ($ExcludeParam in $Exclude) {
$ScriptBlock += "`"$ExcludeParam`", "
}
$ScriptBlock = $ScriptBlock.TrimEnd(", ")
}

If ($null -ne $Force) {
$ScriptBlock += " -Force"
}
If ($null -ne $Force) {
$ScriptBlock += " -Force"
}

Write-Verbose "> $ScriptBlock"
Invoke-Expression "$ScriptBlock"
} Else {
Write-Status -Types "?", $TweakType -Status "The property `"$Path>$Name`" does not exist." -Warning
Write-Verbose "> $ScriptBlock"
Invoke-Expression "$ScriptBlock"
$ScriptBlock = "Remove-ItemProperty"
} Else {
Write-Status -Types "?", $TweakType -Status "The property `"$DirectoryPath>$Name`" does not exist." -Warning

}
} Else {
Write-Status -Types "?", $TweakType -Status "The path(s) `"$DirectoryPath`" to the property `"$Name`" couldn't be found." -Warning
}
}
}
}
43 changes: 7 additions & 36 deletions src/lib/ui/Get-CurrentResolution.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,16 @@ function Get-CurrentResolution() {
[OutputType([System.Object[]])]
param ()

# Adapted from: https://www.reddit.com/r/PowerShell/comments/67no9x/comment/dgrry3b/?utm_source=share&utm_medium=web2x&context=3
$NumberOfScreens = (Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams | Where-Object { $_.Active -like "True" }).Active.Count
$ScreenWidth = $null
$ScreenHeight = $null
Add-Type -AssemblyName System.Windows.Forms

Write-Verbose "Num. of Monitors: $NumberOfScreens"
# Get the primary screen's working area, which takes DPI scaling into account
$PrimaryScreen = [System.Windows.Forms.Screen]::PrimaryScreen
$WorkingArea = $PrimaryScreen.WorkingArea

If ($NumberOfScreens -eq 1) {
# Accepts Scaling/DPI
[System.Windows.Forms.SystemInformation]::VirtualScreen | ForEach-Object {
Write-Verbose "W: $($_.Width) | H: $($_.Height)"
$ScreenWidth = $WorkingArea.Width
$ScreenHeight = $WorkingArea.Height

If (!$ScreenWidth -or !$ScreenHeight) {
$ScreenWidth = $_.Width
$ScreenHeight = $_.Height
}
Write-Verbose "Primary Monitor: Width: $ScreenWidth, Height: $ScreenHeight (DPI Scaled)"

If (($_.Width) -and ($_.Width -le $ScreenWidth)) {
$ScreenWidth = $_.Width
$ScreenHeight = $_.Height
}
}
} Else {
# Doesn't accepts Scaling/DPI (rollback method)
Get-CimInstance -Class "Win32_VideoController" | ForEach-Object {
Write-Verbose "W: $($_.CurrentHorizontalResolution) | H: $($_.CurrentVerticalResolution)"

If (!$ScreenWidth -or !$ScreenHeight) {
$ScreenWidth = $_.CurrentHorizontalResolution
$ScreenHeight = $_.CurrentVerticalResolution
}

If (($_.CurrentHorizontalResolution) -and ($_.CurrentHorizontalResolution -le $ScreenWidth)) {
$ScreenWidth = $_.CurrentHorizontalResolution
$ScreenHeight = $_.CurrentVerticalResolution
}
}
}

Write-Verbose "Width: $ScreenWidth, Height: $ScreenHeight"
return $ScreenWidth, $ScreenHeight
}

0 comments on commit 5fe5fc9

Please sign in to comment.