@overmvp/kumi 0.1.0 → 0.4.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 +59 -6
- package/animation/index.ts +4 -0
- package/animation/motion-policy.ts +20 -0
- package/animation/slide.ts +61 -0
- package/animation/spring.ts +75 -0
- package/animation/staggered-reveal.ts +34 -0
- package/builder/css-gradients.mjs +74 -0
- package/builder/css-mask-assets.mjs +52 -0
- package/builder/css-mask-assets.test.mjs +31 -0
- package/builder/css-v1.mjs +127 -23
- package/builder/css-v1.test.mjs +82 -2
- package/builder/link-addon-package.mjs +47 -6
- package/builder/module-declarations.test.mjs +9 -18
- package/builder/native-kernels.mjs +1 -1
- package/builder/src/compiler.rs +205 -8
- package/builder/src/lua_upvalues.rs +641 -0
- package/builder/src/main.rs +20 -5
- package/builder/src/native_ir.rs +1 -1
- package/builder/src/native_signal.rs +46 -10
- package/builder/src/numbers.lua +14 -0
- package/builder/src/project-front.mjs +385 -34
- package/builder/src/routes.rs +11 -14
- package/builder/src/setup-store.lua +18 -0
- package/builder/src/signal-kernel.fingerprint +1 -1
- package/builder/src/ts-lower.mjs +2 -2
- package/builder/src/wow-reads.lua +22 -0
- package/builder/style-modules.mjs +111 -0
- package/builder/style-modules.test.mjs +24 -0
- package/builder/style-states.mjs +6 -4
- package/config.ts +56 -14
- package/eslint.mjs +74 -0
- package/form/index.ts +15 -11
- package/package.json +11 -7
- package/router/index.ts +10 -2
- package/router/link.tsx +32 -0
- package/router/navigation.ts +22 -0
- package/router/router-view.ts +134 -0
- package/scripts/addon-build.mjs +377 -0
- package/scripts/addon-project.mjs +89 -0
- package/scripts/kumi-cli.mjs +52 -17
- package/scripts/link-addons.mjs +12 -2
- package/src/bindings.ts +12 -6
- package/src/context.ts +31 -7
- package/src/css-tokens.ts +27 -13
- package/src/css-v1.ts +13 -0
- package/src/elements.ts +35 -0
- package/src/flex-layout.ts +26 -5
- package/src/frame-scheduler.ts +6 -2
- package/src/index.ts +2 -1
- package/src/jsx-runtime.ts +8 -1
- package/src/keyed-list.ts +17 -11
- package/src/module-ui.ts +163 -0
- package/src/module.ts +51 -8
- package/src/owned-collections.ts +8 -0
- package/src/providers.ts +7 -1
- package/src/reactive-scope.ts +3 -3
- package/src/reactivity.ts +42 -8
- package/src/result.ts +6 -0
- package/src/signal-kernel.ts +35 -2
- package/src/style-classes.ts +22 -1
- package/src/style-states.ts +13 -6
- package/state/index.ts +6 -0
- package/state/setup-store-persistence.ts +206 -0
- package/state/setup-store-view.ts +10 -0
- package/state/setup-store.ts +342 -0
- package/state/store.ts +2 -0
- package/templates/addon/.agents/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.agents/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.agents/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.agents/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.agents/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/.claude/skills/kumi-build-debug/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-feature/SKILL.md +50 -0
- package/templates/addon/.claude/skills/kumi-plugin/SKILL.md +36 -0
- package/templates/addon/.claude/skills/kumi-store/SKILL.md +47 -0
- package/templates/addon/.claude/skills/kumi-ui/SKILL.md +73 -0
- package/templates/addon/.claude/skills/kumi-wow-api/SKILL.md +30 -0
- package/templates/addon/AGENTS.md +34 -0
- package/templates/addon/Assets/Art/Corner10.tga +0 -0
- package/templates/addon/Assets/Art/Corner11.tga +0 -0
- package/templates/addon/Assets/Art/Corner12.tga +0 -0
- package/templates/addon/Assets/Art/Corner13.tga +0 -0
- package/templates/addon/Assets/Art/Corner14.tga +0 -0
- package/templates/addon/Assets/Art/Corner15.tga +0 -0
- package/templates/addon/Assets/Art/Corner16.tga +0 -0
- package/templates/addon/Assets/Art/Corner2.tga +0 -0
- package/templates/addon/Assets/Art/Corner3.tga +0 -0
- package/templates/addon/Assets/Art/Corner4.tga +0 -0
- package/templates/addon/Assets/Art/Corner5.tga +0 -0
- package/templates/addon/Assets/Art/Corner6.tga +0 -0
- package/templates/addon/Assets/Art/Corner7.tga +0 -0
- package/templates/addon/Assets/Art/Corner8.tga +0 -0
- package/templates/addon/Assets/Art/Corner9.tga +0 -0
- package/templates/addon/Assets/Art/Dot.tga +0 -0
- package/templates/addon/Assets/Art/Gear.tga +0 -0
- package/templates/addon/Assets/Art/Grip.tga +0 -0
- package/templates/addon/Assets/Art/Outline10.tga +0 -0
- package/templates/addon/Assets/Art/Outline12.tga +0 -0
- package/templates/addon/Assets/Art/Outline13.tga +0 -0
- package/templates/addon/Assets/Art/Outline14.tga +0 -0
- package/templates/addon/Assets/Art/Outline15.tga +0 -0
- package/templates/addon/Assets/Art/Outline2.tga +0 -0
- package/templates/addon/Assets/Art/Outline3.tga +0 -0
- package/templates/addon/Assets/Art/Outline5.tga +0 -0
- package/templates/addon/Assets/Art/Outline7.tga +0 -0
- package/templates/addon/Assets/Art/Outline9.tga +0 -0
- package/templates/addon/Assets/Art/Round11.tga +0 -0
- package/templates/addon/Assets/Art/Round11Border.tga +0 -0
- package/templates/addon/Assets/Art/Round4.tga +0 -0
- package/templates/addon/Assets/Art/Round4Border.tga +0 -0
- package/templates/addon/Assets/Art/Round6.tga +0 -0
- package/templates/addon/Assets/Art/Round6Border.tga +0 -0
- package/templates/addon/Assets/Art/Round8.tga +0 -0
- package/templates/addon/Assets/Art/Round8Border.tga +0 -0
- package/templates/addon/Assets/Art/Search.tga +0 -0
- package/templates/addon/CLAUDE.md +1 -0
- package/templates/addon/README.md +42 -7
- package/templates/addon/eslint.config.mjs +3 -9
- package/templates/addon/gitignore +1 -0
- package/templates/addon/kumi.config.ts +17 -0
- package/templates/addon/package.json +4 -5
- package/templates/addon/src/app/app.module.ts +18 -0
- package/templates/addon/src/app/commands.store.ts +11 -0
- package/templates/addon/src/app/layout/AppWindow.module.css +90 -0
- package/templates/addon/src/app/layout/AppWindow.tsx +32 -0
- package/templates/addon/src/app/main.ts +5 -0
- package/templates/addon/src/app/routes/(window)/home/page.tsx +8 -0
- package/templates/addon/src/app/routes/(window)/plugins/page.tsx +38 -0
- package/templates/addon/src/app/routes/(window)/settings/page.tsx +8 -0
- package/templates/addon/src/app/theme.ts +6 -0
- package/templates/addon/src/modules/greeting/api/player.api.ts +29 -0
- package/templates/addon/src/modules/greeting/greeting.module.ts +18 -0
- package/templates/addon/src/modules/greeting/model/greeting.store.ts +81 -0
- package/templates/addon/src/modules/greeting/services/greeting.service.ts +38 -0
- package/templates/addon/src/modules/greeting/ui/Greeting.module.css +103 -0
- package/templates/addon/src/modules/greeting/ui/GreetingCard.tsx +29 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingHud.tsx +54 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingOverview.tsx +18 -0
- package/templates/addon/src/modules/greeting/widgets/GreetingSettings.tsx +56 -0
- package/templates/addon/src/modules/playtime/api/clock.api.ts +6 -0
- package/templates/addon/src/modules/playtime/model/playtime.store.ts +19 -0
- package/templates/addon/src/modules/playtime/playtime.module.ts +18 -0
- package/templates/addon/src/modules/playtime/services/playtime.service.ts +18 -0
- package/templates/addon/src/modules/playtime/ui/Playtime.module.css +23 -0
- package/templates/addon/src/modules/playtime/ui/PlaytimeBadge.tsx +10 -0
- package/templates/addon/src/modules/playtime/widgets/PlaytimePage.tsx +16 -0
- package/templates/addon/src/shared/api/native-art.ts +28 -0
- package/templates/addon/src/shared/assets/close.png +0 -0
- package/templates/addon/src/shared/lib/format.ts +20 -0
- package/templates/addon/src/shared/styles/tokens.css +13 -0
- package/templates/addon/src/shared/ui/Button.tsx +29 -0
- package/templates/addon/src/shared/ui/Choice.tsx +34 -0
- package/templates/addon/src/shared/ui/Controls.module.css +91 -0
- package/templates/addon/src/shared/ui/Glyph.tsx +18 -0
- package/templates/addon/src/shared/ui/Slider.tsx +25 -0
- package/templates/addon/src/shared/ui/Toggle.tsx +29 -0
- package/templates/addon/src/shared/ui/focus-ref.ts +7 -0
- package/templates/addon/src/shared/ui/range-skin.tsx +15 -0
- package/templates/addon/tsconfig.json +49 -10
- package/wow/action-bar-layout.ts +108 -0
- package/wow/action-button.ts +244 -0
- package/wow/action-catalog.ts +98 -0
- package/wow/addon-manifest.ts +38 -0
- package/wow/animation.ts +3 -14
- package/wow/app-ui.ts +230 -0
- package/wow/cooldown-timing.ts +24 -0
- package/wow/css-background-image.ts +75 -0
- package/wow/css-box.ts +46 -10
- package/wow/css-image-mask.ts +32 -0
- package/wow/css-surfaces.ts +295 -43
- package/wow/cursor.ts +45 -0
- package/wow/element-events.ts +33 -13
- package/wow/frame-access.ts +23 -1
- package/wow/frame-timing.ts +13 -0
- package/wow/heal-prediction.ts +2 -4
- package/wow/hooks.ts +133 -0
- package/wow/index.ts +19 -4
- package/wow/layout-view.ts +44 -23
- package/wow/locale-font.ts +15 -0
- package/wow/module-replacements.ts +103 -0
- package/wow/native.ts +18 -0
- package/wow/panel-host.ts +97 -0
- package/wow/pixel.ts +35 -0
- package/wow/plugins.ts +246 -0
- package/wow/pointer-click.ts +35 -0
- package/wow/protect.ts +27 -3
- package/wow/protected-view.ts +139 -0
- package/wow/range-art.ts +7 -0
- package/wow/readable-api.ts +120 -0
- package/wow/rounded-texture.ts +38 -6
- package/wow/saved-variables.ts +67 -18
- package/wow/spell-cooldown.ts +36 -0
- package/wow/start-addon.ts +31 -8
- package/wow/state-paint.ts +5 -14
- package/wow/texture-fill.ts +10 -0
- package/wow/unit-cast.ts +6 -4
- package/wow/view.ts +458 -228
- package/templates/addon/__ADDON_NAME__.toc +0 -4
- package/templates/addon/scripts/build.mjs +0 -25
- package/templates/addon/src/app/main.tsx +0 -13
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ModuleReplacement } from "../src/module-ui";
|
|
2
|
+
import { ownedMap, ownedSet, type OwnedReadonlyArray } from "../src/owned-collections";
|
|
3
|
+
import { fail, ok, type Failure, type Result } from "../src/result";
|
|
4
|
+
import type { Runtime, RuntimeScope } from "../src/runtime";
|
|
5
|
+
import { protect } from "./protect";
|
|
6
|
+
import { createProtectedLayoutUpdate, type ProtectedLayoutUpdate } from "./protected-layout";
|
|
7
|
+
|
|
8
|
+
const restoring = ownedMap<string, ProtectedLayoutUpdate>();
|
|
9
|
+
|
|
10
|
+
function runAdapter(id: string, index: number, action: "disable" | "restore", run: ModuleReplacement["disable"]): Result<void> {
|
|
11
|
+
const called = protect(run);
|
|
12
|
+
const result = called.ok ? called.value ?? ok(undefined) : called;
|
|
13
|
+
return result.ok ? result : {
|
|
14
|
+
ok: false,
|
|
15
|
+
reason: "Module " + id + ": " + action + " replacement " + (index + 1) + ": " + result.reason,
|
|
16
|
+
trace: result.trace,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function combine(first: Result<void>, second: Result<void>): Result<void> {
|
|
21
|
+
if (first.ok) return second;
|
|
22
|
+
return second.ok ? first : { ok: false, reason: first.reason + "\n" + second.reason, trace: first.trace ?? second.trace };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Pair native frame takeover with a fully mounted batch of module views. */
|
|
26
|
+
export function mountModuleReplacements(this: void, runtime: Runtime, owner: RuntimeScope, id: string,
|
|
27
|
+
adapters: OwnedReadonlyArray<ModuleReplacement>, mount: (this: void, scope: RuntimeScope) => Result<void>): Result<void> {
|
|
28
|
+
let views: RuntimeScope | undefined;
|
|
29
|
+
let attempted = 0;
|
|
30
|
+
let activating = false;
|
|
31
|
+
let initialRequest = true;
|
|
32
|
+
|
|
33
|
+
function release() {
|
|
34
|
+
const mounted = views;
|
|
35
|
+
if (mounted === undefined || activating) return;
|
|
36
|
+
views = undefined;
|
|
37
|
+
const cleanup = runtime.scope();
|
|
38
|
+
const restored = ownedSet<number>();
|
|
39
|
+
const update = createProtectedLayoutUpdate(() => {
|
|
40
|
+
let result: Result<void> = ok(undefined);
|
|
41
|
+
for (let index = attempted - 1; index >= 0; index--) {
|
|
42
|
+
if (restored.has(index)) continue;
|
|
43
|
+
const step = runAdapter(id, index, "restore", adapters[index].restore);
|
|
44
|
+
if (step.ok) restored.add(index);
|
|
45
|
+
else result = combine(result, step);
|
|
46
|
+
}
|
|
47
|
+
if (!result.ok) return result;
|
|
48
|
+
const stopped = mounted.dispose();
|
|
49
|
+
restoring.delete(id);
|
|
50
|
+
cleanup.dispose();
|
|
51
|
+
if (!stopped.ok) return stopped;
|
|
52
|
+
}, { scope: cleanup, label: "Restore native UI for " + id });
|
|
53
|
+
if (!update.ok) {
|
|
54
|
+
cleanup.dispose();
|
|
55
|
+
return update;
|
|
56
|
+
}
|
|
57
|
+
restoring.set(id, update.value);
|
|
58
|
+
return update.value.request();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function mountAndDisable(mounted: RuntimeScope): Result<void> {
|
|
62
|
+
const started = protect(() => mount(mounted));
|
|
63
|
+
const result = started.ok ? started.value : started;
|
|
64
|
+
if (!result.ok) return result;
|
|
65
|
+
for (const adapter of adapters) {
|
|
66
|
+
if (!owner.isActive()) break;
|
|
67
|
+
const index = attempted++;
|
|
68
|
+
const disabled = runAdapter(id, index, "disable", adapter.disable);
|
|
69
|
+
if (!disabled.ok) return disabled;
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function activate(): Result<void> {
|
|
75
|
+
// An earlier unload can still be queued on the frame budget after combat.
|
|
76
|
+
const previous = restoring.get(id);
|
|
77
|
+
if (previous !== undefined) {
|
|
78
|
+
const restored = previous.request();
|
|
79
|
+
if (!restored.ok) return restored;
|
|
80
|
+
if (restoring.has(id)) return fail("Module " + id + ": previous replacement is still restoring");
|
|
81
|
+
}
|
|
82
|
+
if (!owner.isActive()) return ok(undefined);
|
|
83
|
+
const mounted = runtime.scope();
|
|
84
|
+
views = mounted;
|
|
85
|
+
activating = true;
|
|
86
|
+
const result = mountAndDisable(mounted);
|
|
87
|
+
activating = false;
|
|
88
|
+
return result.ok && owner.isActive() ? result : combine(result, release() ?? ok(undefined));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const cleanup = owner.onDispose(release);
|
|
92
|
+
if (!cleanup.ok) return cleanup;
|
|
93
|
+
const update = createProtectedLayoutUpdate((): Failure | void => {
|
|
94
|
+
const result = activate();
|
|
95
|
+
if (result.ok) return;
|
|
96
|
+
const rolledBack = initialRequest ? result : combine(result, owner.dispose());
|
|
97
|
+
if (!rolledBack.ok) return rolledBack;
|
|
98
|
+
}, { scope: owner, label: "Replace native UI for " + id });
|
|
99
|
+
if (!update.ok) return update;
|
|
100
|
+
const requested = update.value.request();
|
|
101
|
+
initialRequest = false;
|
|
102
|
+
return requested;
|
|
103
|
+
}
|
package/wow/native.ts
CHANGED
|
@@ -28,6 +28,24 @@ interface MerchantApi {
|
|
|
28
28
|
|
|
29
29
|
// Native globals omitted by Blizzard's generated API documentation.
|
|
30
30
|
interface LegacyGlobals {
|
|
31
|
+
GetCursorInfo(this: void): LuaMultiReturn<[kind?: string, first?: number, detail?: unknown, spellId?: number]>;
|
|
32
|
+
PlayerHasToy(this: void, itemID: number): boolean;
|
|
33
|
+
readonly C_ToyBox?: {
|
|
34
|
+
GetNumFilteredToys(this: void): number;
|
|
35
|
+
GetToyFromIndex(this: void, index: number): number;
|
|
36
|
+
GetToyInfo(this: void, itemID: number): LuaMultiReturn<[id?: number, name?: string, icon?: number]>;
|
|
37
|
+
};
|
|
38
|
+
GetFlyoutInfo?(this: void, flyoutID: number): LuaMultiReturn<[name?: string, description?: string, slots?: number, known?: boolean]>;
|
|
39
|
+
GetFlyoutSlotInfo?(this: void, flyoutID: number, index: number): LuaMultiReturn<[id?: number, override?: number, known?: boolean, name?: string]>;
|
|
40
|
+
readonly GameTooltip?: {
|
|
41
|
+
SetOwner(this: object, owner: FrameParent, anchor: string): void;
|
|
42
|
+
SetItemByID(this: object, itemId: number): void;
|
|
43
|
+
SetSpellByID(this: object, spellId: number): void;
|
|
44
|
+
SetToyByItemID?(this: object, itemId: number): boolean;
|
|
45
|
+
SetText(this: object, text: string): void;
|
|
46
|
+
Show(this: object): void;
|
|
47
|
+
Hide(this: object): void;
|
|
48
|
+
};
|
|
31
49
|
CreateFont(this: void, name: string): SimpleFont;
|
|
32
50
|
CreateColor?(this: void, red: number, green: number, blue: number, alpha: number): unknown;
|
|
33
51
|
readonly CurveConstants?: { readonly ScaleTo100?: Parameters<WoWGlobals["UnitHealthPercent"]>[2] };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ref, type ReadonlyRef } from "../src/reactivity";
|
|
2
|
+
import { fail, ok, type Result } from "../src/result";
|
|
3
|
+
import type { Runtime, RuntimeScope } from "../src/runtime";
|
|
4
|
+
import type { UIElement } from "../src/elements";
|
|
5
|
+
import type { EventApi } from "./contract";
|
|
6
|
+
import type { FrameStrata } from "./frame-layer";
|
|
7
|
+
import { readFrameHeight, readFrameShown, readFrameWidth } from "./frame-access";
|
|
8
|
+
import { createFrame, type Frame } from "./frames";
|
|
9
|
+
import { api } from "./native";
|
|
10
|
+
import { physicalPixel, snapPixel } from "./pixel";
|
|
11
|
+
import { unlockedActionSlot } from "./action-button";
|
|
12
|
+
import { mountNative, type NativeViewOptions } from "./view";
|
|
13
|
+
|
|
14
|
+
interface NativePanel {
|
|
15
|
+
readonly locked: ReadonlyRef<boolean>;
|
|
16
|
+
show(this: void): void;
|
|
17
|
+
hide(this: void): void;
|
|
18
|
+
isShown(this: void): boolean;
|
|
19
|
+
mount(this: void, runtime: Runtime, render: (this: void, scope: RuntimeScope) => UIElement,
|
|
20
|
+
options: NativeViewOptions): ReturnType<typeof mountNative>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Own a native parent from the first mount and center it on display metric changes. */
|
|
24
|
+
export function createNativePanel(this: void, scope: RuntimeScope, events: EventApi, width: number, height: number,
|
|
25
|
+
strata: FrameStrata, offsetY: number): Result<NativePanel> {
|
|
26
|
+
const locked = ref(!unlockedActionSlot());
|
|
27
|
+
const refreshCombat = () => { locked.value = !unlockedActionSlot(); };
|
|
28
|
+
const lockedEvent = events.on(scope, "PLAYER_REGEN_DISABLED", refreshCombat);
|
|
29
|
+
if (!lockedEvent.ok) return lockedEvent;
|
|
30
|
+
const unlockedEvent = events.on(scope, "PLAYER_REGEN_ENABLED", refreshCombat);
|
|
31
|
+
if (!unlockedEvent.ok) return unlockedEvent;
|
|
32
|
+
|
|
33
|
+
const parent = api.UIParent as Frame;
|
|
34
|
+
let host: Frame | undefined;
|
|
35
|
+
let panelWidth = width;
|
|
36
|
+
let anchorX: number | undefined, anchorY: number | undefined;
|
|
37
|
+
let centered: boolean | undefined;
|
|
38
|
+
function place(panel: Frame) {
|
|
39
|
+
const pixel = physicalPixel(panel);
|
|
40
|
+
const screenWidth = readFrameWidth(parent);
|
|
41
|
+
const screenHeight = readFrameHeight(parent);
|
|
42
|
+
const availableWidth = screenWidth === undefined || screenWidth <= 0 ? width : Math.min(width, screenWidth);
|
|
43
|
+
if (panelWidth !== availableWidth) {
|
|
44
|
+
panelWidth = availableWidth;
|
|
45
|
+
panel.SetWidth(panelWidth);
|
|
46
|
+
}
|
|
47
|
+
const center = screenWidth === undefined || screenHeight === undefined;
|
|
48
|
+
const x = center ? 0 : snapPixel((screenWidth - panelWidth) / 2, pixel);
|
|
49
|
+
const y = center ? offsetY : snapPixel((screenHeight - height) / 2 + offsetY, pixel);
|
|
50
|
+
if (center === centered && x === anchorX && y === anchorY) return;
|
|
51
|
+
const point = center ? "CENTER" : "BOTTOMLEFT";
|
|
52
|
+
panel.ClearAllPoints();
|
|
53
|
+
panel.SetPoint(point, parent, point, x, y);
|
|
54
|
+
centered = center;
|
|
55
|
+
anchorX = x;
|
|
56
|
+
anchorY = y;
|
|
57
|
+
}
|
|
58
|
+
function ensureHost(): Result<Frame> {
|
|
59
|
+
if (host !== undefined) return ok(host);
|
|
60
|
+
return scope.protect(() => {
|
|
61
|
+
const panel = createFrame("Frame", undefined, parent);
|
|
62
|
+
panel.Hide();
|
|
63
|
+
panel.SetFrameStrata(strata);
|
|
64
|
+
panel.SetClampedToScreen(true);
|
|
65
|
+
panel.SetSize(width, height);
|
|
66
|
+
panelWidth = width;
|
|
67
|
+
place(panel);
|
|
68
|
+
host = panel;
|
|
69
|
+
return panel;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function refreshPosition() {
|
|
73
|
+
if (host !== undefined) place(host);
|
|
74
|
+
}
|
|
75
|
+
const zoom = events.on(scope, "UI_SCALE_CHANGED", refreshPosition);
|
|
76
|
+
if (!zoom.ok) return zoom;
|
|
77
|
+
const screen = events.on(scope, "DISPLAY_SIZE_CHANGED", refreshPosition);
|
|
78
|
+
if (!screen.ok) return screen;
|
|
79
|
+
const cleanup = scope.onDispose(() => { host?.Hide(); });
|
|
80
|
+
if (!cleanup.ok) return cleanup;
|
|
81
|
+
return ok({
|
|
82
|
+
locked,
|
|
83
|
+
show: () => {
|
|
84
|
+
if (!scope.isActive()) return;
|
|
85
|
+
const ready = ensureHost();
|
|
86
|
+
if (ready.ok) ready.value.Show();
|
|
87
|
+
else api.geterrorhandler()(ready.reason);
|
|
88
|
+
},
|
|
89
|
+
hide: () => { host?.Hide(); },
|
|
90
|
+
isShown: () => host !== undefined && readFrameShown(host) === true,
|
|
91
|
+
mount: (runtime, render, options) => {
|
|
92
|
+
if (!scope.isActive()) return fail("Cannot mount a disposed panel");
|
|
93
|
+
const ready = ensureHost();
|
|
94
|
+
return ready.ok ? mountNative(ready.value, runtime, render, options) : ready;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
package/wow/pixel.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ok } from "../src/result";
|
|
2
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
3
|
+
import { createEventDispatcher } from "./event-dispatcher";
|
|
4
|
+
import type { Frame } from "./frames";
|
|
5
|
+
import { api, reveal } from "./native";
|
|
6
|
+
|
|
7
|
+
const display = createEventDispatcher();
|
|
8
|
+
|
|
9
|
+
/** Effective scale for a native region whose local unit is one display pixel. */
|
|
10
|
+
export function physicalPixelScale(this: void): number | undefined {
|
|
11
|
+
const [, height] = api.GetPhysicalScreenSize();
|
|
12
|
+
const screen = reveal(height);
|
|
13
|
+
return typeof screen === "number" && Number.isFinite(screen) && screen > 0 ? 768 / screen : undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Local UI units occupied by a single physical display pixel. */
|
|
17
|
+
export function physicalPixel(this: void, frame: Pick<Frame, "GetEffectiveScale">): number {
|
|
18
|
+
const [, height] = api.GetPhysicalScreenSize();
|
|
19
|
+
const scale = reveal(frame.GetEffectiveScale());
|
|
20
|
+
const screen = reveal(height);
|
|
21
|
+
return typeof scale === "number" && Number.isFinite(scale) && scale > 0
|
|
22
|
+
&& typeof screen === "number" && Number.isFinite(screen) && screen > 0 ? 768 / screen / scale : 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function snapPixel(this: void, value: number, unit: number): number {
|
|
26
|
+
return Math.floor(value / unit + 0.5) * unit;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function watchDisplayMetrics(this: void, scope: RuntimeScope, refresh: (this: void) => void) {
|
|
30
|
+
const scale = display.on(scope, "UI_SCALE_CHANGED", refresh);
|
|
31
|
+
if (!scale.ok) return scale;
|
|
32
|
+
const size = display.on(scope, "DISPLAY_SIZE_CHANGED", refresh);
|
|
33
|
+
if (!size.ok) { scale.value(); return size; }
|
|
34
|
+
return ok(undefined);
|
|
35
|
+
}
|
package/wow/plugins.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { ModuleContainer, ModuleDeclaration, ModuleInput, ModuleReference } from "../src/module";
|
|
2
|
+
import { computed } from "../src/reactive-scope";
|
|
3
|
+
import { ref, type SignalRef } from "../src/reactivity";
|
|
4
|
+
import { fail, ok, type Failure, type Result } from "../src/result";
|
|
5
|
+
import type { RuntimeScope } from "../src/runtime";
|
|
6
|
+
import { ownedMap, type OwnedMap } from "../src/owned-collections";
|
|
7
|
+
import { defineStore, readonly } from "../state/setup-store";
|
|
8
|
+
import { addonManifest, type AddonManifest, type PluginManifest } from "./addon-manifest";
|
|
9
|
+
import { api, reveal } from "./native";
|
|
10
|
+
import { protect } from "./protect";
|
|
11
|
+
|
|
12
|
+
type LoadableModule = Exclude<ModuleReference<object>, ModuleInput<object>>;
|
|
13
|
+
type ModuleExports<Module> = Module extends ModuleReference<infer Value> ? Value : never;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The plugins declared in kumi.config.ts, keyed by ID. `kumi check` and `kumi build` fill this in from
|
|
17
|
+
* `build/kumi/plugins.d.ts`, so `usePlugins().load("history")` knows the plugin's services.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
20
|
+
export interface KumiPlugins {}
|
|
21
|
+
|
|
22
|
+
/** A plugin ID from kumi.config.ts. Any string until the project declares plugins. */
|
|
23
|
+
export type PluginId = [keyof KumiPlugins] extends [never] ? string : Extract<keyof KumiPlugins, string>;
|
|
24
|
+
/** The public services of a plugin's module. */
|
|
25
|
+
export type PluginServices<Id extends string> = Id extends keyof KumiPlugins ? Readonly<ModuleExports<KumiPlugins[Id]>> : Readonly<object>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* - `"off"`: turned off in the addon list.
|
|
29
|
+
* - `"waiting"`: turned on but not running yet. A demand plugin waits for `load()`, a startup plugin for a reload.
|
|
30
|
+
* - `"loading"`, `"ready"`, `"error"`: the plugin is starting, running, or failed with `error`.
|
|
31
|
+
*/
|
|
32
|
+
export type PluginStatus = "off" | "waiting" | "loading" | "ready" | "error";
|
|
33
|
+
|
|
34
|
+
export interface PluginInfo {
|
|
35
|
+
readonly id: PluginId;
|
|
36
|
+
readonly addon: string;
|
|
37
|
+
readonly title: string;
|
|
38
|
+
readonly notes: string;
|
|
39
|
+
readonly load: "startup" | "demand";
|
|
40
|
+
/** The saved choice in the addon list. A change applies after `/reload`, or at `load()` for a demand plugin. */
|
|
41
|
+
readonly enabled: boolean;
|
|
42
|
+
readonly status: PluginStatus;
|
|
43
|
+
readonly error?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface PluginState {
|
|
47
|
+
readonly manifest: PluginManifest;
|
|
48
|
+
readonly enabled: SignalRef<boolean>;
|
|
49
|
+
readonly status: SignalRef<PluginStatus>;
|
|
50
|
+
readonly error: SignalRef<string | undefined>;
|
|
51
|
+
/** Whether the plugin's code was running when the UI loaded. */
|
|
52
|
+
readonly running: boolean;
|
|
53
|
+
services?: object;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface PluginHost {
|
|
57
|
+
readonly modules: ModuleContainer;
|
|
58
|
+
readonly scope: RuntimeScope;
|
|
59
|
+
readonly manifest: AddonManifest;
|
|
60
|
+
readonly states: OwnedMap<string, PluginState>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let host: PluginHost | undefined;
|
|
64
|
+
|
|
65
|
+
function playerName() {
|
|
66
|
+
const read = api.UnitName;
|
|
67
|
+
if (typeof read !== "function") return undefined;
|
|
68
|
+
const [name] = read("player");
|
|
69
|
+
const value = reveal(name);
|
|
70
|
+
return typeof value === "string" && value !== "" ? value : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function savedEnabled(addon: string) {
|
|
74
|
+
const state = reveal(api.C_AddOns?.GetAddOnEnableState?.(addon, playerName() ?? ""));
|
|
75
|
+
return typeof state === "number" ? state > 0 : true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function inCombat() {
|
|
79
|
+
return reveal(api.InCombatLockdown?.()) === true;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function activate(state: PluginState, modules: ModuleContainer, manifest: AddonManifest): Result<object> {
|
|
83
|
+
const module = manifest.registered[state.manifest.id] as LoadableModule | undefined;
|
|
84
|
+
if (module === undefined) {
|
|
85
|
+
const failure = manifest.failures[state.manifest.id];
|
|
86
|
+
return fail(failure === undefined ? "Plugin " + state.manifest.id + " did not register its module"
|
|
87
|
+
: "Plugin " + state.manifest.id + " failed while its file loaded: " + failure + ". Reload the UI after updating it.");
|
|
88
|
+
}
|
|
89
|
+
const attempted = protect(() => modules.resolve(module));
|
|
90
|
+
const resolved = attempted.ok ? attempted.value : attempted;
|
|
91
|
+
if (!resolved.ok) return resolved;
|
|
92
|
+
return ok(resolved.value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function settle(state: PluginState, result: Result<object>) {
|
|
96
|
+
if (result.ok) {
|
|
97
|
+
state.services = result.value;
|
|
98
|
+
state.error.value = undefined;
|
|
99
|
+
state.status.value = "ready";
|
|
100
|
+
} else {
|
|
101
|
+
state.error.value = result.reason;
|
|
102
|
+
state.status.value = "error";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** @internal Called by a plugin's generated entry when WoW runs its file. */
|
|
107
|
+
export function registerPlugin(this: void, id: string, module: LoadableModule): void {
|
|
108
|
+
const manifest = addonManifest();
|
|
109
|
+
if (manifest === undefined) throw new Error("Plugin " + id + " needs the Kumi manifest of its addon");
|
|
110
|
+
if ((module as ModuleDeclaration<object>).kind !== "module") throw new Error("Plugin " + id + " must export a Kumi module");
|
|
111
|
+
if (manifest.registered[id] !== undefined) throw new Error("Plugin " + id + " registered twice");
|
|
112
|
+
manifest.registered[id] = module;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** @internal Start the startup plugins once the root module is active. One failing plugin does not stop the others. */
|
|
116
|
+
export function startPlugins(this: void, modules: ModuleContainer, scope: RuntimeScope, report: (this: void, failure: Failure) => void): void {
|
|
117
|
+
const manifest = addonManifest();
|
|
118
|
+
if (manifest === undefined) return;
|
|
119
|
+
manifest.started = true;
|
|
120
|
+
const states = ownedMap<string, PluginState>();
|
|
121
|
+
for (let index = 0; index < manifest.plugins.length; index++) {
|
|
122
|
+
const plugin = manifest.plugins[index];
|
|
123
|
+
const registered = manifest.registered[plugin.id] !== undefined || manifest.failures[plugin.id] !== undefined;
|
|
124
|
+
const enabled = savedEnabled(plugin.addon);
|
|
125
|
+
states.set(plugin.id, {
|
|
126
|
+
manifest: plugin,
|
|
127
|
+
enabled: ref(enabled),
|
|
128
|
+
status: ref<PluginStatus>(enabled ? "waiting" : "off"),
|
|
129
|
+
error: ref<string | undefined>(undefined),
|
|
130
|
+
running: registered,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
host = { modules, scope, manifest, states };
|
|
134
|
+
for (let index = 0; index < manifest.plugins.length; index++) {
|
|
135
|
+
const plugin = manifest.plugins[index];
|
|
136
|
+
const state = states.get(plugin.id);
|
|
137
|
+
if (state === undefined || plugin.load !== "startup" || !state.running) continue;
|
|
138
|
+
settle(state, activate(state, modules, manifest));
|
|
139
|
+
if (state.status.value === "error") report(fail("Plugin " + plugin.id + ": " + (state.error.value ?? "failed")));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function loadPlugin(id: string): Result<object> {
|
|
144
|
+
const current = host;
|
|
145
|
+
if (current === undefined) return fail("Plugins are available after the addon starts");
|
|
146
|
+
if (!current.scope.isActive()) return fail("The addon has stopped");
|
|
147
|
+
const state = current.states.get(id);
|
|
148
|
+
if (state === undefined) return fail("Unknown plugin " + id + ". Declare it in kumi.config.ts.");
|
|
149
|
+
const status = state.status.value;
|
|
150
|
+
if (status === "ready" && state.services !== undefined) return ok(state.services);
|
|
151
|
+
if (status === "loading") return fail("Plugin " + id + " is already loading");
|
|
152
|
+
if (!state.enabled.value) return fail("Plugin " + id + " is turned off. Turn it on in the plugin list.");
|
|
153
|
+
if (state.manifest.load === "startup" && !state.running) return fail("Plugin " + id + " starts after a UI reload");
|
|
154
|
+
if (inCombat()) return fail("Plugin " + id + " can load after combat");
|
|
155
|
+
const { manifest, modules } = current;
|
|
156
|
+
state.status.value = "loading";
|
|
157
|
+
state.error.value = undefined;
|
|
158
|
+
if (manifest.registered[id] === undefined && manifest.failures[id] === undefined) {
|
|
159
|
+
const loader = api.C_AddOns?.LoadAddOn;
|
|
160
|
+
if (typeof loader !== "function") {
|
|
161
|
+
settle(state, fail("This client cannot load addons on demand"));
|
|
162
|
+
return fail(state.error.value ?? "");
|
|
163
|
+
}
|
|
164
|
+
// WoW reports errors from the plugin's files to its error handler. LoadAddOn itself returns a status.
|
|
165
|
+
manifest.loading = state.manifest.addon;
|
|
166
|
+
const [success, reason] = loader(state.manifest.addon);
|
|
167
|
+
manifest.loading = undefined;
|
|
168
|
+
if (reveal(success) !== true) {
|
|
169
|
+
const failure = fail("Could not load " + state.manifest.addon + ": " + (reveal(reason) ?? "unknown reason"));
|
|
170
|
+
settle(state, failure);
|
|
171
|
+
return failure;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const result = activate(state, modules, manifest);
|
|
175
|
+
settle(state, result);
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function setPluginEnabled(id: string, enabled: boolean, reload: SignalRef<boolean>): Result<void> {
|
|
180
|
+
const current = host;
|
|
181
|
+
const state = current?.states.get(id);
|
|
182
|
+
if (current === undefined || state === undefined) return fail("Unknown plugin " + id + ". Declare it in kumi.config.ts.");
|
|
183
|
+
if (state.enabled.value === enabled) return ok(undefined);
|
|
184
|
+
const addons = api.C_AddOns;
|
|
185
|
+
const write = enabled ? addons?.EnableAddOn : addons?.DisableAddOn;
|
|
186
|
+
if (typeof write !== "function") return fail("This client cannot change the addon list");
|
|
187
|
+
const character = current.manifest.pluginState === "character" ? playerName() : undefined;
|
|
188
|
+
const written = protect(() => {
|
|
189
|
+
if (character === undefined) write(state.manifest.addon);
|
|
190
|
+
else write(state.manifest.addon, character);
|
|
191
|
+
addons?.SaveAddOns?.();
|
|
192
|
+
});
|
|
193
|
+
if (!written.ok) return written;
|
|
194
|
+
state.enabled.value = enabled;
|
|
195
|
+
if (state.status.value === "off" || state.status.value === "waiting") state.status.value = enabled ? "waiting" : "off";
|
|
196
|
+
// A running plugin stops only after a reload. A startup plugin also starts only after one.
|
|
197
|
+
const running = state.status.value === "ready" || state.status.value === "error" || state.running;
|
|
198
|
+
if (running !== enabled && (running || state.manifest.load === "startup")) reload.value = true;
|
|
199
|
+
return ok(undefined);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The addon's plugins and their state. Use it to build a plugin list:
|
|
204
|
+
* `plugins.list` is reactive, `setEnabled` changes the addon list, and `reload()` applies the change.
|
|
205
|
+
*/
|
|
206
|
+
export const usePlugins = defineStore("kumi/plugins", () => {
|
|
207
|
+
const reloadRequired = ref(false);
|
|
208
|
+
const list = computed(() => {
|
|
209
|
+
const rows: PluginInfo[] = [];
|
|
210
|
+
const current = host;
|
|
211
|
+
if (current === undefined) return rows;
|
|
212
|
+
for (let index = 0; index < current.manifest.plugins.length; index++) {
|
|
213
|
+
const plugin = current.manifest.plugins[index];
|
|
214
|
+
const state = current.states.get(plugin.id);
|
|
215
|
+
if (state === undefined) continue;
|
|
216
|
+
rows.push({
|
|
217
|
+
id: plugin.id as PluginId, addon: plugin.addon, title: plugin.title, notes: plugin.notes, load: plugin.load,
|
|
218
|
+
enabled: state.enabled.value, status: state.status.value, error: state.error.value,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return rows;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
/** Load a demand plugin, or return a running plugin's services. Repeated calls return the same services. */
|
|
225
|
+
function load<Id extends PluginId>(this: void, id: Id): Result<PluginServices<Id>> {
|
|
226
|
+
return loadPlugin(id) as Result<PluginServices<Id>>;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Turn a plugin on or off in the addon list. Check `reloadRequired` to offer a reload. */
|
|
230
|
+
function setEnabled(this: void, id: PluginId, enabled: boolean): Result<void> {
|
|
231
|
+
return setPluginEnabled(id, enabled, reloadRequired);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function status(this: void, id: PluginId): PluginStatus | undefined {
|
|
235
|
+
return host?.states.get(id)?.status.value;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Reload the interface so plugin changes take effect. */
|
|
239
|
+
function reload(this: void): void {
|
|
240
|
+
const ui = api.C_UI;
|
|
241
|
+
if (typeof ui?.Reload === "function") ui.Reload();
|
|
242
|
+
else (api as { ReloadUI?: (this: void) => void }).ReloadUI?.();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return { list, reloadRequired: readonly(reloadRequired), load, setEnabled, status, reload };
|
|
246
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MouseButton } from "../src/elements";
|
|
2
|
+
import { api, reveal } from "./native";
|
|
3
|
+
|
|
4
|
+
const releaseGrace = 0.05;
|
|
5
|
+
|
|
6
|
+
/** A button's native OnClick can follow OnMouseUp or a drag-stop callback. */
|
|
7
|
+
export function createPointerClickGate(maxDuration: number) {
|
|
8
|
+
let button: MouseButton | undefined;
|
|
9
|
+
let started: number | undefined;
|
|
10
|
+
let released: number | undefined;
|
|
11
|
+
let dragged = false;
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
press: (next: MouseButton) => {
|
|
15
|
+
button = next;
|
|
16
|
+
started = reveal(api.GetTime());
|
|
17
|
+
released = undefined;
|
|
18
|
+
dragged = false;
|
|
19
|
+
},
|
|
20
|
+
drag: () => { dragged = true; },
|
|
21
|
+
release: (next: MouseButton) => {
|
|
22
|
+
if (next === button) released = reveal(api.GetTime());
|
|
23
|
+
},
|
|
24
|
+
clear: () => { button = undefined; },
|
|
25
|
+
accept: (next: MouseButton) => {
|
|
26
|
+
if (button !== next) return true;
|
|
27
|
+
button = undefined;
|
|
28
|
+
const now = reveal(api.GetTime());
|
|
29
|
+
// A later activation without a fresh pointer press is not part of this gesture.
|
|
30
|
+
if (now !== undefined && released !== undefined && now - released > releaseGrace) return true;
|
|
31
|
+
const end = released ?? now;
|
|
32
|
+
return !dragged && (started === undefined || end === undefined || end - started <= maxDuration);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
package/wow/protect.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ok, type Failure, type Result } from "../src/result";
|
|
2
|
+
import { rawField } from "./lua-table";
|
|
3
|
+
import { api, isSecret } from "./native";
|
|
2
4
|
import type { LuaMultiReturn } from "@kumi/wow-generated";
|
|
3
5
|
|
|
4
6
|
type ProtectedNative<Values extends unknown[]> = LuaMultiReturn<
|
|
@@ -15,10 +17,32 @@ declare function pcall<Receiver extends object, Args extends unknown[], Value>(
|
|
|
15
17
|
this: void, run: (this: Receiver, ...args: Args) => Value, receiver: Receiver, ...args: Args
|
|
16
18
|
): ProtectedNative<[Value]>;
|
|
17
19
|
|
|
20
|
+
declare function xpcall<Value>(
|
|
21
|
+
this: void, run: (this: void) => Value, onError: (this: void, error: unknown) => Failure
|
|
22
|
+
): LuaMultiReturn<[success: true, value: Value] | [success: false, error: Failure]>;
|
|
23
|
+
|
|
18
24
|
/** Preserve native multiple returns and leave error objects opaque. */
|
|
19
25
|
export const protectNative = pcall;
|
|
20
26
|
|
|
27
|
+
type DebugStack = (this: void, skip: number, top: number, bottom: number) => string;
|
|
28
|
+
type Traceback = (this: void, prefix: string, level: number) => string;
|
|
29
|
+
|
|
30
|
+
function readTrace(this: void): string | undefined {
|
|
31
|
+
const stack = rawField<DebugStack>(api, "debugstack");
|
|
32
|
+
const trace = stack === undefined
|
|
33
|
+
? rawField<Traceback>(rawField(api, "debug"), "traceback")?.("", 3)
|
|
34
|
+
: stack(3, 24, 8);
|
|
35
|
+
return isSecret(trace) || trace === "" ? undefined : trace;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// xpcall invokes the handler while the throwing callback's stack is still available.
|
|
39
|
+
function captureFailure(this: void, error: unknown): Failure {
|
|
40
|
+
const [described, reason] = protectNative(() => isSecret(error) ? "Protected WoW error" : String(error));
|
|
41
|
+
const [captured, trace] = protectNative(readTrace);
|
|
42
|
+
return { ok: false, reason: described ? reason : "WoW callback failed", trace: captured ? trace : undefined };
|
|
43
|
+
}
|
|
44
|
+
|
|
21
45
|
export function protect<T>(run: (this: void) => T): Result<T> {
|
|
22
|
-
const [success, value] =
|
|
23
|
-
return success ? ok(value) :
|
|
46
|
+
const [success, value] = xpcall(run, captureFailure);
|
|
47
|
+
return success ? ok(value) : value;
|
|
24
48
|
}
|