Files
client/scripts/lib/stream-windows.ps1
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring.

Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
2026-11-01 19:43:18 +03:00

68 lines
4.1 KiB
PowerShell

param(
[Parameter(Mandatory=$true)][int]$RootProcessId,
[string]$CloseHandle = ''
)
$ErrorActionPreference = 'Stop'
Add-Type -TypeDefinition @'
using System;
using System.Text;
using System.Runtime.InteropServices;
public static class StreamSmokeWindows {
[DllImport("kernel32.dll")] public static extern uint WTSGetActiveConsoleSessionId();
public delegate bool EnumProc(IntPtr hwnd, IntPtr parameter);
[DllImport("user32.dll")] public static extern bool EnumWindows(EnumProc callback, IntPtr parameter);
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hwnd, out uint processId);
[DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr hwnd);
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowText(IntPtr hwnd, StringBuilder text, int count);
[DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetClassName(IntPtr hwnd, StringBuilder text, int count);
[DllImport("user32.dll", EntryPoint="GetWindowLongPtrW")] public static extern IntPtr GetWindowLongPtr(IntPtr hwnd, int index);
[DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr hwnd, out Rect rect);
[DllImport("user32.dll")] public static extern bool PostMessage(IntPtr hwnd, uint message, IntPtr wParam, IntPtr lParam);
[StructLayout(LayoutKind.Sequential)] public struct Rect { public int Left, Top, Right, Bottom; }
}
'@
# A dedicated test login/session must be isolated from the user's interactive console. This check
# applies to preflight, enumeration and WM_CLOSE alike; a profile alone is NOT desktop isolation.
$currentSession = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
$consoleSession = [StreamSmokeWindows]::WTSGetActiveConsoleSessionId()
$rootSession = (Get-Process -Id $RootProcessId -ErrorAction Stop).SessionId
if ($consoleSession -eq [uint32]::MaxValue -or $currentSession -eq $consoleSession -or $rootSession -ne $currentSession) {
throw 'Native PiP smoke requires a dedicated Windows test session separate from the active console; refusing desktop access'
}
# Only windows owned by this disposable Electron instance or its descendants are returned/touched.
$processes = @(Get-CimInstance Win32_Process | Select-Object ProcessId, ParentProcessId)
$owned = [System.Collections.Generic.HashSet[int]]::new()
[void]$owned.Add($RootProcessId)
do {
$added = $false
foreach ($process in $processes) {
if ($owned.Contains([int]$process.ParentProcessId) -and $owned.Add([int]$process.ProcessId)) { $added = $true }
}
} while ($added)
$windows = [System.Collections.Generic.List[object]]::new()
$callback = [StreamSmokeWindows+EnumProc]{
param([IntPtr]$handle, [IntPtr]$parameter)
[uint32]$ownerId = 0
[void][StreamSmokeWindows]::GetWindowThreadProcessId($handle, [ref]$ownerId)
if (-not $owned.Contains([int]$ownerId) -or -not [StreamSmokeWindows]::IsWindowVisible($handle)) { return $true }
$title = [System.Text.StringBuilder]::new(1024)
$class = [System.Text.StringBuilder]::new(256)
[void][StreamSmokeWindows]::GetWindowText($handle, $title, $title.Capacity)
[void][StreamSmokeWindows]::GetClassName($handle, $class, $class.Capacity)
$rect = [StreamSmokeWindows+Rect]::new()
[void][StreamSmokeWindows]::GetWindowRect($handle, [ref]$rect)
$style = [StreamSmokeWindows]::GetWindowLongPtr($handle, -20).ToInt64()
$windows.Add([pscustomobject]@{
handle = $handle.ToInt64().ToString(); processId = $ownerId; title = $title.ToString(); class = $class.ToString()
topmost = (($style -band 8) -ne 0); width = $rect.Right - $rect.Left; height = $rect.Bottom - $rect.Top
})
return $true
}
[void][StreamSmokeWindows]::EnumWindows($callback, [IntPtr]::Zero)
if ($CloseHandle) {
$target = @($windows | Where-Object { $_.handle -eq $CloseHandle -and $_.topmost })
if ($target.Count -ne 1) { throw 'Refusing to close a window outside this disposable instance or without topmost style' }
if (-not [StreamSmokeWindows]::PostMessage([IntPtr]([long]$CloseHandle), 0x0010, [IntPtr]::Zero, [IntPtr]::Zero)) { throw 'Native PiP close failed' }
}
ConvertTo-Json -InputObject @($windows.ToArray()) -Depth 4 -Compress