feat(renderer): useMenuAction hook (native menu IPC -> command store)

- bridge between main-process menu events and the command dispatcher
- optional transform: convert raw IPC payload to command args
- extends ipc.ts with ipc.menu.on() helper
- TDD: 5 unit tests covering subscription, payload transform, no-op, unmount
This commit is contained in:
Amit Haridas
2026-06-05 15:53:37 +05:30
parent 6df21ace35
commit cdd370c62d
3 changed files with 125 additions and 0 deletions
+12
View File
@@ -95,4 +95,16 @@ export const ipc = {
showItemInFolder: (path: string): Promise<IpcResult<void | ChannelMissing>> =>
safeCall('app', 'showItemInFolder', path),
},
menu: {
/**
* Subscribe to a native-menu IPC channel. The callback receives the
* raw payload(s) from the main process. Returns an unsubscribe fn.
*/
on: (channel: string, callback: (...args: unknown[]) => void): (() => void) => {
if (typeof window === 'undefined' || !window.electronAPI?.on) {
return () => {};
}
return window.electronAPI.on(channel, callback as (...a: any[]) => void);
},
},
};