dsh-native-uia 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +431 -2
- package/client/client.js +81 -0
- package/cordis.patch.yml +11 -0
- package/icon.svg +11 -0
- package/locale/desktop/en.json +6 -0
- package/locale/desktop/zh.json +6 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +80 -4
- package/scripts/bench-live.mjs +157 -0
- package/scripts/check-lease.mjs +308 -0
- package/scripts/install.mjs +154 -0
- package/scripts/lib/load-tools-source.mjs +24 -0
- package/scripts/measure-parse.mjs +77 -0
- package/scripts/regression-halt-latch.mjs +100 -0
- package/scripts/regression-quality.mjs +207 -0
- package/scripts/regression-tools.mjs +88 -0
- package/scripts/regression-worker.ps1 +1042 -0
- package/scripts/smoke.mjs +158 -0
- package/scripts/verify-capture-scale.mjs +37 -0
- package/scripts/verify-live-clipboard.mjs +108 -0
- package/scripts/verify-live.mjs +110 -0
- package/scripts/verify-locator.mjs +52 -0
- package/scripts/verify.mjs +1459 -0
- package/src/activity-window.js +212 -0
- package/src/dashboard.js +145 -0
- package/src/guard.js +191 -0
- package/src/index.js +377 -0
- package/src/native-uia-remote.js +80 -0
- package/src/panel-face.js +14 -0
- package/src/state.js +177 -0
- package/src/tools.js +1482 -0
- package/src/worker-client.js +246 -0
- package/web/control.html +1413 -0
- package/worker/bin/build-ocr.ps1 +41 -0
- package/worker/bin/ocr.cs +69 -0
- package/worker/bin/ocr.exe +0 -0
- package/worker/indicator-server.ps1 +1928 -0
- package/worker/ps-stdio.ps1 +168 -0
- package/worker/uia-worker.ps1 +4220 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# ps-stdio.ps1 -- stdio JSON framing helpers shared verbatim by the two resident
|
|
2
|
+
# PowerShell processes: uia-worker.ps1 (the UIA worker) and indicator-server.ps1
|
|
3
|
+
# (the overlay indicator).
|
|
4
|
+
#
|
|
5
|
+
# Each host loads this file at the top of its framing/io section:
|
|
6
|
+
# . (Join-Path $PSScriptRoot 'ps-stdio.ps1')
|
|
7
|
+
# Dot-sourcing keeps the caller's scope, so the functions below run against the
|
|
8
|
+
# host's script scope and the $script:escCache initialised below lands there.
|
|
9
|
+
# (scripts/regression-worker.ps1 loads these functions by AST extraction instead,
|
|
10
|
+
# which skips top-level assignments, so it initialises $script:escCache itself.)
|
|
11
|
+
#
|
|
12
|
+
# HOST-AGNOSTIC RULE: none of these functions may reference $script:W, $script:S
|
|
13
|
+
# or any other host-owned variable. A dot-sourced function body resolves $script:
|
|
14
|
+
# against whichever host loaded it, so one host-specific reference would silently
|
|
15
|
+
# break in the other process.
|
|
16
|
+
#
|
|
17
|
+
# Send-Ok / Send-Err are deliberately NOT shared: the worker writes $script:W.stats,
|
|
18
|
+
# the indicator writes $script:S.stats and decorates every result with exStyles and
|
|
19
|
+
# the last palette. Those shapes are per-host contracts, so they stay in their hosts.
|
|
20
|
+
#
|
|
21
|
+
# SAVED AS UTF-8 WITH BOM, CONTENT ASCII-ONLY: Windows PowerShell 5.1 decodes a
|
|
22
|
+
# BOM-less .ps1 with the system codepage, so an unlabelled file is one editor save
|
|
23
|
+
# away from mojibake. ASCII-only source cannot be corrupted that way.
|
|
24
|
+
#
|
|
25
|
+
# Escaping contract: every response line is escaped to pure ASCII -- chars > 0x7E
|
|
26
|
+
# become \uXXXX so the byte stream on the pipe is 7-bit clean regardless of the
|
|
27
|
+
# codepage the pipe was created with. JsonOf preserves the "absent vs null"
|
|
28
|
+
# distinction: a field explicitly marked [DBNull]::Value is emitted as JSON null,
|
|
29
|
+
# ordinary $null values stay dropped.
|
|
30
|
+
|
|
31
|
+
$script:escCache = @{}
|
|
32
|
+
|
|
33
|
+
function Esc([string]$s) {
|
|
34
|
+
if ($null -eq $s) { return '' }
|
|
35
|
+
$t = $s.Replace('\', '\\').Replace('"', '\"')
|
|
36
|
+
$t = $t.Replace("`b", '\b').Replace("`f", '\f').Replace("`n", '\n').Replace("`r", '\r').Replace("`t", '\t')
|
|
37
|
+
if ($t.Length -gt 0 -and $t -notmatch '[^\x20-\x7E]') { return $t }
|
|
38
|
+
$sb = New-Object System.Text.StringBuilder
|
|
39
|
+
$chars = $t.ToCharArray()
|
|
40
|
+
for ($i = 0; $i -lt $chars.Length; $i++) {
|
|
41
|
+
$c = $chars[$i]
|
|
42
|
+
$code = [int]$c
|
|
43
|
+
if ($code -ge 32 -and $code -le 126) {
|
|
44
|
+
[void]$sb.Append($c)
|
|
45
|
+
} else {
|
|
46
|
+
$key = [string]$code
|
|
47
|
+
$rep = $script:escCache.Item($key)
|
|
48
|
+
if ($null -eq $rep) { $rep = '\u' + $code.ToString('x4'); $script:escCache[$key] = $rep }
|
|
49
|
+
[void]$sb.Append($rep)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return $sb.ToString()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function JsonOf($o) {
|
|
56
|
+
if ($null -eq $o) { return 'null' }
|
|
57
|
+
if ($o -is [bool]) { if ($o) { return 'true' } else { return 'false' } }
|
|
58
|
+
if ($o -is [string]) { return '"' + (Esc $o) + '"' }
|
|
59
|
+
if ($o -is [System.Collections.IDictionary]) {
|
|
60
|
+
$parts = New-Object System.Collections.Generic.List[string]
|
|
61
|
+
foreach ($k in $o.Keys) {
|
|
62
|
+
$v = $o[$k]
|
|
63
|
+
# A field explicitly marked [DBNull]::Value is emitted as JSON null. Ordinary $null values
|
|
64
|
+
# stay dropped (many consumers distinguish "absent" from "null", e.g. act.before/after), so
|
|
65
|
+
# an intentional null has to be opted into case by case.
|
|
66
|
+
if ($v -is [System.DBNull]) { [void]$parts.Add('"' + (Esc ([string]$k)) + '":null'); continue }
|
|
67
|
+
# Reference equality, not value equality: PowerShell answers TRUE to
|
|
68
|
+
# `$null -eq $false`, `$null -eq 0`, `$null -eq @()` and `$null -eq ''`, so a
|
|
69
|
+
# value test silently deletes performedCount=0, truncated=false and empty
|
|
70
|
+
# names as well. The "absent vs null" contract is preserved for real nulls.
|
|
71
|
+
if ([Object]::ReferenceEquals($v, $null)) { continue }
|
|
72
|
+
[void]$parts.Add('"' + (Esc ([string]$k)) + '":' + (JsonOf $v))
|
|
73
|
+
}
|
|
74
|
+
if ($parts.Count -eq 0) { return '{}' }
|
|
75
|
+
return '{' + ([string]::Join(',', $parts)) + '}'
|
|
76
|
+
}
|
|
77
|
+
if ($o -is [System.Management.Automation.PSCustomObject]) {
|
|
78
|
+
$parts = New-Object System.Collections.Generic.List[string]
|
|
79
|
+
foreach ($kk in $o.PSObject.Properties) {
|
|
80
|
+
if ($null -eq $kk.Value) { continue }
|
|
81
|
+
[void]$parts.Add('"' + (Esc $kk.Name) + '":' + (JsonOf $kk.Value))
|
|
82
|
+
}
|
|
83
|
+
if ($parts.Count -eq 0) { return '{}' }
|
|
84
|
+
return '{' + ([string]::Join(',', $parts)) + '}'
|
|
85
|
+
}
|
|
86
|
+
if ($o -is [byte] -or $o -is [int16] -or $o -is [int32] -or $o -is [int64] -or $o -is [uint32] -or $o -is [sbyte] -or $o -is [uint16] -or $o -is [uint64]) {
|
|
87
|
+
return [string]([long]$o)
|
|
88
|
+
}
|
|
89
|
+
if ($o -is [double] -or $o -is [single] -or $o -is [decimal]) {
|
|
90
|
+
$d = [double]$o
|
|
91
|
+
if ([double]::IsNaN($d) -or [double]::IsInfinity($d)) { return 'null' }
|
|
92
|
+
if ($d -eq [Math]::Floor($d) -and [Math]::Abs($d) -lt 9.0E+15) { return ([long]$d).ToString([System.Globalization.CultureInfo]::InvariantCulture) }
|
|
93
|
+
return $d.ToString('R', [System.Globalization.CultureInfo]::InvariantCulture)
|
|
94
|
+
}
|
|
95
|
+
if ($o -is [System.Collections.IEnumerable]) {
|
|
96
|
+
$parts = New-Object System.Collections.Generic.List[string]
|
|
97
|
+
foreach ($it in $o) { [void]$parts.Add((JsonOf $it)) }
|
|
98
|
+
return '[' + ([string]::Join(',', $parts)) + ']'
|
|
99
|
+
}
|
|
100
|
+
return '"' + (Esc ([string]$o)) + '"'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function OneLine([string]$s) {
|
|
104
|
+
if ($null -eq $s) { return '' }
|
|
105
|
+
$t = $s.Replace("`r", ' ').Replace("`n", ' ')
|
|
106
|
+
if ($t.Length -gt 400) { $t = $t.Substring(0, 400) + '~' }
|
|
107
|
+
return $t
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function Err($code, $message) {
|
|
111
|
+
throw ('ERR|' + $code + '|' + $message)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function ArgOf($A, $name) { if ($null -eq $A) { return $null } ; if (-not $A.Contains($name)) { return $null }; return $A[$name] }
|
|
115
|
+
function IntArg($A, $name, $default) {
|
|
116
|
+
$v = ArgOf $A $name
|
|
117
|
+
if ($null -eq $v -or $v -is [string] -and ([string]$v).Length -eq 0) { return $default }
|
|
118
|
+
try { return [int][double]$v } catch { return $default }
|
|
119
|
+
}
|
|
120
|
+
function StrArg($A, $name, $default) {
|
|
121
|
+
$v = ArgOf $A $name
|
|
122
|
+
if ($null -eq $v) { return $default }
|
|
123
|
+
if ($v -is [string]) { return $v }
|
|
124
|
+
return [string]$v
|
|
125
|
+
}
|
|
126
|
+
function BoolArg($A, $name, $default) {
|
|
127
|
+
$v = ArgOf $A $name
|
|
128
|
+
if ($null -eq $v) { return $default }
|
|
129
|
+
if ($v -is [bool]) { return $v }
|
|
130
|
+
$s = ([string]$v).ToLowerInvariant()
|
|
131
|
+
if ($s -eq 'true' -or $s -eq '1' -or $s -eq 'yes') { return $true }
|
|
132
|
+
if ($s -eq 'false' -or $s -eq '0' -or $s -eq 'no') { return $false }
|
|
133
|
+
return $default
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
# Normalises a handler argument that may arrive as PSCustomObject into a hashtable.
|
|
137
|
+
# Scalars pass through unchanged; every caller gates on -is [IDictionary] before use,
|
|
138
|
+
# so the loose return is safe in both hosts.
|
|
139
|
+
function Dict($o) {
|
|
140
|
+
if ($null -eq $o) { return $null }
|
|
141
|
+
if ($o -is [System.Collections.IDictionary]) { return $o }
|
|
142
|
+
if ($o -is [System.Management.Automation.PSCustomObject]) {
|
|
143
|
+
$h = @{}
|
|
144
|
+
foreach ($kk in $o.PSObject.Properties) { $h[$kk.Name] = (Dict $kk.Value) }
|
|
145
|
+
return $h
|
|
146
|
+
}
|
|
147
|
+
return $o
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
# Splits a caught ErrorRecord into (code, message). ERR|-thrown errors keep their
|
|
151
|
+
# declared code; raw exceptions are classified -- a released UIA element is
|
|
152
|
+
# element_gone, COM/method failures surface as uia_error, anything else is
|
|
153
|
+
# internal_error.
|
|
154
|
+
function Split-Err($errRecord) {
|
|
155
|
+
$msg = $errRecord.Exception.Message
|
|
156
|
+
if ($null -eq $msg) { $msg = '' }
|
|
157
|
+
if ($msg.StartsWith('ERR|')) {
|
|
158
|
+
$parts = $msg.Split('|', 3)
|
|
159
|
+
if ($parts.Count -ge 3) { return @($parts[1], $parts[2]) }
|
|
160
|
+
if ($parts.Count -eq 2) { return @($parts[1], '') }
|
|
161
|
+
}
|
|
162
|
+
$ex = $errRecord.Exception
|
|
163
|
+
$code = 'internal_error'
|
|
164
|
+
if ($ex -is [System.Runtime.InteropServices.InvalidComObjectException]) { $code = 'element_gone' }
|
|
165
|
+
elseif ($ex -is [System.Runtime.InteropServices.COMException]) { $code = 'uia_error' }
|
|
166
|
+
elseif ($ex -is [System.Management.Automation.MethodInvocationException]) { $code = 'uia_error' }
|
|
167
|
+
return @($code, $msg)
|
|
168
|
+
}
|