Skip to content

Commit 40df0b9

Browse files
committed
chore(spike): close the first-logon privacy page before driving input
1 parent 35ca025 commit 40df0b9

5 files changed

Lines changed: 58 additions & 12 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,35 @@ function Set-Display([int]$Width, [int]$Height) {
2727
$after = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
2828
"before=$($before.Width)x$($before.Height) change=$code after=$($after.Width)x$($after.Height)"
2929
}
30+
31+
Add-Type -Namespace Wg2 -Name Foreground -MemberDefinition @'
32+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
33+
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint pid);
34+
'@
35+
36+
function Get-ForegroundProcess {
37+
[uint32]$owner = 0
38+
[Wg2.Foreground]::GetWindowThreadProcessId([Wg2.Foreground]::GetForegroundWindow(), [ref]$owner) | Out-Null
39+
$p = Get-Process -Id $owner -ErrorAction SilentlyContinue
40+
if ($p) { "$($p.ProcessName) ($owner)" } else { "pid $owner" }
41+
}
42+
43+
# The Windows 11 Arm64 image signs in to "Choose privacy settings for your device", which covers the desktop and
44+
# keeps the foreground. The policy keeps it from coming back; the open page still has to be closed.
45+
function Clear-FirstLogon {
46+
$log = @("foreground before: $(Get-ForegroundProcess)")
47+
New-Item -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\OOBE' -Force | Out-Null
48+
Set-ItemProperty -Path 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\OOBE' -Name 'DisablePrivacyExperience' -Value 1 -Type DWord
49+
$owner = (Get-ForegroundProcess) -replace ' \(.*', ''
50+
$names = @('WWAHost', 'CloudExperienceHostBroker', 'UserOOBEBroker')
51+
if ($owner -notin @('explorer', 'pwsh', 'powershell', 'Runner.Worker', 'pid 0')) { $names += $owner }
52+
foreach ($name in $names | Select-Object -Unique) {
53+
foreach ($p in Get-Process -Name $name -ErrorAction SilentlyContinue) {
54+
$log += "stopping $($p.ProcessName) ($($p.Id)) title='$($p.MainWindowTitle)'"
55+
Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue
56+
}
57+
}
58+
Start-Sleep 3
59+
$log += "foreground after: $(Get-ForegroundProcess)"
60+
$log -join '; '
61+
}

‎spikes/wingates2/ci/run-grid.ps1‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function Timed([string]$name, [scriptblock]$body) {
1919
Write-Host "== $name took $($build["${name}_s"]) s"
2020
}
2121

22-
. (Join-Path $PSScriptRoot 'display.ps1')
22+
. (Join-Path $PSScriptRoot 'desktop.ps1')
23+
$build.first_logon = Clear-FirstLogon
2324
$build.display = Set-Display -Width 1920 -Height 1080
2425
$build.dotnet = (dotnet --version)
2526

‎spikes/wingates2/ime/install-ime.ps1‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,7 @@ $telex = '042A:{C2CB2CF0-AF47-413E-9780-8BC3A3C16068}{5FB02EC5-0A77-4684-B4FA-DE
99
$pinyin = '0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}'
1010

1111
$sw = [Diagnostics.Stopwatch]::StartNew()
12-
$list = Get-WinUserLanguageList
13-
foreach ($tag in 'vi', 'zh-Hans-CN') {
14-
if (-not ($list.LanguageTag -contains $tag)) { $list.Add($tag) }
15-
}
16-
foreach ($entry in $list) {
17-
if ($entry.LanguageTag -eq 'vi') { $entry.InputMethodTips.Clear(); $entry.InputMethodTips.Add($telex) }
18-
if ($entry.LanguageTag -eq 'zh-Hans-CN') { $entry.InputMethodTips.Clear(); $entry.InputMethodTips.Add($pinyin) }
19-
}
20-
Set-WinUserLanguageList $list -Force
21-
Log (Get-WinUserLanguageList | Select-Object LanguageTag, InputMethodTips)
12+
Log (powershell.exe -NoProfile -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot 'set-languages.ps1') 2>&1)
2213

2314
Add-Type -Namespace Wg2 -Name Input -MemberDefinition @'
2415
[DllImport("input.dll", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool InstallLayoutOrTip(string profile, uint flags);

‎spikes/wingates2/ime/run-ime.ps1‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ $rid = "win-$Arch"
88
$platform = if ($Arch -eq 'arm64') { 'ARM64' } else { 'x64' }
99
New-Item -ItemType Directory -Force -Path $Out, "$Out\shots" | Out-Null
1010

11+
. (Join-Path $PSScriptRoot '..\ci\desktop.ps1')
12+
$desktop = [ordered]@{ first_logon = Clear-FirstLogon; display = Set-Display -Width 1920 -Height 1080 }
13+
1114
$sw = [Diagnostics.Stopwatch]::StartNew()
1215
dotnet publish "$PSScriptRoot\app\ImeHarness.csproj" -c Release -r $rid "-p:Platform=$platform" -o "$env:RUNNER_TEMP\ime-app" | Out-Host
1316
if ($LASTEXITCODE -ne 0) { throw 'harness publish failed' }
1417
dotnet publish "$PSScriptRoot\driver\ImeUia.csproj" -c Release -r $rid -o "$env:RUNNER_TEMP\ime-driver" | Out-Host
1518
if ($LASTEXITCODE -ne 0) { throw 'driver publish failed' }
16-
Write-Host "== build took $([int]$sw.Elapsed.TotalSeconds) s"
19+
$desktop.build_s = [int]$sw.Elapsed.TotalSeconds
20+
$desktop | ConvertTo-Json | Set-Content "$Out\desktop.json"
21+
Get-Content "$Out\desktop.json" | Out-Host
1722

1823
$driver = Start-Process "$env:RUNNER_TEMP\ime-driver\ImeUia.exe" -ArgumentList "serve `"$Out`" 900" -PassThru -RedirectStandardOutput "$Out\driver-stdout.txt" -RedirectStandardError "$Out\driver-stderr.txt"
1924
$app = Start-Process "$env:RUNNER_TEMP\ime-app\ImeHarness.exe" -ArgumentList "`"$Out`"" -PassThru
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Runs under Windows PowerShell 5.1: in PowerShell 7 the International module loads through implicit remoting,
2+
# and the language list comes back as deserialized objects without Add().
3+
$telex = '042A:{C2CB2CF0-AF47-413E-9780-8BC3A3C16068}{5FB02EC5-0A77-4684-B4FA-DEF8A2195628}'
4+
$pinyin = '0804:{81D4E9C9-1D3B-41BC-9E6C-4B40BF79E35E}{FA550B04-5AD7-411F-A5AC-CA038EC515D7}'
5+
6+
$list = Get-WinUserLanguageList
7+
"before: $(($list | ForEach-Object { "$($_.LanguageTag)[$($_.InputMethodTips -join ',')]" }) -join ' ')"
8+
foreach ($tag in 'en-US', 'vi', 'zh-Hans-CN') {
9+
if (-not ($list | Where-Object LanguageTag -eq $tag)) { $list.Add($tag) }
10+
}
11+
foreach ($entry in $list) {
12+
if ($entry.LanguageTag -eq 'vi') { $entry.InputMethodTips.Clear(); $entry.InputMethodTips.Add($telex) }
13+
if ($entry.LanguageTag -eq 'zh-Hans-CN') { $entry.InputMethodTips.Clear(); $entry.InputMethodTips.Add($pinyin) }
14+
}
15+
Set-WinUserLanguageList $list -Force
16+
$after = Get-WinUserLanguageList
17+
"after: $(($after | ForEach-Object { "$($_.LanguageTag)[$($_.InputMethodTips -join ',')]" }) -join ' ')"

0 commit comments

Comments
 (0)