dsh-native-uia 0.2.0 → 0.6.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/README.md +81 -398
- package/client/client.js +236 -48
- package/cordis.patch.yml +7 -8
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +8 -17
- package/scripts/check-lease.mjs +1 -1
- package/scripts/lib/dsh-tools-stub.mjs +14 -0
- package/scripts/lib/load-tools-source.mjs +17 -16
- package/scripts/lib/sources.mjs +62 -0
- package/scripts/load-tools.mjs +74 -0
- package/scripts/measure-parse.mjs +2 -2
- package/scripts/regression-tools.mjs +155 -6
- package/scripts/regression-worker.ps1 +29 -0
- package/scripts/verify-live-style.mjs +46 -0
- package/scripts/verify-live.mjs +12 -18
- package/scripts/verify.mjs +953 -192
- package/src/activity-window.js +71 -7
- package/src/dashboard.js +27 -69
- package/src/guard.js +39 -10
- package/src/index.js +187 -77
- package/src/notes.js +83 -0
- package/src/state.js +97 -10
- package/src/themes.js +66 -0
- package/src/tools/defs/act.js +671 -0
- package/src/tools/defs/lifecycle.js +205 -0
- package/src/tools/defs/observe.js +325 -0
- package/src/tools/defs/pointer.js +328 -0
- package/src/tools/format.js +338 -0
- package/src/tools/index.js +125 -0
- package/src/tools/ocr.js +91 -0
- package/src/tools/recipes.js +49 -0
- package/src/tools/runtime.js +42 -0
- package/src/worker-client.js +32 -10
- package/worker/assets/dsh-whale.path +1 -0
- package/worker/indicator-server.ps1 +1107 -72
- package/worker/lib/01-core.ps1 +64 -0
- package/worker/lib/02-uia.ps1 +224 -0
- package/worker/lib/03-window.ps1 +194 -0
- package/worker/lib/04-match.ps1 +435 -0
- package/worker/lib/05-value.ps1 +254 -0
- package/worker/lib/06-snapshot.ps1 +412 -0
- package/worker/lib/07-action.ps1 +329 -0
- package/worker/lib/08-command.ps1 +1495 -0
- package/worker/lib/09-pointer.ps1 +840 -0
- package/worker/lib/10-dispatch.ps1 +132 -0
- package/worker/ps-stdio.ps1 +7 -2
- package/worker/uia-worker.ps1 +599 -4220
- package/locale/desktop/en.json +0 -6
- package/locale/desktop/zh.json +0 -6
- package/scripts/regression-halt-latch.mjs +0 -100
- package/src/native-uia-remote.js +0 -80
- package/src/panel-face.js +0 -14
- package/src/tools.js +0 -1482
- package/web/control.html +0 -1413
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# 10-dispatch.ps1 -- handler table, budgets, request dispatch
|
|
2
|
+
#
|
|
3
|
+
# Part of worker/uia-worker.ps1, dot-sourced by it in the order scripts/lib/sources.mjs declares.
|
|
4
|
+
# It lives in its own file only so a section can be read without scrolling the whole RPC server.
|
|
5
|
+
# Dot-sourcing shares the entry's script scope, so a helper here may use $script:W and may call
|
|
6
|
+
# any function from any other part: neighbour order is not a dependency.
|
|
7
|
+
# ---------------------------------------------------------------- dispatch
|
|
8
|
+
$handlers = @{
|
|
9
|
+
ping = 'Cmd-Ping'
|
|
10
|
+
list_windows = 'Cmd-ListWindows'
|
|
11
|
+
resolve_window = 'Cmd-ResolveWindow'
|
|
12
|
+
snapshot = 'Cmd-Snapshot'
|
|
13
|
+
describe = 'Cmd-Describe'
|
|
14
|
+
descriptor_match = 'Cmd-DescriptorMatch'
|
|
15
|
+
act = 'Cmd-Act'
|
|
16
|
+
set_pointer_mode = 'Cmd-SetPointerMode'
|
|
17
|
+
escape_pressed = 'Cmd-EscapePressed'
|
|
18
|
+
prepare_batch = 'Cmd-PrepareBatch'
|
|
19
|
+
commit_batch = 'Cmd-CommitBatch'
|
|
20
|
+
wait = 'Cmd-Wait'
|
|
21
|
+
capture = 'Cmd-Capture'
|
|
22
|
+
capture_screen = 'Cmd-CaptureScreen'
|
|
23
|
+
ocr = 'Cmd-Ocr'
|
|
24
|
+
find_text = 'Cmd-FindText'
|
|
25
|
+
launch = 'Cmd-Launch'
|
|
26
|
+
close_window = 'Cmd-CloseWindow'
|
|
27
|
+
pointer_target = 'Cmd-PointerTarget'
|
|
28
|
+
pointer_click = 'Cmd-PointerClick'
|
|
29
|
+
pointer_drag = 'Cmd-PointerDrag'
|
|
30
|
+
pointer_scroll = 'Cmd-PointerScroll'
|
|
31
|
+
pointer_mouse = 'Cmd-PointerMouse'
|
|
32
|
+
window_action = 'Cmd-WindowAction'
|
|
33
|
+
type_text = 'Cmd-TypeText'
|
|
34
|
+
clipboard_read = 'Cmd-ClipboardRead'
|
|
35
|
+
clipboard_write = 'Cmd-ClipboardWrite'
|
|
36
|
+
clipboard_clear = 'Cmd-ClipboardClear'
|
|
37
|
+
key = 'Cmd-Key'
|
|
38
|
+
shutdown = 'Cmd-Shutdown'
|
|
39
|
+
}
|
|
40
|
+
$defaultBudget = @{
|
|
41
|
+
snapshot = 15000
|
|
42
|
+
commit_batch = 25000
|
|
43
|
+
prepare_batch = 12000
|
|
44
|
+
capture = 12000
|
|
45
|
+
capture_screen = 15000
|
|
46
|
+
ocr = 20000
|
|
47
|
+
launch = 25000
|
|
48
|
+
resolve_window = 15000
|
|
49
|
+
wait = 25000
|
|
50
|
+
find_text = 12000
|
|
51
|
+
close_window = 12000
|
|
52
|
+
act = 15000
|
|
53
|
+
set_pointer_mode = 3000
|
|
54
|
+
escape_pressed = 2000
|
|
55
|
+
list_windows = 8000
|
|
56
|
+
pointer_click = 5000
|
|
57
|
+
pointer_drag = 8000
|
|
58
|
+
pointer_scroll = 8000
|
|
59
|
+
pointer_mouse = 8000
|
|
60
|
+
window_action = 8000
|
|
61
|
+
type_text = 8000
|
|
62
|
+
clipboard_read = 5000
|
|
63
|
+
clipboard_write = 5000
|
|
64
|
+
clipboard_clear = 5000
|
|
65
|
+
key = 5000
|
|
66
|
+
pointer_target = 3000
|
|
67
|
+
describe = 8000
|
|
68
|
+
descriptor_match = 6000
|
|
69
|
+
ping = 5000
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function Invoke-Request($line) {
|
|
73
|
+
$id = 0
|
|
74
|
+
$cmd = ''
|
|
75
|
+
$A = @{}
|
|
76
|
+
try {
|
|
77
|
+
$obj = $null
|
|
78
|
+
try { $obj = ConvertFrom-Json $line } catch { Send-Err 0 'bad_json' ('not valid JSON: ' + $_.Exception.Message); return $true }
|
|
79
|
+
if ($null -eq $obj) { Send-Err 0 'bad_json' 'empty request'; return $true }
|
|
80
|
+
$pp = $obj.PSObject.Properties['id']
|
|
81
|
+
if ($null -ne $pp -and $null -ne $pp.Value) { try { $id = [long]$pp.Value } catch { $id = 0 } }
|
|
82
|
+
$pp = $obj.PSObject.Properties['cmd']
|
|
83
|
+
if ($null -ne $pp -and $null -ne $pp.Value) { $cmd = [string]$pp.Value }
|
|
84
|
+
$pp = $obj.PSObject.Properties['args']
|
|
85
|
+
if ($null -ne $pp -and $null -ne $pp.Value) { $d = Dict $pp.Value; if ($d -is [System.Collections.IDictionary]) { $A = $d } }
|
|
86
|
+
if ($cmd -eq '' -or -not $handlers.ContainsKey($cmd)) {
|
|
87
|
+
Send-Err $id 'unknown_cmd' ("unknown cmd '" + (OneLine $cmd) + "'")
|
|
88
|
+
return $true
|
|
89
|
+
}
|
|
90
|
+
$budgetMs = IntArg $A 'timeoutMs' 0
|
|
91
|
+
if ($budgetMs -gt 0) { $budgetMs = $budgetMs + 2500 } else {
|
|
92
|
+
$b = $defaultBudget[$cmd]
|
|
93
|
+
if ($null -eq $b) { $b = 10000 }
|
|
94
|
+
$budgetMs = [int]$b
|
|
95
|
+
}
|
|
96
|
+
Set-Deadline $budgetMs
|
|
97
|
+
$fn = $handlers[$cmd]
|
|
98
|
+
$result = & $fn $A
|
|
99
|
+
Set-Deadline 0
|
|
100
|
+
if ($cmd -eq 'shutdown') {
|
|
101
|
+
Send-Ok $id $result
|
|
102
|
+
Cleanup-All
|
|
103
|
+
return $false
|
|
104
|
+
}
|
|
105
|
+
Send-Ok $id $result
|
|
106
|
+
} catch {
|
|
107
|
+
Set-Deadline 0
|
|
108
|
+
$code, $msg = Split-Err $_
|
|
109
|
+
$log = $cmd + ' -> ' + $code + ': ' + (OneLine $msg)
|
|
110
|
+
if ($script:W.errors.Count -lt 200) { $script:W.errors.Add($log) | Out-Null }
|
|
111
|
+
Log $log
|
|
112
|
+
Send-Err $id $code $msg
|
|
113
|
+
}
|
|
114
|
+
return $true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function Cleanup-All {
|
|
118
|
+
# No Marshal.ReleaseComObject here either: managed UIA elements are not COM objects, so the
|
|
119
|
+
# call always threw and the empty catch swallowed it. Dropping every reference and letting the
|
|
120
|
+
# GC run below is the whole cleanup.
|
|
121
|
+
foreach ($rk in @($script:W.refs.Keys)) {
|
|
122
|
+
$r = $script:W.refs[$rk]
|
|
123
|
+
if ($null -ne $r) { $r.ae = $null }
|
|
124
|
+
}
|
|
125
|
+
$script:W.refs.Clear()
|
|
126
|
+
$script:W.refOrder.Clear()
|
|
127
|
+
$script:W.windows.Clear()
|
|
128
|
+
$script:W.winByHwnd.Clear()
|
|
129
|
+
$script:W.totalRefs = 0
|
|
130
|
+
try { [GC]::Collect(); [GC]::WaitForPendingFinalizers(); [GC]::Collect() } catch { }
|
|
131
|
+
}
|
|
132
|
+
|
package/worker/ps-stdio.ps1
CHANGED
|
@@ -58,8 +58,13 @@ function JsonOf($o) {
|
|
|
58
58
|
if ($o -is [string]) { return '"' + (Esc $o) + '"' }
|
|
59
59
|
if ($o -is [System.Collections.IDictionary]) {
|
|
60
60
|
$parts = New-Object System.Collections.Generic.List[string]
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
# GetEnumerator(), never $o.Keys: PowerShell's member lookup resolves `$dict.Keys` to the VALUE
|
|
62
|
+
# of a dictionary entry literally named "keys" before it resolves the .Keys property, so a
|
|
63
|
+
# result field called `keys` serialized as {} (the iteration walked the string 'shift' and
|
|
64
|
+
# indexed the dictionary by character). Enumerator entries are immune to member shadowing.
|
|
65
|
+
foreach ($entry in $o.GetEnumerator()) {
|
|
66
|
+
$k = $entry.Key
|
|
67
|
+
$v = $entry.Value
|
|
63
68
|
# A field explicitly marked [DBNull]::Value is emitted as JSON null. Ordinary $null values
|
|
64
69
|
# stay dropped (many consumers distinguish "absent" from "null", e.g. act.before/after), so
|
|
65
70
|
# an intentional null has to be opted into case by case.
|