@bitefoundry/retrieviewer 0.0.2 → 0.0.4
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/ASSET-PROVENANCE.md +6 -0
- package/ASSETS-LICENSE.md +2 -1
- package/ATTRIBUTION.md +6 -1
- package/COMFORT-ART.md +65 -0
- package/DESKTOP-PLATFORMS.md +75 -0
- package/INSTALLING.md +8 -5
- package/PLUGIN.md +13 -10
- package/PREREQUISITES.md +95 -0
- package/PUPPY-MEMORY.md +102 -1
- package/README.ko.md +110 -0
- package/README.md +119 -58
- package/RELEASING.md +27 -14
- package/THIRD-PARTY-NOTICES.md +5 -3
- package/braille.mjs +35 -9
- package/examples/live.mjs +2 -2
- package/integrations/desktop/platform.mjs +27 -0
- package/integrations/linux-overlay/README.md +83 -0
- package/integrations/linux-overlay/overlay.py +1094 -0
- package/integrations/macos-overlay/README.md +83 -0
- package/integrations/macos-overlay/overlay.jxa +639 -0
- package/integrations/opencode/runtime.mjs +4 -4
- package/integrations/opencode/tui.tsx +1 -1
- package/integrations/windows-overlay/Overlay.cs +4 -4
- package/integrations/windows-overlay/desktop.mjs +40 -8
- package/integrations/windows-overlay/protocol.mjs +11 -7
- package/integrations/windows-overlay/worker.mjs +13 -7
- package/package.json +41 -14
- package/puppy-comfort-sprites.mjs +25 -0
- package/puppy-companion-comfort-q5.bin.gz +0 -0
- package/puppy-companion-comfort.json +77 -0
- package/puppy-companion-life.mjs +49 -16
- package/puppy-companion-objects.mjs +12 -0
- package/puppy-frame-predictive.mjs +15 -9
- package/puppy-frame-store.mjs +2 -2
- package/puppy-paper-world.mjs +14 -0
- package/puppy-paper.mjs +65 -14
- package/retrieviewer-cli.mjs +10 -3
- package/retrieviewer-plugin.d.mts +1 -1
- package/retrieviewer-plugin.mjs +1 -1
- package/retrieviewer.d.mts +10 -4
- package/retrieviewer.mjs +20 -14
- package/locomotion-core.mjs +0 -21
- package/locomotion-puppy.animal +0 -0
- package/vendor/procedural-animals/package.json +0 -40
- package/vendor/procedural-animals/src/animal.js +0 -146
- package/vendor/procedural-animals/src/bake.js +0 -51
- package/vendor/procedural-animals/src/build.js +0 -81
- package/vendor/procedural-animals/src/core/build/coatKit.js +0 -121
- package/vendor/procedural-animals/src/core/build/featherCards.js +0 -189
- package/vendor/procedural-animals/src/core/build/finEdges.js +0 -85
- package/vendor/procedural-animals/src/core/build/furSlope.js +0 -115
- package/vendor/procedural-animals/src/core/build/mesh.js +0 -67
- package/vendor/procedural-animals/src/core/build/pipeline.js +0 -272
- package/vendor/procedural-animals/src/core/build/seams.js +0 -183
- package/vendor/procedural-animals/src/core/build/warp.js +0 -112
- package/vendor/procedural-animals/src/core/build/weights.js +0 -393
- package/vendor/procedural-animals/src/core/math/vec.js +0 -81
- package/vendor/procedural-animals/src/core/motion/actions.js +0 -800
- package/vendor/procedural-animals/src/core/motion/bird.js +0 -3063
- package/vendor/procedural-animals/src/core/motion/birdActions.js +0 -1059
- package/vendor/procedural-animals/src/core/motion/common.js +0 -158
- package/vendor/procedural-animals/src/core/motion/index.js +0 -22
- package/vendor/procedural-animals/src/core/motion/quadruped.js +0 -2875
- package/vendor/procedural-animals/src/core/motion/snake.js +0 -1594
- package/vendor/procedural-animals/src/core/motion/spider.js +0 -1810
- package/vendor/procedural-animals/src/core/motion/swimmer.js +0 -1047
- package/vendor/procedural-animals/src/core/motion/swimmerActions.js +0 -613
- package/vendor/procedural-animals/src/core/render/animalObject.js +0 -262
- package/vendor/procedural-animals/src/core/render/coatMaterial.js +0 -1301
- package/vendor/procedural-animals/src/core/render/dqs.js +0 -159
- package/vendor/procedural-animals/src/core/render/eyes.js +0 -676
- package/vendor/procedural-animals/src/core/render/membranes.js +0 -77
- package/vendor/procedural-animals/src/core/render/skeleton.js +0 -41
- package/vendor/procedural-animals/src/core/rig/bird.js +0 -327
- package/vendor/procedural-animals/src/core/rig/quadruped.js +0 -76
- package/vendor/procedural-animals/src/core/rig/rig.js +0 -79
- package/vendor/procedural-animals/src/core/rig/snake.js +0 -76
- package/vendor/procedural-animals/src/core/rig/spider.js +0 -110
- package/vendor/procedural-animals/src/core/rig/swimmer.js +0 -181
- package/vendor/procedural-animals/src/core/sdf/eyeSocket.js +0 -53
- package/vendor/procedural-animals/src/core/sdf/mesher.js +0 -238
- package/vendor/procedural-animals/src/core/sdf/sdf.js +0 -263
- package/vendor/procedural-animals/src/index.d.ts +0 -98
- package/vendor/procedural-animals/src/index.js +0 -29
- package/vendor/procedural-animals/src/registry.js +0 -48
- package/vendor/procedural-animals/src/species/bear/behaviour.js +0 -463
- package/vendor/procedural-animals/src/species/bear/claws.js +0 -147
- package/vendor/procedural-animals/src/species/bear/coat.js +0 -726
- package/vendor/procedural-animals/src/species/bear/index.js +0 -139
- package/vendor/procedural-animals/src/species/bear/motion.js +0 -112
- package/vendor/procedural-animals/src/species/bear/regions.js +0 -78
- package/vendor/procedural-animals/src/species/bear/rig.js +0 -112
- package/vendor/procedural-animals/src/species/bear/sculpt.js +0 -272
- package/vendor/procedural-animals/src/species/boar/behaviour.js +0 -335
- package/vendor/procedural-animals/src/species/boar/coat.js +0 -372
- package/vendor/procedural-animals/src/species/boar/index.js +0 -110
- package/vendor/procedural-animals/src/species/boar/motion.js +0 -85
- package/vendor/procedural-animals/src/species/boar/regions.js +0 -88
- package/vendor/procedural-animals/src/species/boar/rig.js +0 -111
- package/vendor/procedural-animals/src/species/boar/sculpt.js +0 -285
- package/vendor/procedural-animals/src/species/cat/behaviour.js +0 -559
- package/vendor/procedural-animals/src/species/cat/coat.js +0 -841
- package/vendor/procedural-animals/src/species/cat/index.js +0 -211
- package/vendor/procedural-animals/src/species/cat/motion.js +0 -101
- package/vendor/procedural-animals/src/species/cat/regions.js +0 -82
- package/vendor/procedural-animals/src/species/cat/rig.js +0 -100
- package/vendor/procedural-animals/src/species/cat/sculpt.js +0 -266
- package/vendor/procedural-animals/src/species/cat/whiskers.js +0 -110
- package/vendor/procedural-animals/src/species/cheetah/coat.js +0 -427
- package/vendor/procedural-animals/src/species/cheetah/index.js +0 -51
- package/vendor/procedural-animals/src/species/cheetah/joints.js +0 -3
- package/vendor/procedural-animals/src/species/cheetah/motion.js +0 -77
- package/vendor/procedural-animals/src/species/cheetah/regions.js +0 -95
- package/vendor/procedural-animals/src/species/cheetah/rig.js +0 -66
- package/vendor/procedural-animals/src/species/cheetah/sculpt.js +0 -158
- package/vendor/procedural-animals/src/species/chicken/coat.js +0 -313
- package/vendor/procedural-animals/src/species/chicken/coverts.js +0 -320
- package/vendor/procedural-animals/src/species/chicken/index.js +0 -110
- package/vendor/procedural-animals/src/species/chicken/motion.js +0 -177
- package/vendor/procedural-animals/src/species/chicken/regions.js +0 -66
- package/vendor/procedural-animals/src/species/chicken/rig.js +0 -144
- package/vendor/procedural-animals/src/species/chicken/sculpt.js +0 -389
- package/vendor/procedural-animals/src/species/chicken/wingLook.js +0 -66
- package/vendor/procedural-animals/src/species/chicken/wingStack.js +0 -124
- package/vendor/procedural-animals/src/species/cow/behaviour.js +0 -521
- package/vendor/procedural-animals/src/species/cow/coat.js +0 -465
- package/vendor/procedural-animals/src/species/cow/index.js +0 -118
- package/vendor/procedural-animals/src/species/cow/motion.js +0 -81
- package/vendor/procedural-animals/src/species/cow/regions.js +0 -98
- package/vendor/procedural-animals/src/species/cow/rig.js +0 -116
- package/vendor/procedural-animals/src/species/cow/sculpt.js +0 -339
- package/vendor/procedural-animals/src/species/crow/coat.js +0 -145
- package/vendor/procedural-animals/src/species/crow/index.js +0 -70
- package/vendor/procedural-animals/src/species/crow/joints.js +0 -3
- package/vendor/procedural-animals/src/species/crow/motion.js +0 -101
- package/vendor/procedural-animals/src/species/crow/regions.js +0 -50
- package/vendor/procedural-animals/src/species/crow/rig.js +0 -83
- package/vendor/procedural-animals/src/species/crow/sculpt.js +0 -118
- package/vendor/procedural-animals/src/species/deer/behaviour.js +0 -513
- package/vendor/procedural-animals/src/species/deer/coat.js +0 -391
- package/vendor/procedural-animals/src/species/deer/index.js +0 -106
- package/vendor/procedural-animals/src/species/deer/motion.js +0 -97
- package/vendor/procedural-animals/src/species/deer/regions.js +0 -60
- package/vendor/procedural-animals/src/species/deer/rig.js +0 -124
- package/vendor/procedural-animals/src/species/deer/sculpt.js +0 -297
- package/vendor/procedural-animals/src/species/dog/behaviour.js +0 -521
- package/vendor/procedural-animals/src/species/dog/coat.js +0 -495
- package/vendor/procedural-animals/src/species/dog/index.js +0 -144
- package/vendor/procedural-animals/src/species/dog/motion.js +0 -118
- package/vendor/procedural-animals/src/species/dog/regions.js +0 -61
- package/vendor/procedural-animals/src/species/dog/rig.js +0 -129
- package/vendor/procedural-animals/src/species/dog/sculpt.js +0 -246
- package/vendor/procedural-animals/src/species/eagle/coat.js +0 -250
- package/vendor/procedural-animals/src/species/eagle/index.js +0 -76
- package/vendor/procedural-animals/src/species/eagle/joints.js +0 -3
- package/vendor/procedural-animals/src/species/eagle/motion.js +0 -137
- package/vendor/procedural-animals/src/species/eagle/regions.js +0 -57
- package/vendor/procedural-animals/src/species/eagle/rig.js +0 -107
- package/vendor/procedural-animals/src/species/eagle/sculpt.js +0 -137
- package/vendor/procedural-animals/src/species/fish/coat.js +0 -271
- package/vendor/procedural-animals/src/species/fish/index.js +0 -88
- package/vendor/procedural-animals/src/species/fish/motion.js +0 -92
- package/vendor/procedural-animals/src/species/fish/regions.js +0 -27
- package/vendor/procedural-animals/src/species/fish/rig.js +0 -143
- package/vendor/procedural-animals/src/species/fish/sculpt.js +0 -214
- package/vendor/procedural-animals/src/species/fish/variants.js +0 -126
- package/vendor/procedural-animals/src/species/fox/behaviour.js +0 -314
- package/vendor/procedural-animals/src/species/fox/coat.js +0 -444
- package/vendor/procedural-animals/src/species/fox/index.js +0 -120
- package/vendor/procedural-animals/src/species/fox/motion.js +0 -81
- package/vendor/procedural-animals/src/species/fox/regions.js +0 -59
- package/vendor/procedural-animals/src/species/fox/rig.js +0 -91
- package/vendor/procedural-animals/src/species/fox/sculpt.js +0 -202
- package/vendor/procedural-animals/src/species/frog/behaviour.js +0 -590
- package/vendor/procedural-animals/src/species/frog/coat.js +0 -305
- package/vendor/procedural-animals/src/species/frog/index.js +0 -97
- package/vendor/procedural-animals/src/species/frog/motion.js +0 -69
- package/vendor/procedural-animals/src/species/frog/regions.js +0 -46
- package/vendor/procedural-animals/src/species/frog/rig.js +0 -156
- package/vendor/procedural-animals/src/species/frog/sculpt.js +0 -240
- package/vendor/procedural-animals/src/species/goat/behaviour.js +0 -509
- package/vendor/procedural-animals/src/species/goat/coat.js +0 -590
- package/vendor/procedural-animals/src/species/goat/index.js +0 -149
- package/vendor/procedural-animals/src/species/goat/motion.js +0 -95
- package/vendor/procedural-animals/src/species/goat/regions.js +0 -98
- package/vendor/procedural-animals/src/species/goat/rig.js +0 -181
- package/vendor/procedural-animals/src/species/goat/sculpt.js +0 -547
- package/vendor/procedural-animals/src/species/horse/coat.js +0 -361
- package/vendor/procedural-animals/src/species/horse/coatSeam.js +0 -122
- package/vendor/procedural-animals/src/species/horse/index.js +0 -80
- package/vendor/procedural-animals/src/species/horse/motion.js +0 -245
- package/vendor/procedural-animals/src/species/horse/regions.js +0 -60
- package/vendor/procedural-animals/src/species/horse/rig.js +0 -117
- package/vendor/procedural-animals/src/species/horse/sculpt.js +0 -316
- package/vendor/procedural-animals/src/species/horse/seamWeights.js +0 -272
- package/vendor/procedural-animals/src/species/lion/behaviour.js +0 -509
- package/vendor/procedural-animals/src/species/lion/coat.js +0 -1016
- package/vendor/procedural-animals/src/species/lion/index.js +0 -111
- package/vendor/procedural-animals/src/species/lion/motion.js +0 -87
- package/vendor/procedural-animals/src/species/lion/regions.js +0 -106
- package/vendor/procedural-animals/src/species/lion/rig.js +0 -110
- package/vendor/procedural-animals/src/species/lion/sculpt.js +0 -384
- package/vendor/procedural-animals/src/species/lion/whiskers.js +0 -132
- package/vendor/procedural-animals/src/species/pig/behaviour.js +0 -575
- package/vendor/procedural-animals/src/species/pig/coat.js +0 -730
- package/vendor/procedural-animals/src/species/pig/ears.js +0 -242
- package/vendor/procedural-animals/src/species/pig/index.js +0 -161
- package/vendor/procedural-animals/src/species/pig/motion.js +0 -105
- package/vendor/procedural-animals/src/species/pig/regions.js +0 -100
- package/vendor/procedural-animals/src/species/pig/rig.js +0 -152
- package/vendor/procedural-animals/src/species/pig/sculpt.js +0 -382
- package/vendor/procedural-animals/src/species/rabbit/behaviour.js +0 -605
- package/vendor/procedural-animals/src/species/rabbit/coat.js +0 -285
- package/vendor/procedural-animals/src/species/rabbit/index.js +0 -85
- package/vendor/procedural-animals/src/species/rabbit/motion.js +0 -85
- package/vendor/procedural-animals/src/species/rabbit/regions.js +0 -48
- package/vendor/procedural-animals/src/species/rabbit/rig.js +0 -99
- package/vendor/procedural-animals/src/species/rabbit/sculpt.js +0 -148
- package/vendor/procedural-animals/src/species/rat/behaviour.js +0 -539
- package/vendor/procedural-animals/src/species/rat/coat.js +0 -341
- package/vendor/procedural-animals/src/species/rat/index.js +0 -111
- package/vendor/procedural-animals/src/species/rat/motion.js +0 -90
- package/vendor/procedural-animals/src/species/rat/regions.js +0 -92
- package/vendor/procedural-animals/src/species/rat/rig.js +0 -112
- package/vendor/procedural-animals/src/species/rat/sculpt.js +0 -163
- package/vendor/procedural-animals/src/species/rat/whiskers.js +0 -119
- package/vendor/procedural-animals/src/species/shark/coat.js +0 -383
- package/vendor/procedural-animals/src/species/shark/index.js +0 -104
- package/vendor/procedural-animals/src/species/shark/motion.js +0 -69
- package/vendor/procedural-animals/src/species/shark/regions.js +0 -34
- package/vendor/procedural-animals/src/species/shark/rig.js +0 -194
- package/vendor/procedural-animals/src/species/shark/sculpt.js +0 -343
- package/vendor/procedural-animals/src/species/shark/variants.js +0 -105
- package/vendor/procedural-animals/src/species/sheep/behaviour.js +0 -522
- package/vendor/procedural-animals/src/species/sheep/coat.js +0 -529
- package/vendor/procedural-animals/src/species/sheep/index.js +0 -152
- package/vendor/procedural-animals/src/species/sheep/motion.js +0 -86
- package/vendor/procedural-animals/src/species/sheep/neck.js +0 -41
- package/vendor/procedural-animals/src/species/sheep/regions.js +0 -62
- package/vendor/procedural-animals/src/species/sheep/rig.js +0 -163
- package/vendor/procedural-animals/src/species/sheep/sculpt.js +0 -542
- package/vendor/procedural-animals/src/species/snake/coat.js +0 -315
- package/vendor/procedural-animals/src/species/snake/index.js +0 -73
- package/vendor/procedural-animals/src/species/snake/motion.js +0 -51
- package/vendor/procedural-animals/src/species/snake/regions.js +0 -51
- package/vendor/procedural-animals/src/species/snake/rig.js +0 -108
- package/vendor/procedural-animals/src/species/snake/sculpt.js +0 -122
- package/vendor/procedural-animals/src/species/spider/coat.js +0 -279
- package/vendor/procedural-animals/src/species/spider/index.js +0 -78
- package/vendor/procedural-animals/src/species/spider/motion.js +0 -72
- package/vendor/procedural-animals/src/species/spider/regions.js +0 -87
- package/vendor/procedural-animals/src/species/spider/rig.js +0 -118
- package/vendor/procedural-animals/src/species/spider/sculpt.js +0 -182
- package/vendor/procedural-animals/src/species/wolf/behaviour.js +0 -160
- package/vendor/procedural-animals/src/species/wolf/coat.js +0 -749
- package/vendor/procedural-animals/src/species/wolf/index.js +0 -107
- package/vendor/procedural-animals/src/species/wolf/motion.js +0 -80
- package/vendor/procedural-animals/src/species/wolf/regions.js +0 -57
- package/vendor/procedural-animals/src/species/wolf/rig.js +0 -87
- package/vendor/procedural-animals/src/species/wolf/sculpt.js +0 -339
- package/vendor/procedural-animals/src/worker.js +0 -29
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
// Native macOS painter for the existing Braille engine, run with the built-in
|
|
2
|
+
// '/usr/bin/osascript -l JavaScript overlay.jxa [--ipc-test|--self-test [proof.tiff]]'.
|
|
3
|
+
// JXA + AppKit/Foundation/CoreGraphics bridge only: no compiler, Python, Swift,
|
|
4
|
+
// Electron, downloaded binary, Accessibility API, event tap, injection, screen
|
|
5
|
+
// image capture, privacy prompt or agent/terminal content access. Window titles,
|
|
6
|
+
// positions and the foreground PID are read as metadata only.
|
|
7
|
+
// stdout carries NDJSON protocol messages only; nothing else is ever written there.
|
|
8
|
+
// Source is ASCII-only (non-ASCII text is \u-escaped) so osascript decoding cannot vary.
|
|
9
|
+
// ES5 syntax only: no arrow functions, let/const, classes or template literals.
|
|
10
|
+
|
|
11
|
+
// <pure> -- No ObjC below this line until </pure>; evaluated by Node tests.
|
|
12
|
+
var MAX_CELLS = 125000, LOW_PROFILE_CELLS = 20000, MAX_LINE_BYTES = 800000;
|
|
13
|
+
var MIN_WIDTH = 160, MIN_HEIGHT = 120;
|
|
14
|
+
var INK = [248, 242, 232, 245];
|
|
15
|
+
var TERMINAL_OWNERS = ['Terminal', 'iTerm2', 'iTerm', 'WezTerm', 'wezterm-gui', 'Alacritty', 'kitty', 'Ghostty', 'Warp', 'Hyper', 'Tabby'];
|
|
16
|
+
var TEXT = {
|
|
17
|
+
preparing: '\uC900\uBE44 \uC911',
|
|
18
|
+
playing: '\uD568\uAED8 \uB178\uB294 \uC911',
|
|
19
|
+
accepted: '\uC88B\uC544!',
|
|
20
|
+
busy: '\uC7A0\uAE50 \uAE30\uB2E4\uB824',
|
|
21
|
+
engineError: '\uC5D4\uC9C4 \uC624\uB958',
|
|
22
|
+
chooseFromMenu: '\uBA54\uB274 \uB9C9\uB300\uC5D0\uC11C \uCC3D \uC120\uD0DD'
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Low profile: 12pt cells, or 16pt when a large window would exceed 20000 cells.
|
|
26
|
+
function chooseGrid(rect) {
|
|
27
|
+
if (!rect) return { cell: 12, columns: 0, rows: 0 };
|
|
28
|
+
var cell = 12;
|
|
29
|
+
if (Math.floor(rect.width / cell) * Math.floor(rect.height / (cell * 2)) > LOW_PROFILE_CELLS) cell = 16;
|
|
30
|
+
return { cell: cell, columns: Math.floor(rect.width / cell), rows: Math.floor(rect.height / (cell * 2)) };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// CoreGraphics global space: origin at the primary display's top-left, y down, points.
|
|
34
|
+
// Cocoa screen space: origin at the primary display's bottom-left, y up, points.
|
|
35
|
+
// One formula covers secondary displays with negative origins; Retina scale does
|
|
36
|
+
// not enter because both spaces are in points.
|
|
37
|
+
function cgToCocoa(rect, primaryHeight) {
|
|
38
|
+
return { x: rect.x, y: primaryHeight - (rect.y + rect.height), width: rect.width, height: rect.height };
|
|
39
|
+
}
|
|
40
|
+
function cocoaToCg(rect, primaryHeight) {
|
|
41
|
+
return { x: rect.x, y: primaryHeight - (rect.y + rect.height), width: rect.width, height: rect.height };
|
|
42
|
+
}
|
|
43
|
+
function sameRect(a, b) {
|
|
44
|
+
if (!a || !b) return a === b;
|
|
45
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function isInt(v) { return typeof v === 'number' && isFinite(v) && Math.floor(v) === v; }
|
|
49
|
+
|
|
50
|
+
// Validates a protocol frame against the current grid; null means "empty frame".
|
|
51
|
+
function parseFrame(m, cell, canvas) {
|
|
52
|
+
var columns = m.columns, rows = m.rows, x = m.x, y = m.y, text = m.text;
|
|
53
|
+
if (!isInt(columns) || !isInt(rows) || !isInt(x) || !isInt(y) || typeof text !== 'string') throw new Error('Invalid overlay frame');
|
|
54
|
+
if (columns === 0 && rows === 0 && text.length === 0) return null;
|
|
55
|
+
if (columns < 1 || rows < 1 || columns * rows > MAX_CELLS || x < 0 || y < 0 || !canvas ||
|
|
56
|
+
(x + columns) * cell > canvas.width || (y + rows) * cell * 2 > canvas.height) throw new Error('Out-of-bounds overlay frame');
|
|
57
|
+
var lines = text.split('\n');
|
|
58
|
+
if (lines.length !== rows) throw new Error('Invalid overlay row count');
|
|
59
|
+
for (var r = 0; r < rows; r++) {
|
|
60
|
+
var line = lines[r];
|
|
61
|
+
if (line.length !== columns) throw new Error('Invalid overlay column count');
|
|
62
|
+
for (var c = 0; c < columns; c++) {
|
|
63
|
+
var code = line.charCodeAt(c);
|
|
64
|
+
if (code < 0x2800 || code > 0x28ff) throw new Error('Not a Braille frame');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { x: x, y: y, columns: columns, rows: rows, lines: lines };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Cocoa rectangle (CG space) of a parsed frame inside the target canvas.
|
|
71
|
+
function petRect(canvas, parsed, cell) {
|
|
72
|
+
return { x: canvas.x + parsed.x * cell, y: canvas.y + parsed.y * cell * 2, width: parsed.columns * cell, height: parsed.rows * cell * 2 };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Same dot geometry as Overlay.cs: Braille bit order, half-cell pitch, 0.48 diameter.
|
|
76
|
+
var DOT_DX = [0, 0, 0, 1, 1, 1, 0, 1], DOT_DY = [0, 1, 2, 0, 1, 2, 3, 3];
|
|
77
|
+
function dotStamp(cell, scale) {
|
|
78
|
+
var step = cell / 2 * scale, diameter = Math.max(1.1 * scale, step * 0.48), radius = diameter / 2;
|
|
79
|
+
var center = 0.5 * step, frac = center - Math.floor(center), reach = Math.ceil(radius + 1), size = reach * 2 + 1;
|
|
80
|
+
var cover = new Float32Array(size * size), samples = 4;
|
|
81
|
+
for (var py = 0; py < size; py++) for (var px = 0; px < size; px++) {
|
|
82
|
+
var hit = 0;
|
|
83
|
+
for (var sy = 0; sy < samples; sy++) for (var sx = 0; sx < samples; sx++) {
|
|
84
|
+
var dx = px - reach + (sx + 0.5) / samples - frac, dy = py - reach + (sy + 0.5) / samples - frac;
|
|
85
|
+
if (dx * dx + dy * dy <= radius * radius) hit++;
|
|
86
|
+
}
|
|
87
|
+
cover[py * size + px] = hit / (samples * samples);
|
|
88
|
+
}
|
|
89
|
+
return { cover: cover, size: size, reach: reach, step: step };
|
|
90
|
+
}
|
|
91
|
+
// Premultiplied RGBA pixels at 'scale' pixels per point.
|
|
92
|
+
function rasterize(parsed, cell, scale) {
|
|
93
|
+
var width = parsed.columns * cell * scale, height = parsed.rows * cell * 2 * scale;
|
|
94
|
+
var alpha = new Float32Array(width * height), stamp = dotStamp(cell, scale), dots = 0;
|
|
95
|
+
for (var row = 0; row < parsed.rows; row++) {
|
|
96
|
+
var line = parsed.lines[row];
|
|
97
|
+
for (var col = 0; col < parsed.columns; col++) {
|
|
98
|
+
var mask = line.charCodeAt(col) - 0x2800;
|
|
99
|
+
if (!mask) continue;
|
|
100
|
+
for (var bit = 0; bit < 8; bit++) {
|
|
101
|
+
if (!(mask & (1 << bit))) continue;
|
|
102
|
+
dots++;
|
|
103
|
+
var cx = Math.floor(col * cell * scale + (DOT_DX[bit] + 0.5) * stamp.step);
|
|
104
|
+
var cy = Math.floor(row * cell * 2 * scale + (DOT_DY[bit] + 0.5) * stamp.step);
|
|
105
|
+
for (var sy = 0; sy < stamp.size; sy++) {
|
|
106
|
+
var py = cy - stamp.reach + sy;
|
|
107
|
+
if (py < 0 || py >= height) continue;
|
|
108
|
+
for (var sx = 0; sx < stamp.size; sx++) {
|
|
109
|
+
var px = cx - stamp.reach + sx;
|
|
110
|
+
if (px < 0 || px >= width) continue;
|
|
111
|
+
var v = stamp.cover[sy * stamp.size + sx], i = py * width + px;
|
|
112
|
+
if (v > alpha[i]) alpha[i] = v;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var pixels = new Uint8Array(width * height * 4);
|
|
119
|
+
for (var p = 0; p < alpha.length; p++) {
|
|
120
|
+
if (!alpha[p]) continue;
|
|
121
|
+
var a = Math.round(alpha[p] * INK[3]);
|
|
122
|
+
pixels[p * 4] = Math.round(INK[0] * a / 255);
|
|
123
|
+
pixels[p * 4 + 1] = Math.round(INK[1] * a / 255);
|
|
124
|
+
pixels[p * 4 + 2] = Math.round(INK[2] * a / 255);
|
|
125
|
+
pixels[p * 4 + 3] = a;
|
|
126
|
+
}
|
|
127
|
+
return { width: width, height: height, pixels: pixels, dots: dots };
|
|
128
|
+
}
|
|
129
|
+
// Retina detail where affordable; never more than ~2M pixels per frame.
|
|
130
|
+
function paintScale(rect, screenScale) {
|
|
131
|
+
var scale = screenScale >= 2 ? 2 : 1;
|
|
132
|
+
while (scale > 1 && rect.width * rect.height * scale * scale > 2000000) scale--;
|
|
133
|
+
return scale;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Minimal baseline uncompressed little-endian RGBA TIFF (associated alpha):
|
|
137
|
+
// AppKit's native bitmap container, decoded by NSImage without extra codecs.
|
|
138
|
+
function tiffRGBA(width, height, pixels) {
|
|
139
|
+
var tags = [[256, 4, 1, width], [257, 4, 1, height], [258, 3, 4, 0], [259, 3, 1, 1], [262, 3, 1, 2],
|
|
140
|
+
[273, 4, 1, 0], [277, 3, 1, 4], [278, 4, 1, height], [279, 4, 1, width * height * 4], [284, 3, 1, 1], [338, 3, 1, 1]];
|
|
141
|
+
var ifd = 8, bitsAt = ifd + 2 + tags.length * 12 + 4, dataAt = bitsAt + 8;
|
|
142
|
+
tags[2][3] = bitsAt; tags[5][3] = dataAt;
|
|
143
|
+
var out = new Uint8Array(dataAt + pixels.length);
|
|
144
|
+
function u16(at, v) { out[at] = v & 255; out[at + 1] = (v >>> 8) & 255; }
|
|
145
|
+
function u32(at, v) { u16(at, v & 65535); u16(at + 2, (v >>> 16) & 65535); }
|
|
146
|
+
out[0] = 0x49; out[1] = 0x49; u16(2, 42); u32(4, ifd); u16(ifd, tags.length);
|
|
147
|
+
for (var t = 0; t < tags.length; t++) {
|
|
148
|
+
var at = ifd + 2 + t * 12, tag = tags[t];
|
|
149
|
+
u16(at, tag[0]); u16(at + 2, tag[1]); u32(at + 4, tag[2]);
|
|
150
|
+
if (tag[1] === 3 && tag[2] === 1) u16(at + 8, tag[3]); else u32(at + 8, tag[3]);
|
|
151
|
+
}
|
|
152
|
+
u32(bitsAt - 4, 0);
|
|
153
|
+
for (var b = 0; b < 4; b++) u16(bitsAt + b * 2, 8);
|
|
154
|
+
out.set(pixels, dataAt);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
159
|
+
function base64(bytes) {
|
|
160
|
+
var parts = [], chunk = [], n = bytes.length, i = 0;
|
|
161
|
+
for (; i + 2 < n; i += 3) {
|
|
162
|
+
var v = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
|
|
163
|
+
chunk.push(B64.charAt(v >> 18), B64.charAt((v >> 12) & 63), B64.charAt((v >> 6) & 63), B64.charAt(v & 63));
|
|
164
|
+
if (chunk.length >= 32768) { parts.push(chunk.join('')); chunk = []; }
|
|
165
|
+
}
|
|
166
|
+
if (i < n) {
|
|
167
|
+
var w = (bytes[i] << 16) | ((i + 1 < n ? bytes[i + 1] : 0) << 8);
|
|
168
|
+
chunk.push(B64.charAt(w >> 18), B64.charAt((w >> 12) & 63), i + 1 < n ? B64.charAt((w >> 6) & 63) : '=', '=');
|
|
169
|
+
}
|
|
170
|
+
parts.push(chunk.join(''));
|
|
171
|
+
return parts.join('');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// CGWindowListCopyWindowInfo dictionary (deep-unwrapped) to a plain record.
|
|
175
|
+
function windowRecord(info) {
|
|
176
|
+
if (!info || typeof info !== 'object') return null;
|
|
177
|
+
var b = info.kCGWindowBounds, id = info.kCGWindowNumber, pid = info.kCGWindowOwnerPID;
|
|
178
|
+
if (!isInt(id) || !isInt(pid) || !b) return null;
|
|
179
|
+
return {
|
|
180
|
+
id: id, pid: pid, owner: typeof info.kCGWindowOwnerName === 'string' ? info.kCGWindowOwnerName : '',
|
|
181
|
+
name: typeof info.kCGWindowName === 'string' ? info.kCGWindowName : '',
|
|
182
|
+
layer: isInt(info.kCGWindowLayer) ? info.kCGWindowLayer : 0,
|
|
183
|
+
alpha: typeof info.kCGWindowAlpha === 'number' ? info.kCGWindowAlpha : 1,
|
|
184
|
+
onscreen: info.kCGWindowIsOnscreen === true || info.kCGWindowIsOnscreen === 1,
|
|
185
|
+
bounds: { x: Math.round(b.X), y: Math.round(b.Y), width: Math.round(b.Width), height: Math.round(b.Height) }
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Picker entries: ordinary (layer 0) visible windows of other processes. When
|
|
189
|
+
// macOS withholds titles (no Screen Recording permission) the app name and
|
|
190
|
+
// window number are shown instead; no permission is requested.
|
|
191
|
+
function pickerTargets(infos, ownPid) {
|
|
192
|
+
var result = [];
|
|
193
|
+
for (var i = 0; i < infos.length; i++) {
|
|
194
|
+
var w = windowRecord(infos[i]);
|
|
195
|
+
if (!w || w.pid === ownPid || w.layer !== 0 || w.alpha <= 0 || w.bounds.width < MIN_WIDTH || w.bounds.height < MIN_HEIGHT) continue;
|
|
196
|
+
var terminal = TERMINAL_OWNERS.indexOf(w.owner) >= 0;
|
|
197
|
+
var label = (terminal ? '[\uD130\uBBF8\uB110] ' : '') + (w.name ? w.name + ' \u00B7 ' + w.owner : w.owner + ' \u00B7 \uCC3D') + ' #' + w.id;
|
|
198
|
+
result.push({ id: w.id, pid: w.pid, owner: w.owner, title: label, terminal: terminal });
|
|
199
|
+
}
|
|
200
|
+
result.sort(function (a, b) { return a.terminal === b.terminal ? (a.title < b.title ? -1 : a.title > b.title ? 1 : 0) : a.terminal ? -1 : 1; });
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
// Another window of the target's own app stacked above it means the selected
|
|
204
|
+
// window is not that app's front window.
|
|
205
|
+
function coveredBySameApp(aboveInfos, target) {
|
|
206
|
+
for (var i = 0; i < aboveInfos.length; i++) {
|
|
207
|
+
var w = windowRecord(aboveInfos[i]);
|
|
208
|
+
if (w && w.pid === target.pid && w.id !== target.id && w.layer === 0 && w.onscreen && w.alpha > 0) return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Platform-neutral state machine shared by the AppKit shell and Node tests.
|
|
214
|
+
// io: emit(msg) observe(target)->{info,frontPid,covered} paint(parsed,cell,canvas)
|
|
215
|
+
// hidePet() showBar(canvas) hideBar() status(text) loaded() quit()
|
|
216
|
+
function createCore(io, options) {
|
|
217
|
+
var s = { target: options && options.target || null, testMode: !!(options && options.testMode), canvas: null, cell: 12,
|
|
218
|
+
revision: 0, visible: false, paused: false, loaded: false, quitting: false, picking: false };
|
|
219
|
+
function track(force) {
|
|
220
|
+
if (s.quitting) return;
|
|
221
|
+
var obs = s.target ? io.observe(s.target) : { info: null };
|
|
222
|
+
if (s.target && (!obs.info || obs.info.pid !== s.target.pid || obs.info.id !== s.target.id)) s.target = null;
|
|
223
|
+
var next = null, show = false;
|
|
224
|
+
if (s.target && obs.info.onscreen) {
|
|
225
|
+
next = obs.info.bounds;
|
|
226
|
+
show = !s.picking && (s.testMode || (obs.frontPid === s.target.pid && !obs.covered)) && next.width >= MIN_WIDTH && next.height >= MIN_HEIGHT;
|
|
227
|
+
}
|
|
228
|
+
var grid = chooseGrid(next);
|
|
229
|
+
if (grid.columns * grid.rows > MAX_CELLS) show = false;
|
|
230
|
+
if (force || show !== s.visible || !sameRect(next, s.canvas) || grid.cell !== s.cell) {
|
|
231
|
+
s.visible = show; s.canvas = next; s.cell = grid.cell; s.revision++; io.hidePet();
|
|
232
|
+
io.emit({ type: 'viewport', revision: s.revision, visible: show && !s.paused, selected: s.target !== null,
|
|
233
|
+
columns: grid.columns, rows: grid.rows, cellWidth: s.cell, cellHeight: s.cell * 2 });
|
|
234
|
+
}
|
|
235
|
+
if (s.visible) { io.showBar(s.canvas); if (s.paused) io.hidePet(); } else { io.hidePet(); io.hideBar(); }
|
|
236
|
+
}
|
|
237
|
+
function message(m) {
|
|
238
|
+
if (s.quitting) return;
|
|
239
|
+
if (!m || typeof m !== 'object') throw new Error('Invalid overlay message');
|
|
240
|
+
if (m.type === 'quit') { quit(); return; }
|
|
241
|
+
if (m.type === 'loaded') { s.loaded = true; io.status(TEXT.playing); io.loaded(); return; }
|
|
242
|
+
if (m.type === 'interaction') { io.status(m.accepted === true ? TEXT.accepted : TEXT.busy); return; }
|
|
243
|
+
if (m.type === 'error') { io.status(TEXT.engineError); quit(); return; }
|
|
244
|
+
if (m.type === 'frame') {
|
|
245
|
+
// Always acknowledge stale or hidden frames too, or the sender stalls.
|
|
246
|
+
var painted = s.visible && !s.paused && m.revision === s.revision;
|
|
247
|
+
if (painted) { var parsed = parseFrame(m, s.cell, s.canvas); if (parsed) io.paint(parsed, s.cell, s.canvas); else io.hidePet(); }
|
|
248
|
+
io.emit({ type: 'ack', painted: painted });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function quit() { if (s.quitting) return; s.quitting = true; io.quit(); }
|
|
252
|
+
return {
|
|
253
|
+
track: track, message: message, quit: quit,
|
|
254
|
+
interact: function (kind) { if (s.quitting || !s.loaded || s.paused) return; io.emit({ type: 'interact', kind: kind }); },
|
|
255
|
+
togglePause: function () { if (s.quitting) return; s.paused = !s.paused; io.emit({ type: 'pause', paused: s.paused }); track(true); },
|
|
256
|
+
attach: function (target) { s.target = target; s.paused = false; io.emit({ type: 'pause', paused: false }); },
|
|
257
|
+
setPicking: function (value) { s.picking = !!value; },
|
|
258
|
+
state: s
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
// </pure>
|
|
262
|
+
|
|
263
|
+
var CG_ON_SCREEN_ONLY = 1, CG_ON_SCREEN_ABOVE = 2, CG_INCLUDING_WINDOW = 8, CG_EXCLUDE_DESKTOP = 16;
|
|
264
|
+
var STYLE_BORDERLESS = 0, STYLE_TITLED = 1, STYLE_CLOSABLE = 2, STYLE_NONACTIVATING = 128;
|
|
265
|
+
var BACKING_BUFFERED = 2, FLOATING_LEVEL = 3, ACTIVATION_ACCESSORY = 1, ANIMATION_NONE = 2;
|
|
266
|
+
// canJoinAllSpaces | stationary | ignoresCycle | fullScreenAuxiliary
|
|
267
|
+
var OVERLAY_SPACES = 1 | 16 | 64 | 256;
|
|
268
|
+
var BAR_WIDTH = 404, BAR_HEIGHT = 40;
|
|
269
|
+
|
|
270
|
+
var shell = null;
|
|
271
|
+
|
|
272
|
+
function emit(value) {
|
|
273
|
+
var line = $(JSON.stringify(value) + '\n').dataUsingEncoding($.NSUTF8StringEncoding);
|
|
274
|
+
$.NSFileHandle.fileHandleWithStandardOutput.writeData(line);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// CGWindowListCopyWindowInfo returns a +1 CFArray. Older JXA hands it back as
|
|
278
|
+
// an opaque Ref that must be cast; it is deep-copied into JS values and released.
|
|
279
|
+
function windowInfos(option, relativeTo) {
|
|
280
|
+
var ref = $.CGWindowListCopyWindowInfo(option, relativeTo), list = null;
|
|
281
|
+
if (ref === null || ref === undefined) return [];
|
|
282
|
+
if (typeof Ref === 'function' && ref instanceof Ref) {
|
|
283
|
+
list = ObjC.deepUnwrap(ObjC.castRefToObject(ref));
|
|
284
|
+
if (list) $.CFRelease(ref);
|
|
285
|
+
} else {
|
|
286
|
+
list = ObjC.deepUnwrap(ref);
|
|
287
|
+
}
|
|
288
|
+
return list instanceof Array ? list : [];
|
|
289
|
+
}
|
|
290
|
+
function windowById(id) {
|
|
291
|
+
var list = windowInfos(CG_INCLUDING_WINDOW, id);
|
|
292
|
+
for (var i = 0; i < list.length; i++) { var w = windowRecord(list[i]); if (w && w.id === id) return w; }
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
function primaryHeight() {
|
|
296
|
+
var screens = $.NSScreen.screens;
|
|
297
|
+
return screens.count ? screens.objectAtIndex(0).frame.size.height : 0;
|
|
298
|
+
}
|
|
299
|
+
function maxBackingScale() {
|
|
300
|
+
var screens = $.NSScreen.screens, scale = 1;
|
|
301
|
+
for (var i = 0; i < screens.count; i++) scale = Math.max(scale, screens.objectAtIndex(i).backingScaleFactor);
|
|
302
|
+
return scale;
|
|
303
|
+
}
|
|
304
|
+
function frontPid() {
|
|
305
|
+
var app = $.NSWorkspace.sharedWorkspace.frontmostApplication;
|
|
306
|
+
return app && !app.isNil() ? app.processIdentifier : -1;
|
|
307
|
+
}
|
|
308
|
+
function ownPid() { return $.NSProcessInfo.processInfo.processIdentifier; }
|
|
309
|
+
function rectFromStruct(frame) { return { x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: frame.size.height }; }
|
|
310
|
+
function nsRect(r) { return $.NSMakeRect(r.x, r.y, r.width, r.height); }
|
|
311
|
+
|
|
312
|
+
function makePanel(rect, style) {
|
|
313
|
+
var panel = $.NSPanel.alloc.initWithContentRectStyleMaskBackingDefer(nsRect(rect), style, BACKING_BUFFERED, false);
|
|
314
|
+
// JS wrappers own these windows; AppKit must not also release them on close.
|
|
315
|
+
panel.setReleasedWhenClosed(false);
|
|
316
|
+
panel.setHidesOnDeactivate(false);
|
|
317
|
+
panel.setAnimationBehavior(ANIMATION_NONE);
|
|
318
|
+
return panel;
|
|
319
|
+
}
|
|
320
|
+
// Transparent, shadowless, click-through, never key/main, above normal windows.
|
|
321
|
+
function makePetPanel() {
|
|
322
|
+
var panel = makePanel({ x: 0, y: 0, width: 16, height: 32 }, STYLE_BORDERLESS | STYLE_NONACTIVATING);
|
|
323
|
+
panel.setOpaque(false);
|
|
324
|
+
panel.setBackgroundColor($.NSColor.clearColor);
|
|
325
|
+
panel.setHasShadow(false);
|
|
326
|
+
panel.setIgnoresMouseEvents(true);
|
|
327
|
+
panel.setFloatingPanel(true);
|
|
328
|
+
panel.setBecomesKeyOnlyIfNeeded(true);
|
|
329
|
+
panel.setLevel(FLOATING_LEVEL);
|
|
330
|
+
panel.setCollectionBehavior(OVERLAY_SPACES);
|
|
331
|
+
var view = $.NSImageView.alloc.initWithFrame($.NSMakeRect(0, 0, 16, 32));
|
|
332
|
+
view.setImageScaling(1); // NSImageScaleAxesIndependently: image fills the view exactly.
|
|
333
|
+
panel.setContentView(view);
|
|
334
|
+
return { panel: panel, view: view };
|
|
335
|
+
}
|
|
336
|
+
function paintInto(pet, parsed, cell, canvas) {
|
|
337
|
+
var rect = petRect(canvas, parsed, cell), scale = paintScale(rect, maxBackingScale());
|
|
338
|
+
var raster = rasterize(parsed, cell, scale);
|
|
339
|
+
var data = $.NSData.alloc.initWithBase64EncodedStringOptions($(base64(tiffRGBA(raster.width, raster.height, raster.pixels))), 0);
|
|
340
|
+
var image = $.NSImage.alloc.initWithData(data);
|
|
341
|
+
if (!image || image.isNil()) throw new Error('Overlay bitmap decode failed');
|
|
342
|
+
image.setSize($.NSMakeSize(rect.width, rect.height));
|
|
343
|
+
// New image and new position are applied before ordering in: no afterimage.
|
|
344
|
+
pet.view.setFrame($.NSMakeRect(0, 0, rect.width, rect.height));
|
|
345
|
+
pet.view.setImage(image);
|
|
346
|
+
pet.panel.setFrameDisplay(nsRect(cgToCocoa(rect, primaryHeight())), true);
|
|
347
|
+
if (!pet.panel.isVisible) pet.panel.orderFrontRegardless;
|
|
348
|
+
return { rect: rect, data: data, raster: raster };
|
|
349
|
+
}
|
|
350
|
+
function hidePanel(panel) { if (panel.isVisible) panel.orderOut(null); }
|
|
351
|
+
function makeLabel(text, rect, color) {
|
|
352
|
+
var label = $.NSTextField.alloc.initWithFrame(nsRect(rect));
|
|
353
|
+
label.setStringValue($(text));
|
|
354
|
+
label.setEditable(false); label.setSelectable(false); label.setBordered(false); label.setDrawsBackground(false);
|
|
355
|
+
if (color) label.setTextColor(color);
|
|
356
|
+
return label;
|
|
357
|
+
}
|
|
358
|
+
function makeButton(title, rect, action) {
|
|
359
|
+
// RetrieviewerButton accepts the first click without activating this app.
|
|
360
|
+
var button = $.RetrieviewerButton.alloc.initWithFrame(nsRect(rect));
|
|
361
|
+
button.setTitle($(title));
|
|
362
|
+
button.setBezelStyle(1);
|
|
363
|
+
button.target = shell.controller;
|
|
364
|
+
button.action = action;
|
|
365
|
+
return button;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function registerClasses() {
|
|
369
|
+
function guarded(name) {
|
|
370
|
+
return { types: ['void', ['id']], implementation: function (sender) {
|
|
371
|
+
try { shell[name](sender); } catch (error) { fail(error); }
|
|
372
|
+
} };
|
|
373
|
+
}
|
|
374
|
+
ObjC.registerSubclass({
|
|
375
|
+
name: 'RetrieviewerButton', superclass: 'NSButton',
|
|
376
|
+
methods: { 'acceptsFirstMouse:': { types: ['bool', ['id']], implementation: function (event) { return true; } } }
|
|
377
|
+
});
|
|
378
|
+
ObjC.registerSubclass({
|
|
379
|
+
name: 'RetrieviewerController', superclass: 'NSObject',
|
|
380
|
+
methods: {
|
|
381
|
+
'onInput:': guarded('onInput'), 'onTick:': guarded('onTick'),
|
|
382
|
+
'onBall:': guarded('onBall'), 'onTreat:': guarded('onTreat'), 'onTug:': guarded('onTug'), 'onPick:': guarded('onPick'),
|
|
383
|
+
'onPause:': guarded('onPause'), 'onQuit:': guarded('onQuit'),
|
|
384
|
+
'onRefresh:': guarded('onRefresh'), 'onAttach:': guarded('onAttach'), 'onCancel:': guarded('onCancel'),
|
|
385
|
+
'windowWillClose:': guarded('onWindowWillClose')
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function fail(error) {
|
|
391
|
+
try { emit({ type: 'error', message: String(error && error.message || error) }); } catch (ignored) {}
|
|
392
|
+
if (shell && shell.core) shell.core.quit(); else $.exit(1);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function startCompanion(testMode) {
|
|
396
|
+
var app = $.NSApplication.sharedApplication;
|
|
397
|
+
app.setActivationPolicy(ACTIVATION_ACCESSORY);
|
|
398
|
+
registerClasses();
|
|
399
|
+
var me = ownPid(), buffer = $.NSMutableData.data, newline = $('\n').dataUsingEncoding($.NSUTF8StringEncoding);
|
|
400
|
+
var input = $.NSFileHandle.fileHandleWithStandardInput, timer = null, picker = null, pickerItems = [], pickerList = null;
|
|
401
|
+
var announced = false, testTarget = null, statusItem = null, ballButton = null, statusLabel = null, attachedPid = 0;
|
|
402
|
+
var readModes = $([$.NSDefaultRunLoopMode, $.NSEventTrackingRunLoopMode, $.NSModalPanelRunLoopMode]);
|
|
403
|
+
var readNote = $.NSFileHandleReadCompletionNotification || $('NSFileHandleReadCompletionNotification');
|
|
404
|
+
var dataKey = $.NSFileHandleNotificationDataItem || $('NSFileHandleNotificationDataItem');
|
|
405
|
+
shell = { controller: $.RetrieviewerController.alloc.init };
|
|
406
|
+
var pet = makePetPanel();
|
|
407
|
+
var bar = makePanel({ x: 0, y: 0, width: BAR_WIDTH, height: BAR_HEIGHT }, STYLE_BORDERLESS | STYLE_NONACTIVATING);
|
|
408
|
+
bar.setOpaque(false);
|
|
409
|
+
bar.setBackgroundColor($.NSColor.colorWithCalibratedRedGreenBlueAlpha(28 / 255, 30 / 255, 34 / 255, 0.94));
|
|
410
|
+
bar.setFloatingPanel(true); bar.setBecomesKeyOnlyIfNeeded(true); bar.setLevel(FLOATING_LEVEL); bar.setCollectionBehavior(OVERLAY_SPACES);
|
|
411
|
+
var content = bar.contentView;
|
|
412
|
+
ballButton = makeButton('\uACF5', { x: 8, y: 6, width: 40, height: 28 }, 'onBall:');
|
|
413
|
+
content.addSubview(ballButton);
|
|
414
|
+
content.addSubview(makeButton('\uAC04\uC2DD', { x: 52, y: 6, width: 46, height: 28 }, 'onTreat:'));
|
|
415
|
+
content.addSubview(makeButton('\uD130\uADF8', { x: 102, y: 6, width: 46, height: 28 }, 'onTug:'));
|
|
416
|
+
content.addSubview(makeButton('\uCC3D', { x: 152, y: 6, width: 40, height: 28 }, 'onPick:'));
|
|
417
|
+
content.addSubview(makeButton('\uC27C', { x: 196, y: 6, width: 40, height: 28 }, 'onPause:'));
|
|
418
|
+
content.addSubview(makeButton('\uC885\uB8CC', { x: 240, y: 6, width: 46, height: 28 }, 'onQuit:'));
|
|
419
|
+
statusLabel = makeLabel(TEXT.preparing, { x: 292, y: 10, width: 108, height: 20 }, $.NSColor.whiteColor);
|
|
420
|
+
content.addSubview(statusLabel);
|
|
421
|
+
|
|
422
|
+
// Menu bar item: the macOS counterpart of the Windows tray icon.
|
|
423
|
+
statusItem = $.NSStatusBar.systemStatusBar.statusItemWithLength(-1);
|
|
424
|
+
statusItem.button.setTitle($('\u28BF'));
|
|
425
|
+
statusItem.button.setToolTip($('Retrieviewer'));
|
|
426
|
+
var menu = $.NSMenu.alloc.initWithTitle($('Retrieviewer'));
|
|
427
|
+
[['\uB2E4\uB978 \uCC3D \uC120\uD0DD', 'onPick:'], ['\uC228\uAE30\uAE30 / \uB2E4\uC2DC \uD45C\uC2DC', 'onPause:'], ['\uC885\uB8CC', 'onQuit:']].forEach(function (entry) {
|
|
428
|
+
var item = $.NSMenuItem.alloc.initWithTitleActionKeyEquivalent($(entry[0]), entry[1], $(''));
|
|
429
|
+
item.target = shell.controller;
|
|
430
|
+
menu.addItem(item);
|
|
431
|
+
});
|
|
432
|
+
statusItem.setMenu(menu);
|
|
433
|
+
|
|
434
|
+
function placeBar(canvas) {
|
|
435
|
+
var rect = { x: canvas.x + canvas.width - BAR_WIDTH - 10, y: canvas.y + 10, width: BAR_WIDTH, height: BAR_HEIGHT };
|
|
436
|
+
bar.setFrameDisplay(nsRect(cgToCocoa(rect, primaryHeight())), true);
|
|
437
|
+
if (!bar.isVisible) bar.orderFrontRegardless;
|
|
438
|
+
}
|
|
439
|
+
var core = createCore({
|
|
440
|
+
emit: emit,
|
|
441
|
+
observe: function (target) {
|
|
442
|
+
var info = windowById(target.id), result = { info: info, frontPid: -1, covered: false };
|
|
443
|
+
if (info && info.onscreen && !testMode) {
|
|
444
|
+
result.frontPid = frontPid();
|
|
445
|
+
if (result.frontPid === target.pid) result.covered = coveredBySameApp(windowInfos(CG_ON_SCREEN_ABOVE | CG_EXCLUDE_DESKTOP, target.id), target);
|
|
446
|
+
}
|
|
447
|
+
return result;
|
|
448
|
+
},
|
|
449
|
+
paint: function (parsed, cell, canvas) { paintInto(pet, parsed, cell, canvas); },
|
|
450
|
+
hidePet: function () { if (pet.panel.isVisible) { pet.panel.orderOut(null); pet.view.setImage(null); } },
|
|
451
|
+
showBar: placeBar,
|
|
452
|
+
hideBar: function () { hidePanel(bar); },
|
|
453
|
+
status: function (text) { statusLabel.setStringValue($(text)); },
|
|
454
|
+
loaded: function () { if (testMode) ballButton.performClick(null); },
|
|
455
|
+
quit: function () {
|
|
456
|
+
if (timer) timer.invalidate;
|
|
457
|
+
$.NSNotificationCenter.defaultCenter.removeObserver(shell.controller);
|
|
458
|
+
if (picker) { picker.setDelegate(null); picker.orderOut(null); }
|
|
459
|
+
pet.panel.orderOut(null); bar.orderOut(null);
|
|
460
|
+
if (testTarget) testTarget.orderOut(null);
|
|
461
|
+
if (statusItem) $.NSStatusBar.systemStatusBar.removeStatusItem(statusItem);
|
|
462
|
+
try { emit({ type: 'quit' }); } catch (ignored) {}
|
|
463
|
+
$.exit(0);
|
|
464
|
+
}
|
|
465
|
+
}, { testMode: testMode });
|
|
466
|
+
shell.core = core;
|
|
467
|
+
|
|
468
|
+
function refreshPicker() {
|
|
469
|
+
pickerItems = pickerTargets(windowInfos(CG_ON_SCREEN_ONLY | CG_EXCLUDE_DESKTOP, 0), me);
|
|
470
|
+
pickerList.removeAllItems;
|
|
471
|
+
for (var i = 0; i < pickerItems.length; i++) pickerList.addItemWithTitle($(pickerItems[i].title));
|
|
472
|
+
}
|
|
473
|
+
function choose() {
|
|
474
|
+
if (picker || core.state.quitting) return;
|
|
475
|
+
core.setPicking(true); core.track(true);
|
|
476
|
+
picker = makePanel({ x: 0, y: 0, width: 650, height: 230 }, STYLE_TITLED | STYLE_CLOSABLE);
|
|
477
|
+
picker.setTitle($('Retrieviewer \u00B7 \uD568\uAED8 \uC788\uC744 \uCC3D'));
|
|
478
|
+
picker.setLevel(FLOATING_LEVEL);
|
|
479
|
+
picker.setDelegate(shell.controller);
|
|
480
|
+
var view = picker.contentView;
|
|
481
|
+
view.addSubview(makeLabel('Codex\uB97C \uC0AC\uC6A9\uD558\uB294 \uD130\uBBF8\uB110 \uCC3D\uC744 \uC120\uD0DD\uD558\uC138\uC694.\n' +
|
|
482
|
+
'\uB0B4\uC6A9\uC744 \uC77D\uC9C0 \uC54A\uACE0 \uCC3D\uC758 \uC704\uCE58\u00B7\uD06C\uAE30\uB9CC \uB530\uB77C\uAC11\uB2C8\uB2E4. \uD0ED\uC740 \uAD6C\uBCC4\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.\n' +
|
|
483
|
+
'\uD654\uBA74 \uAE30\uB85D \uAD8C\uD55C\uC774 \uC5C6\uC73C\uBA74 \uC81C\uBAA9 \uB300\uC2E0 \uC571 \uC774\uB984\uACFC \uCC3D \uBC88\uD638\uAC00 \uBCF4\uC785\uB2C8\uB2E4.',
|
|
484
|
+
{ x: 18, y: 150, width: 614, height: 64 }, null));
|
|
485
|
+
pickerList = $.NSPopUpButton.alloc.initWithFramePullsDown($.NSMakeRect(18, 106, 600, 28), false);
|
|
486
|
+
view.addSubview(pickerList);
|
|
487
|
+
view.addSubview(makeButton('\uC0C8\uB85C \uACE0\uCE68', { x: 18, y: 24, width: 100, height: 34 }, 'onRefresh:'));
|
|
488
|
+
view.addSubview(makeButton('\uC774 \uCC3D\uC5D0 \uBD99\uC774\uAE30', { x: 378, y: 24, width: 140, height: 34 }, 'onAttach:'));
|
|
489
|
+
view.addSubview(makeButton('\uCDE8\uC18C', { x: 528, y: 24, width: 90, height: 34 }, 'onCancel:'));
|
|
490
|
+
refreshPicker();
|
|
491
|
+
picker.center;
|
|
492
|
+
app.activateIgnoringOtherApps(true);
|
|
493
|
+
picker.makeKeyAndOrderFront(null);
|
|
494
|
+
emit({ type: 'picker', visible: picker.isVisible });
|
|
495
|
+
}
|
|
496
|
+
function pickerClosed() {
|
|
497
|
+
if (!picker) return;
|
|
498
|
+
picker.setDelegate(null); picker = null; pickerList = null; core.setPicking(false);
|
|
499
|
+
emit({ type: 'picker', visible: false });
|
|
500
|
+
if (core.state.quitting) return;
|
|
501
|
+
if (!core.state.target) statusLabel.setStringValue($(TEXT.chooseFromMenu));
|
|
502
|
+
statusItem.button.setToolTip($(core.state.target ? 'Retrieviewer \u00B7 \uCC3D\uC5D0 \uBD99\uC5B4 \uC788\uC74C' : 'Retrieviewer \u00B7 \uCC3D \uC120\uD0DD'));
|
|
503
|
+
// Hand focus back: to the window the user just chose, otherwise to whoever had it.
|
|
504
|
+
var chosen = attachedPid ? $.NSRunningApplication.runningApplicationWithProcessIdentifier(attachedPid) : null;
|
|
505
|
+
attachedPid = 0;
|
|
506
|
+
if (chosen && !chosen.isNil()) chosen.activateWithOptions(0); else app.deactivate;
|
|
507
|
+
core.track(true);
|
|
508
|
+
}
|
|
509
|
+
function readMore() { input.readInBackgroundAndNotifyForModes(readModes); }
|
|
510
|
+
|
|
511
|
+
shell.onInput = function (note) {
|
|
512
|
+
var data = note.userInfo.objectForKey(dataKey);
|
|
513
|
+
if (!data || data.isNil() || data.length === 0) { core.quit(); return; } // EOF: parent is gone.
|
|
514
|
+
buffer.appendData(data);
|
|
515
|
+
for (;;) {
|
|
516
|
+
var length = buffer.length;
|
|
517
|
+
var found = length ? buffer.rangeOfDataOptionsRange(newline, 0, $.NSMakeRange(0, length)) : null;
|
|
518
|
+
if (!found || found.location >= length) break;
|
|
519
|
+
var line = $.NSString.alloc.initWithDataEncoding(buffer.subdataWithRange($.NSMakeRange(0, found.location)), $.NSUTF8StringEncoding);
|
|
520
|
+
buffer = $.NSMutableData.dataWithData(buffer.subdataWithRange($.NSMakeRange(found.location + 1, length - found.location - 1)));
|
|
521
|
+
if (!line || line.isNil()) throw new Error('Overlay input is not UTF-8');
|
|
522
|
+
var text = ObjC.unwrap(line);
|
|
523
|
+
if (text.length) core.message(JSON.parse(text));
|
|
524
|
+
if (core.state.quitting) return;
|
|
525
|
+
}
|
|
526
|
+
if (buffer.length > MAX_LINE_BYTES) throw new Error('Oversized overlay input line');
|
|
527
|
+
readMore();
|
|
528
|
+
};
|
|
529
|
+
shell.onTick = function () {
|
|
530
|
+
if (!announced) {
|
|
531
|
+
announced = true;
|
|
532
|
+
if (!testMode) choose();
|
|
533
|
+
emit({ type: 'ready', pickerVisible: !!(picker && picker.isVisible) });
|
|
534
|
+
}
|
|
535
|
+
core.track(false);
|
|
536
|
+
};
|
|
537
|
+
shell.onBall = function () { core.interact('ball'); };
|
|
538
|
+
shell.onTreat = function () { core.interact('treat'); };
|
|
539
|
+
shell.onTug = function () { core.interact('tug'); };
|
|
540
|
+
shell.onPick = function () { choose(); };
|
|
541
|
+
shell.onPause = function () { core.togglePause(); };
|
|
542
|
+
shell.onQuit = function () { core.quit(); };
|
|
543
|
+
shell.onRefresh = function () { if (picker) refreshPicker(); };
|
|
544
|
+
shell.onAttach = function () {
|
|
545
|
+
if (!picker) return;
|
|
546
|
+
var index = pickerList.indexOfSelectedItem;
|
|
547
|
+
if (index < 0 || index >= pickerItems.length) return;
|
|
548
|
+
var item = pickerItems[index];
|
|
549
|
+
core.attach({ id: item.id, pid: item.pid, title: item.title });
|
|
550
|
+
attachedPid = item.pid;
|
|
551
|
+
picker.close; // windowWillClose: finishes the hand-off.
|
|
552
|
+
};
|
|
553
|
+
shell.onCancel = function () { if (picker) picker.close; };
|
|
554
|
+
shell.onWindowWillClose = function () { pickerClosed(); };
|
|
555
|
+
|
|
556
|
+
if (testMode) {
|
|
557
|
+
// Diagnostics follow only an owned, off-screen window.
|
|
558
|
+
testTarget = makePanel({ x: -12000, y: -12000, width: 1280, height: 800 }, STYLE_BORDERLESS | STYLE_NONACTIVATING);
|
|
559
|
+
testTarget.orderFrontRegardless;
|
|
560
|
+
core.attach({ id: testTarget.windowNumber, pid: me, title: 'owned diagnostic window' });
|
|
561
|
+
}
|
|
562
|
+
$.NSNotificationCenter.defaultCenter.addObserverSelectorNameObject(shell.controller, 'onInput:', readNote, input);
|
|
563
|
+
readMore();
|
|
564
|
+
timer = $.NSTimer.timerWithTimeIntervalTargetSelectorUserInfoRepeats(0.05, shell.controller, 'onTick:', null, true);
|
|
565
|
+
$.NSRunLoop.mainRunLoop.addTimerForMode(timer, $.NSRunLoopCommonModes);
|
|
566
|
+
app.run;
|
|
567
|
+
return 0;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// Owned windows only: never clicks, captures, focuses or moves a user application.
|
|
571
|
+
function selfTest(proofPath) {
|
|
572
|
+
var app = $.NSApplication.sharedApplication;
|
|
573
|
+
app.setActivationPolicy(ACTIVATION_ACCESSORY);
|
|
574
|
+
function pump() { $.NSRunLoop.currentRunLoop.runUntilDate($.NSDate.dateWithTimeIntervalSinceNow(0.25)); }
|
|
575
|
+
var frontBefore = frontPid(), result = { type: 'self-test' };
|
|
576
|
+
var target = makePanel({ x: -12000, y: -12000, width: 1600, height: 1000 }, STYLE_BORDERLESS | STYLE_NONACTIVATING);
|
|
577
|
+
var pet = makePetPanel();
|
|
578
|
+
try {
|
|
579
|
+
target.orderFrontRegardless; pump();
|
|
580
|
+
var info = windowById(target.windowNumber), height = primaryHeight();
|
|
581
|
+
result.windowList = !!info;
|
|
582
|
+
var expected = rectFromStruct(target.frame);
|
|
583
|
+
result.geometryConsistent = !!info && sameRect(cgToCocoa(info.bounds, height), expected);
|
|
584
|
+
var frame = { type: 'frame', revision: 1, x: 2, y: 1, columns: 3, rows: 2, text: '\u28FF\u2800\u2847\n\u2800\u28B8\u28FF' };
|
|
585
|
+
var parsed = parseFrame(frame, 12, info ? info.bounds : null);
|
|
586
|
+
var painted = paintInto(pet, parsed, 12, info.bounds);
|
|
587
|
+
result.dots = painted.raster.dots;
|
|
588
|
+
var rep = $.NSBitmapImageRep.imageRepWithData(painted.data);
|
|
589
|
+
result.bitmapDecoded = !!rep && !rep.isNil() && rep.pixelsWide === painted.raster.width && rep.pixelsHigh === painted.raster.height;
|
|
590
|
+
var scale = painted.raster.width / painted.rect.width;
|
|
591
|
+
result.inkAtDot = result.bitmapDecoded && rep.colorAtXY(Math.floor(3 * scale), Math.floor(3 * scale)).alphaComponent > 0.5;
|
|
592
|
+
result.clearBetweenDots = result.bitmapDecoded && rep.colorAtXY(Math.floor(18 * scale), Math.floor(6 * scale)).alphaComponent === 0;
|
|
593
|
+
result.followGeometry = sameRect(cocoaToCg(rectFromStruct(pet.panel.frame), height), petRect(info.bounds, parsed, 12));
|
|
594
|
+
result.clickThrough = pet.panel.ignoresMouseEvents === true;
|
|
595
|
+
result.nonActivating = (pet.panel.styleMask & STYLE_NONACTIVATING) !== 0;
|
|
596
|
+
result.neverKey = pet.panel.canBecomeKeyWindow === false && pet.panel.canBecomeMainWindow === false;
|
|
597
|
+
result.transparent = pet.panel.isOpaque === false && pet.panel.hasShadow === false;
|
|
598
|
+
target.setFrameDisplay($.NSMakeRect(-11000, -11500, 1800, 1100), true); pump();
|
|
599
|
+
var moved = windowById(target.windowNumber);
|
|
600
|
+
paintInto(pet, parsed, 12, moved.bounds);
|
|
601
|
+
result.followsMove = !!moved && sameRect(cocoaToCg(rectFromStruct(pet.panel.frame), height), petRect(moved.bounds, parsed, 12));
|
|
602
|
+
target.orderOut(null); pump();
|
|
603
|
+
var hidden = windowById(target.windowNumber);
|
|
604
|
+
result.hiddenDetected = !hidden || !hidden.onscreen;
|
|
605
|
+
hidePanel(pet.panel);
|
|
606
|
+
result.petHidden = pet.panel.isVisible === false;
|
|
607
|
+
result.foregroundPreserved = frontPid() === frontBefore;
|
|
608
|
+
if (proofPath) result.proofWritten = painted.data.writeToFileAtomically($(proofPath), true) === true;
|
|
609
|
+
} catch (error) {
|
|
610
|
+
result.error = String(error && error.message || error);
|
|
611
|
+
} finally {
|
|
612
|
+
target.orderOut(null); pet.panel.orderOut(null);
|
|
613
|
+
}
|
|
614
|
+
var checks = ['windowList', 'geometryConsistent', 'bitmapDecoded', 'inkAtDot', 'clearBetweenDots', 'followGeometry', 'clickThrough',
|
|
615
|
+
'nonActivating', 'neverKey', 'transparent', 'followsMove', 'hiddenDetected', 'petHidden', 'foregroundPreserved'];
|
|
616
|
+
result.passed = !result.error && result.dots > 0 && checks.every(function (key) { return result[key] === true; }) && (!proofPath || result.proofWritten === true);
|
|
617
|
+
emit(result);
|
|
618
|
+
return result.passed ? 0 : 1;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function run(argv) {
|
|
622
|
+
var code = 1;
|
|
623
|
+
try {
|
|
624
|
+
ObjC.import('Cocoa');
|
|
625
|
+
ObjC.import('CoreGraphics');
|
|
626
|
+
ObjC.import('stdlib');
|
|
627
|
+
ObjC.bindFunction('CFRelease', ['void', ['void *']]);
|
|
628
|
+
var args = [];
|
|
629
|
+
for (var i = 0; i < argv.length; i++) args.push(String(argv[i]));
|
|
630
|
+
if (args[0] === '--self-test' && args.length <= 2) code = selfTest(args[1] || null);
|
|
631
|
+
else if (args.length === 0 || (args.length === 1 && args[0] === '--ipc-test')) code = startCompanion(args[0] === '--ipc-test');
|
|
632
|
+
else throw new Error('Unsupported native painter argument');
|
|
633
|
+
} catch (error) {
|
|
634
|
+
try { emit({ type: 'error', message: String(error && error.message || error) }); } catch (ignored) {}
|
|
635
|
+
code = 1;
|
|
636
|
+
}
|
|
637
|
+
// Exit explicitly so osascript never prints a script result onto the protocol stream.
|
|
638
|
+
$.exit(code);
|
|
639
|
+
}
|
|
@@ -11,7 +11,7 @@ export const HEARTBEAT_MS=5000;
|
|
|
11
11
|
// Bounded so the host prompt stays usable: at most 64x12 cells, hidden when the
|
|
12
12
|
// terminal is too small for a legible pet.
|
|
13
13
|
export const LIMITS=Object.freeze({maxColumns:64,maxRows:12,minColumns:20,minRows:5,sideMargin:4,reservedRows:14});
|
|
14
|
-
export const COMMANDS=Object.freeze(['enable','disable','ball','treat','status']);
|
|
14
|
+
export const COMMANDS=Object.freeze(['enable','disable','ball','treat','tug','status']);
|
|
15
15
|
|
|
16
16
|
const fn=(value,name)=>{if(typeof value!=='function')throw TypeError(`${name} must be a function`);};
|
|
17
17
|
const defaultScheduler=()=>({now:()=>performance.now(),schedule:(callback,delayMs)=>setTimeout(callback,delayMs),cancel:handle=>clearTimeout(handle)});
|
|
@@ -133,7 +133,7 @@ export function createOpenCodePetController({hostVersion='unknown',scheduler,fps
|
|
|
133
133
|
enabled=value;reconcile();
|
|
134
134
|
}
|
|
135
135
|
function interact(kind){
|
|
136
|
-
if(
|
|
136
|
+
if(!['ball','treat','tug'].includes(kind))throw TypeError("kind must be 'ball', 'treat' or 'tug'");
|
|
137
137
|
return plugin?plugin.interact(kind):false;
|
|
138
138
|
}
|
|
139
139
|
function status(){
|
|
@@ -168,11 +168,11 @@ export function createOpenCodePetController({hostVersion='unknown',scheduler,fps
|
|
|
168
168
|
setEnabled,
|
|
169
169
|
interact,
|
|
170
170
|
status,
|
|
171
|
-
// Slash handler: '/retrieviewer <enable|disable|ball|treat|status>'.
|
|
171
|
+
// Slash handler: '/retrieviewer <enable|disable|ball|treat|tug|status>'.
|
|
172
172
|
async command(argument){
|
|
173
173
|
const word=String(argument??'').trim().toLowerCase()||'status';
|
|
174
174
|
if(word==='enable'||word==='disable'){await setEnabled(word==='enable');return word==='enable'?'Retrieviewer enabled':'Retrieviewer disabled';}
|
|
175
|
-
if(word==='ball'||word==='treat'){
|
|
175
|
+
if(word==='ball'||word==='treat'||word==='tug'){
|
|
176
176
|
if(!plugin)return enabled?'Retrieviewer is still loading':'Retrieviewer is disabled; run /retrieviewer enable';
|
|
177
177
|
return interact(word)?`Retrieviewer: ${word} accepted`:`Retrieviewer is busy; ${word} not accepted`;
|
|
178
178
|
}
|