|
#requires -Version 5.1 |
|
$ErrorActionPreference = 'Stop' |
|
|
|
# This script needs administrator access because Windhawk's system-wide engine |
|
# and its HKLM mod configuration are used. |
|
$identity = [Security.Principal.WindowsIdentity]::GetCurrent() |
|
$principal = New-Object Security.Principal.WindowsPrincipal($identity) |
|
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { |
|
$args = '-NoProfile -ExecutionPolicy Bypass -File "' + $PSCommandPath + '"' |
|
$p = Start-Process powershell.exe -Verb RunAs -ArgumentList $args -Wait -PassThru |
|
exit $p.ExitCode |
|
} |
|
|
|
$modId = 'taskbar-auto-hide-keyboard-only' |
|
$modBase = "https://mods.windhawk.net/mods/$modId/" |
|
$windhawkRoot = 'C:\Program Files\Windhawk' |
|
$appData = 'C:\ProgramData\Windhawk' |
|
|
|
if (-not (Get-Command winget.exe -ErrorAction SilentlyContinue)) { |
|
throw 'winget is not available. Install App Installer from Microsoft Store first.' |
|
} |
|
|
|
winget install --id RamenSoftware.Windhawk --exact --silent --accept-package-agreements --accept-source-agreements |
|
|
|
$versions = @(Invoke-RestMethod ($modBase + 'versions.json')) |
|
$version = ($versions | Sort-Object timestamp | Select-Object -Last 1).version |
|
if ([string]::IsNullOrWhiteSpace($version)) { throw 'Could not determine the latest mod version.' } |
|
|
|
$tempRoot = Join-Path $env:TEMP $modId |
|
New-Item -ItemType Directory -Force -Path $tempRoot | Out-Null |
|
$tempDll = Join-Path $tempRoot "$modId`_$version`_64.dll" |
|
$tempSource = Join-Path $tempRoot "$modId`_$version.wh.cpp" |
|
Invoke-WebRequest ($modBase + "$version`_64.dll") -OutFile $tempDll -UseBasicParsing |
|
Invoke-WebRequest ($modBase + "$version.wh.cpp") -OutFile $tempSource -UseBasicParsing |
|
|
|
$engineMods64 = Join-Path $appData 'Engine\Mods\64' |
|
$modsSource = Join-Path $appData 'ModsSource' |
|
$statusDir = Join-Path $appData 'Engine\ModsWritable\mod-status' |
|
New-Item -ItemType Directory -Force -Path $engineMods64,$modsSource,$statusDir | Out-Null |
|
|
|
$dllName = "$modId`_$version`_123456.dll" |
|
Copy-Item $tempDll (Join-Path $engineMods64 $dllName) -Force |
|
Copy-Item $tempSource (Join-Path $modsSource "$modId.wh.cpp") -Force |
|
|
|
$modKey = "HKLM:\SOFTWARE\Windhawk\Engine\Mods\$modId" |
|
New-Item -Path $modKey -Force | Out-Null |
|
$config = @{ |
|
LibraryFileName = $dllName |
|
Disabled = 0 |
|
LoggingEnabled = 0 |
|
DebugLoggingEnabled = 0 |
|
Include = 'explorer.exe' |
|
Exclude = '' |
|
Architecture = 'x86-64' |
|
Version = [string]$version |
|
SettingsChangeTime = [int](([DateTimeOffset]::UtcNow.ToUnixTimeSeconds()) -band 0x7fffffff) |
|
} |
|
foreach ($item in $config.GetEnumerator()) { |
|
$type = if ($item.Value -is [int]) { 'DWord' } else { 'String' } |
|
New-ItemProperty -Path $modKey -Name $item.Key -Value $item.Value -PropertyType $type -Force | Out-Null |
|
} |
|
|
|
$settingsKey = Join-Path $modKey 'Settings' |
|
New-Item -Path $settingsKey -Force | Out-Null |
|
$settings = @{ |
|
mode = 'keyboardOnlyFullyHide' |
|
showTemporarilyHotkey = 'Alt+Escape' |
|
toggleAlwaysShowHotkey = 'Alt+`' |
|
toggleAlwaysShowMouseEvent = 'disabled' |
|
showTemporarilyDurationMs = '1000' |
|
winKeyAction = 'showTaskbarOpenStartIfShown' |
|
oldTaskbarOnWin11 = '0' |
|
} |
|
foreach ($item in $settings.GetEnumerator()) { |
|
New-ItemProperty -Path $settingsKey -Name $item.Key -Value $item.Value -PropertyType String -Force | Out-Null |
|
} |
|
|
|
# Enable the native auto-hide prerequisite. |
|
$stuckRects = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects3' |
|
$taskbar = (Get-ItemProperty $stuckRects).Settings |
|
$taskbar[8] = 3 |
|
Set-ItemProperty -Path $stuckRects -Name Settings -Value $taskbar |
|
|
|
& (Join-Path $windhawkRoot 'windhawk.exe') -restart |
|
Start-Sleep -Seconds 4 |
|
|
|
$loaded = Get-Process explorer -ErrorAction SilentlyContinue | ForEach-Object { |
|
$_.Modules | Where-Object { $_.ModuleName -eq $dllName } |
|
} |
|
if (-not $loaded) { Write-Warning 'The mod file was installed, but Explorer has not reported the DLL yet. Sign out and back in once.' } |
|
else { Write-Output "Done: $modId $version is loaded in Explorer." } |