@fiahfy/electron-context-menu
v0.1.2
Published
Context Menu Helper in Electron Apps.
Downloads
4
Readme
electron-context-menu
Context Menu Helper in Electron Apps.
Installation
npm install @fiahfy/electron-context-menu
Usage
// main.js
import { register } from '@fiahfy/electron-context-menu'
const actionCreators = {
ping: (_event, _params, { message }) => ({
click: () => console.log(message), // => pong
}),
}
register(actionCreators)
// preload.js
import { exposeOperations } from '@fiahfy/electron-context-menu/preload'
contextBridge.exposeInMainWorld('electronAPI', {
...exposeOperations(),
}
// renderer.js
import { buildContextMenuParams } from '@fiahfy/electron-context-menu/renderer'
const handleContextMenu = (e) => {
e.preventDefault()
e.stopPropagation()
const items = [
{ type: 'ping', data: { message: 'pong' }}
]
await window.electronAPI.showContextMenu(
buildContextMenuParams(e, items),
)
}