Skip to content

Commit 46b469f

Browse files
fix(ci): stabilize Windows tray screenshots (#173)
1 parent 40790a5 commit 46b469f

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

  • .github/actions/configure-windows-tray-screenshots

.github/actions/configure-windows-tray-screenshots/action.yml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,37 @@ runs:
1313
Invoke-WebRequest `
1414
-Uri "https://raw.githubusercontent.com/paulmann/windows-show-all-tray-icons/main/Enable-AllTrayIcons.ps1" `
1515
-OutFile $trayIconScript
16-
& $trayIconScript -Action Enable -Force
17-
echo "::endgroup::"
16+
& $trayIconScript -Action Enable -RestartExplorer -Force
17+
18+
Add-Type @"
19+
using System;
20+
using System.Runtime.InteropServices;
1821
19-
echo "::group::Disable Do Not Disturb"
20-
Add-Type -AssemblyName System.Windows.Forms
21-
Start-Process "ms-settings:notifications"
22-
Start-Sleep -Seconds 2
23-
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
24-
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
25-
[System.Windows.Forms.SendKeys]::SendWait(" ")
22+
public static class WindowsShell {
23+
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
24+
public static extern IntPtr FindWindow(string className, string windowName);
25+
}
26+
"@
27+
$taskbarDeadline = (Get-Date).AddSeconds(15)
28+
do {
29+
$taskbarHandle = [WindowsShell]::FindWindow("Shell_TrayWnd", $null)
30+
if ($taskbarHandle -ne [IntPtr]::Zero) {
31+
break
32+
}
33+
Start-Sleep -Milliseconds 250
34+
} while ((Get-Date) -lt $taskbarDeadline)
35+
if ($taskbarHandle -eq [IntPtr]::Zero) {
36+
throw "Windows taskbar did not become ready after restarting Explorer"
37+
}
2638
echo "::endgroup::"
2739
2840
echo "::group::Minimize all windows"
2941
$shell = New-Object -ComObject Shell.Application
3042
$shell.MinimizeAll()
3143
echo "::endgroup::"
3244
45+
# Avoid opening ms-settings here. On Windows 11 ARM64 hosted runners,
46+
# the first Settings URI can open the privacy OOBE over every screenshot.
3347
echo "::group::Set Date - Hack for Quiet Time"
3448
$newDate = (Get-Date).AddHours(2)
3549
Set-Date -Date $newDate

0 commit comments

Comments
 (0)