Summary
MenuBridge in packages/zig/types/craft-bridge.d.ts declares a method set that does not exist on the injected window.craft.menu. Every declared name is wrong, and the one method that matters for handling clicks is not declared at all.
TypeScript consumers get a green typecheck on calls that throw TypeError: ... is not a function at runtime.
Declared vs actual
Enumerated from a live webview (Object.keys(window.craft.menu)), craft 0.0.66:
craft-bridge.d.ts declares | Actually on the bridge |
|---|---|
setAppMenu | set |
setDockMenu | setDock |
addMenuItem | addItem |
removeMenuItem | removeItem |
enableMenuItem | enableItem |
disableMenuItem | disableItem |
checkMenuItem | checkItem |
uncheckMenuItem | uncheckItem |
setMenuItemLabel | setItemLabel |
clearDockMenu | clearDock |
| (not declared) | onAction |
onAction is the callback that receives menu clicks, so the omission means the typings describe a menu API with no way to respond to a menu.
Reproduction:
typeof window.craft.menu // 'object'
typeof window.craft.menu.setAppMenu // 'undefined' <- as declared
typeof window.craft.menu.set // 'function' <- actualMenuItemDefinition fields are also unparsed
The declared item shape is:
interface MenuItemDefinition {
id: string; label: string;
type?: 'normal' | 'separator' | 'checkbox' | 'radio';
checked?: boolean; enabled?: boolean; action?: string;
shortcut?: string; icon?: string;
submenu?: MenuItemDefinition[];
}The struct the native side actually decodes into (bridge_menu.zig:87) is:
const ParsedItem = struct {
id: ?[]const u8 = null,
label: ?[]const u8 = null,
shortcut: ?[]const u8 = null,
icon: ?[]const u8 = null,
separator: ?bool = null,
};So type, checked, enabled, action and submenu are silently dropped (.ignore_unknown_fields = true). Two consequences worth calling out:
- a separator must be written
{ separator: true }; the declared{ type: 'separator' }renders as a normal item submenuis declared and recursive, but nested menus are never built
Expected
Typings match the injected bridge: correct method names, onAction declared, and MenuItemDefinition reduced to the fields that are actually honoured (or the parser extended to honour the declared ones).
Environment
craft 0.0.66, macOS (arm64).
Found while wiring a File/Edit/View/Window/Help menu bar for a Craft-hosted app. Related: the app menu API is separately non-functional (#24), which is what sent me to the typings in the first place.