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,41 @@
|
|
|
1
|
+
# Rebuild ocr.exe from ocr.cs — the WinRT OCR shim the PowerShell worker shells out to.
|
|
2
|
+
#
|
|
3
|
+
# Why a compiled shim at all: Windows PowerShell 5.1's dynamic WinRT binding cannot construct a
|
|
4
|
+
# SoftwareBitmap from captured bytes (every CreateCopyFromPixels / IBuffer route throws
|
|
5
|
+
# MethodNotFound), so OCR-in-PS is a dead end. Compiled C# resolves those WinRT types at COMPILE
|
|
6
|
+
# time and works. The .exe needs NEITHER csc NOR the SDK at RUNTIME — it runs on any Win10/11 with
|
|
7
|
+
# .NET Framework 4.x + the OS OCR language pack. Footprint: ~7 KB, zero bundled model
|
|
8
|
+
# (Windows.Media.Ocr is an OS component).
|
|
9
|
+
#
|
|
10
|
+
# Needs: the Framework C# compiler (ships with .NET Framework) and the Windows SDK's unified
|
|
11
|
+
# Windows.winmd for the WinRT metadata. Run after installing the SDK via: powershell -File build-ocr.ps1
|
|
12
|
+
$ErrorActionPreference = 'Stop'
|
|
13
|
+
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
14
|
+
$FW = Join-Path $env:WINDIR 'Microsoft.NET\Framework64\v4.0.30319'
|
|
15
|
+
$csc = Join-Path $FW 'csc.exe'
|
|
16
|
+
if (-not (Test-Path $csc)) { throw "csc.exe not found at $csc" }
|
|
17
|
+
|
|
18
|
+
$sdkRoot = 'C:\Program Files (x86)\Windows Kits\10\UnionMetadata'
|
|
19
|
+
# Take the FULL versioned metadata (UnionMetadata\<ver>\Windows.winmd), NOT the type-forwarding
|
|
20
|
+
# Facade\Windows.WinMD — the facade has no real Windows.Media.Ocr types and fails to compile.
|
|
21
|
+
$winmd = Get-ChildItem -Path $sdkRoot -Recurse -Filter 'Windows.winmd' -ErrorAction SilentlyContinue |
|
|
22
|
+
Where-Object { $_.FullName -notmatch '\\Facade\\' } |
|
|
23
|
+
Sort-Object FullName -Descending | Select-Object -First 1
|
|
24
|
+
if ($null -eq $winmd) { throw "Windows.winmd not found under $sdkRoot — install the Windows 10/11 SDK" }
|
|
25
|
+
|
|
26
|
+
$refs = @(
|
|
27
|
+
"-reference:$($winmd.FullName)",
|
|
28
|
+
"-reference:$FW\System.Runtime.WindowsRuntime.dll",
|
|
29
|
+
"-reference:$FW\System.Runtime.dll",
|
|
30
|
+
"-reference:$FW\System.ObjectModel.dll",
|
|
31
|
+
"-reference:$FW\System.Collections.dll",
|
|
32
|
+
"-reference:$FW\System.Globalization.dll",
|
|
33
|
+
"-reference:$FW\System.Threading.Tasks.dll",
|
|
34
|
+
"-reference:$FW\System.Runtime.InteropServices.dll",
|
|
35
|
+
"-reference:$FW\System.Diagnostics.Debug.dll",
|
|
36
|
+
"-reference:$FW\System.Runtime.InteropServices.WindowsRuntime.dll"
|
|
37
|
+
)
|
|
38
|
+
$out = Join-Path $here 'ocr.exe'
|
|
39
|
+
& $csc -nologo -target:exe "-out:$out" $refs (Join-Path $here 'ocr.cs')
|
|
40
|
+
if ($LASTEXITCODE -ne 0) { throw "csc failed (exit $LASTEXITCODE)" }
|
|
41
|
+
Write-Output ("built " + $out + " (" + (Get-Item $out).Length + " bytes) against " + $winmd.FullName)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.IO;
|
|
3
|
+
using System.Text;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using Windows.Storage.Streams;
|
|
6
|
+
using Windows.Graphics.Imaging;
|
|
7
|
+
using Windows.Media.Ocr;
|
|
8
|
+
using Windows.Globalization;
|
|
9
|
+
|
|
10
|
+
class OcrTool {
|
|
11
|
+
static string J(string s) {
|
|
12
|
+
var sb = new StringBuilder();
|
|
13
|
+
foreach (char c in s) {
|
|
14
|
+
if (c == '"') sb.Append("\\\"");
|
|
15
|
+
else if (c == '\\') sb.Append("\\\\");
|
|
16
|
+
else if (c == '\n') sb.Append("\\n");
|
|
17
|
+
else if (c == '\r') sb.Append("\\r");
|
|
18
|
+
else if (c == '\t') sb.Append("\\t");
|
|
19
|
+
else if (c < ' ') sb.Append("\\u" + ((int)c).ToString("x4"));
|
|
20
|
+
else sb.Append(c);
|
|
21
|
+
}
|
|
22
|
+
return sb.ToString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static T Wait<T>(Windows.Foundation.IAsyncOperation<T> op) {
|
|
26
|
+
return op.AsTask().GetAwaiter().GetResult();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static int Main(string[] args) {
|
|
30
|
+
Console.OutputEncoding = new UTF8Encoding(false);
|
|
31
|
+
try {
|
|
32
|
+
if (args.Length < 1) { Console.WriteLine("{\"ok\":false,\"error\":\"no path\"}"); return 2; }
|
|
33
|
+
byte[] data = File.ReadAllBytes(args[0]);
|
|
34
|
+
var stream = new InMemoryRandomAccessStream();
|
|
35
|
+
var dw = new DataWriter(stream.GetOutputStreamAt(0));
|
|
36
|
+
dw.WriteBytes(data);
|
|
37
|
+
dw.StoreAsync().AsTask().GetAwaiter().GetResult();
|
|
38
|
+
dw.DetachStream();
|
|
39
|
+
stream.Seek(0);
|
|
40
|
+
var dec = Wait(BitmapDecoder.CreateAsync(stream));
|
|
41
|
+
var bmp = Wait(dec.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied));
|
|
42
|
+
|
|
43
|
+
OcrEngine eng = null;
|
|
44
|
+
try {
|
|
45
|
+
var lang = new Language("zh-Hans-CN");
|
|
46
|
+
if (OcrEngine.IsLanguageSupported(lang)) eng = OcrEngine.TryCreateFromLanguage(lang);
|
|
47
|
+
} catch { }
|
|
48
|
+
if (eng == null) eng = OcrEngine.TryCreateFromUserProfileLanguages();
|
|
49
|
+
if (eng == null) { Console.WriteLine("{\"ok\":false,\"error\":\"no engine\"}"); return 3; }
|
|
50
|
+
|
|
51
|
+
var res = Wait(eng.RecognizeAsync(bmp));
|
|
52
|
+
var words = new List<string>();
|
|
53
|
+
foreach (var line in res.Lines) {
|
|
54
|
+
foreach (var w in line.Words) {
|
|
55
|
+
var r = w.BoundingRect;
|
|
56
|
+
words.Add("{\"t\":\"" + J(w.Text) + "\",\"x\":" + ((int)Math.Round(r.X)) +
|
|
57
|
+
",\"y\":" + ((int)Math.Round(r.Y)) + ",\"w\":" + ((int)Math.Round(r.Width)) +
|
|
58
|
+
",\"h\":" + ((int)Math.Round(r.Height)) + "}");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
Console.WriteLine("{\"ok\":true,\"text\":\"" + J(res.Text) + "\",\"words\":[" +
|
|
62
|
+
string.Join(",", words.ToArray()) + "]}");
|
|
63
|
+
return 0;
|
|
64
|
+
} catch (Exception e) {
|
|
65
|
+
Console.WriteLine("{\"ok\":false,\"error\":\"" + J(e.GetType().Name + ": " + e.Message) + "\"}");
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
Binary file
|