ReviewOS

craft-native/craft

Application menu cannot be set: JS sends setApplicationMenu, Zig handles setAppMenu

#24
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days ago

Summary

The application menu bar cannot be set from a webview. craft.menu.set() sends the bridge action setApplicationMenu, but bridge_menu.zig only recognises setAppMenu, so every call falls through to BridgeError.UnknownAction.

The call resolves successfully in JS, so nothing surfaces to the caller — the error is only visible in the native process log.

Reproduction

Serve this page and open it with packages/zig/zig-out/bin/craft --url http://localhost:4311:

<script>
setTimeout(async () => {
  const r = await window.craft.menu.set({ menus: [
    { label: 'File', items: [{ id: 'new', label: 'New Post', shortcut: 'cmd+n' }] },
  ]})
  console.log('resolved:', r)   // -> null, looks like success
}, 900)
</script>

Observed

Menu bar is unchanged. JS sees null (no throw). The native log shows:

[Bridge] Received JSON message: {"a":"setApplicationMenu","d":"{\"menus\":[...]}","t":"menu"}
[Bridge] Executed JS: if(window.__craftBridgeError)window.__craftBridgeError({"error":true,"code":"NATIVE_CALL_FAILED","action":"setApplicationMenu","message":"Native API call failed"});
[BridgeError] setApplicationMenu: NATIVE_CALL_FAILED - Native API call failed

Cause

packages/zig/src/bridge_menu.zig:53

if (std.mem.eql(u8, action, "setAppMenu")) {
    try self.setAppMenu(data);
}

The dispatch table has no setApplicationMenu branch, and the chain ends in return BridgeError.UnknownAction. The name the JS bridge emits and the name the native side accepts have diverged.

Expected

Either the JS bridge emits setAppMenu, or the Zig dispatcher accepts setApplicationMenu. Whichever way it is aligned, a rejected bridge action should also reject the JS promise rather than resolving null — silent failure is what made this take a while to pin down.

Environment

craft 0.0.66, macOS (arm64), native binary packages/zig/zig-out/bin/craft.

Sign in to comment on this issue.