omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Let plugins declare menu entries in their manifest

Open ReidenXerx opened this issue 2 months ago • 4 comments

Problem

A plugin cannot contribute anything to the Omarchy menu. The menu is built from exactly two sources:

// shell/plugins/menu/Menu.qml
property string defaultMenuPath: omarchyPath + "/default/omarchy/omarchy-menu.jsonc"
property string userMenuPath: Quickshell.env("HOME") + "/.config/omarchy/extensions/omarchy-menu.jsonc"

and the dynamic row providers are a fixed registry:

readonly property var providers: ({ "fonts": {...}, "power-profiles": {...} })

plus the QML-native apps provider. Nothing reads plugin manifests, so a plugin that wants a settings entry has only one route: edit the user's omarchy-menu.jsonc on their behalf.

Why that route is bad

Every plugin author ends up writing the same merge helper, and it has to be careful in ways that are easy to get wrong. parseMenuJsonc returns [] on any parse failure:

try { parsed = JSON.parse(stripped) } catch (e) { return [] }

That is silent and total: one plugin writing slightly malformed JSONC does not break its entries, it removes every user menu entry, with no error anywhere the user will see. A plugin that appends carelessly, or an uninstall that leaves a dangling block, takes the user's own customisations with it.

Writing three plugins, I ended up with a ~120-line helper duplicated into each: marker-delimited blocks so unrelated content and comments survive, a validator mirroring stripJsonc exactly, and rollback-to-backup if the result would not parse. That is a lot of shared risk to push onto plugin authors for what is declarative data.

Proposal

A menu block in manifest.json, merged as a third source after the default and before (or after) the user extension:

{
  "id": "reidenxerx.idle-dim",
  "kinds": ["bar-widget"],
  "menu": {
    "setup.idle-dim": { "icon": "󰣝", "label": "Idle dim", "aliases": ["dim", "brightness"] },
    "setup.idle-dim.delay.60": { "label": "1 minute", "action": "$PLUGIN_BIN/idle-dim-config set-delay 60" }
  }
}

Same entry schema as the JSONC files, so nothing new to learn. Two details that would matter in practice:

  • A path token. Entries need to invoke the plugin's own binaries, and a plugin does not know its install path when the manifest is written. Something like $PLUGIN_DIR / $PLUGIN_BIN expanded at load, mirroring how $OMARCHY_PATH already works for runtime code.
  • Namespacing. Restricting a plugin to routes under a prefix it owns (or auto-prefixing) would stop one plugin overriding system.lock, and would make removal exact: entries vanish when the plugin is disabled or removed, with no cleanup step and nothing left dangling.

Why it is worth it

Menu discoverability is how Omarchy surfaces everything else — a plugin whose settings are reachable only by right-clicking its bar widget is invisible to a user who searches. That also rules out settings for plugins with no bar widget at all (service-only), which today have nowhere to put configuration.

Related: #10021 covers keeping third-party plugins updated; this is about letting them register in the first place.

Happy to implement if the shape sounds right — the merge point in rebuildItemsFromSources looks small, and I have three plugins to test it against.

ReidenXerx avatar Sep 10 '26 14:09 ReidenXerx

Supporting this.

I maintain Airport (derekwisong.airport), a panel plugin on the marketplace. After install and enable there's nothing on screen yet, so reaching it means either copying a block into omarchy-menu.jsonc or setting aside a keybinding. Both work fine, it's just friction right at the first-run moment. A manifest-declared entry would take care of it.

derekwisong avatar Sep 13 '26 02:09 derekwisong

I'm testing plugins, and this is definitely needed for management of them. After installing a plugin, you need to be able to see, open, and configure it. Right now the omarchy menu only supports add and remove plugin menu entries. Needs a full cleanup

silversword411 avatar Sep 27 '26 18:09 silversword411

Agreed this is a real plugin-platform gap — Airport and others have nowhere to surface after install.

If we go ahead, the design question is the manifest shape (label, icon, action IPC vs command, placement) and how to keep untrusted plugins from injecting arbitrary menu actions. A short schema proposal in this thread would unblock a PR.

jandrusk avatar Oct 13 '26 16:10 jandrusk

Thanks. Here is a schema that answers both questions. In short: a plugin declares labels and which of its own entry points receives a click, and the host writes the action. No plugin-supplied command, shell condition or path ever reaches the menu. State and lists come from the plugin's own service as plain data, so plugins keep ticks, hidden rows and lists without running anything.

This replaces the $PLUGIN_BIN command idea from my first post. A command string in a manifest is exactly the injection you are asking about.

Manifest

{
  "id": "someone.example",
  "kinds": ["service", "panel"],
  "entryPoints": { "service": "Service.qml", "panel": "Panel.qml" },
  "menu": [
    { "id": "settings", "label": "Example settings", "icon": "󰒓", "placement": "setup", "open": "panel", "payload": { "page": "settings" } },
    { "id": "pause", "label": "Pause until morning", "placement": "trigger", "open": "service", "payload": { "action": "pause" }, "checked": "paused" },
    { "id": "profiles", "label": "Profiles", "placement": "setup", "open": "service", "rows": "profileRows" }
  ]
}
Field Rule
id [a-z0-9-]{1,32}, unique within the plugin
label Plain text, 1–40 characters, rendered with Text.PlainText
icon Optional, one glyph. When it is missing, the menu's default glyph is used
placement setup (the default), trigger, style or system. Not install, remove, update or about, which are Omarchy's own package and info flows
open An entry point this same manifest declares: panel, overlay or service. The click's payload goes to it (open(payloadJson) for UI, a menuAction(payloadJson) function on the service)
payload Optional JSON object of scalars, at most 1 KB serialized
checked, visible, enabled Optional. Each names a boolean property on the plugin's own service. The host reads it; nothing is executed
rows Optional. Names a property on the plugin's own service that holds an array of { id, label, icon?, payload? }. The host shows it as a submenu, clicks go to open with that row's payload, and it is validated like manifest entries and capped at 50 rows

A plugin can declare at most 8 entries. Unknown fields are rejected, not ignored, so a later field cannot be smuggled in early.

What the host does with it

  • Routes are namespaced by the host. An entry becomes <placement>.plugins.<plugin>.<id>, where <plugin> is the plugin ID with its dots turned into dashes (dotted IDs mean hierarchy in the menu), so setup.plugins.someone-example.settings. That means it cannot replace system.lock or any default route. Each plugin's rows sit in a submenu with its name, and the plugins node keeps third-party rows visibly grouped rather than mixed into Omarchy's own lists. That is also why system can be allowed: a plugin row there cannot pose as Lock or Suspend.
  • The host builds the action. A click delivers the payload in-process: summon <pluginId> <payloadJson> for a panel or overlay, or the service's menuAction(payloadJson). No shell string is ever built. A click can therefore only run code the plugin already ships, and that code has already been reviewed with the plugin. A one-click action ("pause until morning", "start a 1-minute keyboard clean") is a payload the plugin's own code acts on, with no UI shown.
  • State without shell conditions. checked, visible and enabled read booleans from the plugin's own service, so "✓ Paused" or hiding a row on hardware without the device works without when/checked shell conditions. Those stay reserved for Omarchy's own JSONC.
  • Lists without providers. rows covers what providers do for built-ins, for example saved layouts or a choice of regions, from data the service already holds. It is plain text, capped and validated. No provider script is declared or run.
  • A summon name, generated by the host. Each plugin's submenu can be summoned as omarchy menu summon <plugin>, using the same dashed name, unless that name is already taken. Plugins cannot declare aliases, since those stay reserved for established names.
  • Each entry is validated alone. An invalid entry is dropped with a journal warning naming the plugin and the field, and nothing else is affected. This is the opposite of parseMenuJsonc's all-or-nothing []. A service that is not loaded makes its rows hide instead of erroring.
  • Lifecycle. Only enabled plugins contribute. Disabling or removing a plugin removes its rows on the next rebuild, with no files written and nothing to clean up.

Merge order

mergeMenuSources(default, plugins, user): the user extension stays last. Because plugin routes are deterministic, a user can still relabel or hide a plugin's row in omarchy-menu.jsonc by its key, and can still add any command row there themselves.

Implementation sketch

  • MenuModel.js: a pure pluginMenuItems(manifests, serviceState) that validates and namespaces entries and expands rows. It is Node-testable like the rest of MenuModel.js, with tests for every rejection above.
  • Menu.qml: feed it the enabled plugins' manifests in rebuildItemsFromSources. Read checked, visible, enabled and rows through each plugin's own-service facade, and rebuild when the plugin registry changes.
  • Marketplace: because the block is pure data, the security baseline can check it statically (allowed placements, open naming a declared entry point, the payload cap).

I can open the PR in this shape, with tests, once you're happy with it. If you would rather start smaller, checked/visible/enabled and rows can be a second PR. The first would then cover static entries and payload actions only.

ReidenXerx avatar Oct 16 '26 21:10 ReidenXerx