{"id":13800788,"url":"https://github.com/c2r0b/tauri-plugin-context-menu","last_synced_at":"2025-05-16T19:03:14.777Z","repository":{"id":184853601,"uuid":"672576933","full_name":"c2r0b/tauri-plugin-context-menu","owner":"c2r0b","description":"Native Context Menu in Tauri v1","archived":false,"fork":false,"pushed_at":"2024-10-26T14:21:52.000Z","size":881,"stargazers_count":146,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T22:07:09.909Z","etag":null,"topics":["context-menu","native","plugin","rust","tauri"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/tauri-plugin-context-menu","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/c2r0b.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-30T14:58:00.000Z","updated_at":"2025-03-26T16:44:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"6089006b-ea73-4ae9-a629-5076eede92eb","html_url":"https://github.com/c2r0b/tauri-plugin-context-menu","commit_stats":{"total_commits":94,"total_committers":5,"mean_commits":18.8,"dds":0.08510638297872342,"last_synced_commit":"1cdd3b55677054ba0e237893435fdc05006b9a3e"},"previous_names":["c2r0b/tauri-plugin-context-menu"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c2r0b%2Ftauri-plugin-context-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c2r0b%2Ftauri-plugin-context-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c2r0b%2Ftauri-plugin-context-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/c2r0b%2Ftauri-plugin-context-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/c2r0b","download_url":"https://codeload.github.com/c2r0b/tauri-plugin-context-menu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248608997,"owners_count":21132826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context-menu","native","plugin","rust","tauri"],"created_at":"2024-08-04T00:01:16.280Z","updated_at":"2025-04-12T17:43:48.053Z","avatar_url":"https://github.com/c2r0b.png","language":"Rust","funding_links":[],"categories":["Development"],"sub_categories":["Plugins"],"readme":"# Tauri v1 Plugin Context Menu\n\nA Tauri plugin to display native context menu in Tauri v1.x.  \nThe Tauri API v1 does not support native context menu out of the box, so this plugin is created to fill the gap.\n\n\u003cimg src=\"./assets/screenshot.png\" alt=\"image\" width=\"400\" height=\"auto\"\u003e\n\n⚠️ **Maintenance Mode with Community Contributions** ⚠️  \n\nTauri v2 [has been released](https://tauri.app/blog/tauri-20/) and it supports creating native context menu without plugins ([here the docs](https://v2.tauri.app/reference/javascript/api/namespacemenu/)).  \n\nBug fixes will still be implemented for this plugin.  \nNew features will not be developed by the main maintainer, but PRs from the community are still welcome.\n\n## Support\n| Windows | MacOS | Linux |\n| ------- | ----- | ----- |\n| ✅       | ✅     | ✅     |\n\n## Installation\nCrate: https://crates.io/crates/tauri-plugin-context-menu\n\n`cargo add tauri-plugin-context-menu` to add the package.\n\nOr add the following to your `Cargo.toml` for the latest unpublished version (not recommanded).\n\n```toml\ntauri-plugin-context-menu = { git = \"https://github.com/c2r0b/tauri-plugin-context-menu\", branch = \"main\" }\n```\n\nSee [\"Using a Plugin\" Tauri official guide](https://tauri.app/v1/guides/features/plugin#using-a-plugin) to initialize the plugin.\n\nThis project provides a typescript utility to simplify the usage of the plugin. Run the following to install the JavaScript/TypeScript package:\n    \n```bash\n npm i tauri-plugin-context-menu\n```\n\n## Examples\nCheck out the `examples` directory for sample usages.\n\nA vanilla JS example is provided in `examples/vanilla`.  \nAfter `npm install`, to run the example use the following command:\n\n```bash\nnpm run examples/vanilla\n```\n\nA typescript example using the utility package is provided in `examples/ts-utility`.\nYou can run it with the same command as above (replace `examples/vanilla` with `examples/ts-utility`).\n\n## Sample Usage\n### Without the JS/TS Package\n```ts\nimport { invoke } from \"@tauri-apps/api\";\nimport { listen } from \"@tauri-apps/api/event\";\nimport { resolveResource } from \"@tauri-apps/api/path\";\n\n// Listen to the event emitted when the first menu item is clicked\nlisten(\"item1clicked\", (event) =\u003e {\n    alert(event.payload);\n});\n\nwindow.addEventListener(\"contextmenu\", async (e) =\u003e {\n    e.preventDefault();\n    const iconUrl = await resolveResource('assets/16x16.png');\n\n    // Show the context menu\n    invoke(\"plugin:context_menu|show_context_menu\", {\n        items: [\n            {\n                label: \"Item 1\",\n                disabled: false,\n                event: \"item1clicked\",\n                payload: \"Hello World!\",\n                shortcut: \"ctrl+M\",\n                icon: {\n                    path: iconUrl\n                },\n                subitems: [\n                    {\n                        label: \"Subitem 1\",\n                        disabled: true,\n                        event: \"subitem1clicked\",\n                    },\n                    {\n                        is_separator: true,\n                    },\n                    {\n                        label: \"Subitem 2\",\n                        disabled: false,\n                        checked: true,\n                        event: \"subitem2clicked\",\n                    }\n                ]\n            }\n        ],\n    });\n});\n```\n\n### With the JS/TS Package\n```ts\nimport { showMenu } from \"tauri-plugin-context-menu\";\n\nshowMenu({ \n    pos: {...}, // Position of the menu (see below for options)\n    theme: \"light\", // Theme of the menu\n    items: [\n        ...,\n        {\n            ..., // Menu item (see below for options)\n            event: () =\u003e {\n                // Do something\n            }\n        }\n    ]\n});\n```\nYou can also use it to respond to window events with the `onEventShowMenu` function:\n```ts\nimport { onEventShowMenu } from \"tauri-plugin-context-menu\";\nonEventShowMenu(\"contextmenu\", (e) =\u003e ({ /* menuOptions */ }));\n```\n\n## Options\nList of options that can be passed to the plugin.\n| Option | Type              | Optional   | Description                                            | OS compatibility                                                               |\n| ------ | ----------------- | ---------- | ------------------------------------------------------ | ------------------------------------------------------------------------------ |\n| items  | `MenuItem[]`      |            | List of menu items to be displayed.                    | All                                                                            |\n| pos    | `Position`        | `optional` | Position of the menu. Defaults to the cursor position. | All                                                                            |\n| theme  | `light` \\| `dark` | `optional` | Theme of the menu. Defaults to system theme.           | MacOS only [#25](https://github.com/c2r0b/tauri-plugin-context-menu/issues/25) |\n\n### MenuItem\n| Option       | Type           | Optional   | Default | Description                                             | JS/TS pkg                                                        |\n| ------------ | -------------- | ---------- | ------- | ------------------------------------------------------- | ---------------------------------------------------------------- |\n| label        | `string`       |            |         | Displayed test of the menu item.                        |                                                                  |\n| disabled     | `boolean`      | `optional` | `false` | Whether the menu item is disabled.                      |\n| event        | `string`       | `optional` |         | Event name to be emitted when the menu item is clicked. | You can pass a function to be executed instead of an event name. |\n| payload      | `string`       | `optional` |         | Payload to be passed to the event.                      | You can pass any type of data.                                   |\n| checked      | `boolean`      | `optional` |         | Whether the menu item is checked.                       |\n| subitems     | `MenuItem[]`   | `optional` | `[]`    | List of sub menu items to be displayed.                 |\n| shortcut     | `string`       | `optional` |         | Keyboard shortcut displayed on the right.               |\n| icon         | `MenuItemIcon` | `optional` |         | Icon to be displayed on the left.                       |\n| is_separator | `boolean`      | `optional` | `false` | Whether the menu item is a separator.                   |\n\n\n### MenuItemIcon\n| Option | Type     | Optional   | Default | Description                     | JS/TS pkg                                                                 |\n| ------ | -------- | ---------- | ------- | ------------------------------- | ------------------------------------------------------------------------- |\n| path   | `string` |            |         | Absolute path to the icon file. | You can use `assetToPath` to convert a relative path to an absolute path. |\n| width  | `number` | `optional` | `16`    | Width of the icon.              |\n| height | `number` | `optional` | `16`    | Height of the icon.             |\n\n### Position\nPosition coordinates must be relative to the currently active window when `is_absolute` is set to `false`.\n| Option      | Type      | Optional   | Default | Description                             |\n| ----------- | --------- | ---------- | ------- | --------------------------------------- |\n| x           | `number`  |            |         | X position of the menu.                 |\n| y           | `number`  |            |         | Y position of the menu.                 |\n| is_absolute | `boolean` | `optional` | `false` | Is the position absolute to the screen. |\n\n### Modifier Keys\nModifier keys can be used in the `shortcut` option of a menu item to display the corresponding symbol (`⌘`, `⌃`, `⌥`, `⇧`).\n\nOn MacOS this also makes the shortcut work when the modifier key is pressed (since it is handled by default by the OS).\n\n\u003cdetails\u003e\n  \u003csummary\u003eKey codes list\u003c/summary\u003e\n  \n  #### Modifiers  \n  - `cmd`\n  - `cmd_or_ctrl` (Alias for `cmd` and `ctrl`)\n  - `shift`\n  - `alt`\n  - `ctrl`\n  - `opt` (Alias for `alt`)\n  - `altgr`\n  - `super`\n  - `win`\n  - `meta`\n\n  #### Keys\n  - `plus`\n  - `space`\n  - `tab`\n  - `capslock`\n  - `numlock`\n  - `scrolllock`\n  - `backspace`\n  - `delete`\n  - `insert`\n  - `return`\n  - `enter`\n  - `up`\n  - `down`\n  - `left`\n  - `right`\n  - `home`\n  - `end`\n  - `pageup`\n  - `pagedown`\n  - `escape`\n  - `esc`\n  - `num0...9`\n  - `numdec`\n  - `numadd`\n  - `numsub`\n  - `nummult`\n  - `numdiv`\n  - `f1...24`\n\u003c/details\u003e\n\n## Events\n### Item Clicked\nEmitted when a menu item is clicked. The event name is the same as the `event` option of the menu item:\n\n```ts\nimport { listen } from \"@tauri-apps/api/event\";\nimport { invoke } from \"@tauri-apps/api\";\n\nlisten(\"[EVENTNAME]\", () =\u003e {\n    alert(\"menu item clicked\");\n});\n\ninvoke(...{\n    items: [{\n        ...\n        event: \"[EVENTNAME]\",\n        ...\n    }]\n});\n```\n\n### Menu Did Close\nEmitted when the menu is closed. This event is emitted regardless of whether the menu is closed by clicking on a menu item or by clicking outside the menu.  \nYou can catch this event using the following code:\n\n```ts\nimport { listen } from \"@tauri-apps/api/event\";\n\nlisten(\"menu-did-close\", () =\u003e {\n    alert(\"menu closed\");\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc2r0b%2Ftauri-plugin-context-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fc2r0b%2Ftauri-plugin-context-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fc2r0b%2Ftauri-plugin-context-menu/lists"}