omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

bar.shell.serviceFor() returns null for third-party service+bar-widget plugins

Open n30nf4nt0m opened this issue 2 months ago • 4 comments

What happened

For a third-party plugin that declares both "service" and "bar-widget" kinds in its manifest, the bar-widget's bar.shell.serviceFor(pluginId) call reliably returns null, even though:

  • the service itself loads and runs correctly (its own IPC target responds, and it persists state to disk correctly)
  • bar.shell exists and bar.shell.serviceFor is a genuine function (not missing/undefined)

Since a plugin's BarWidget.qml/Panel.qml typically guard every interactive control with if (!svc) return, this makes every button, tab, toggle, and slider in the plugin's popup a silent no-op — the popup opens and displays correctly (since static labels don't need svc), but nothing in it does anything, and slider drags visually "snap back" after release (because the value binding re-reads from the unchanged service state).

Steps to reproduce

  1. Install a plugin whose manifest.json has:
    "kinds": ["service", "bar-widget"],
    "entryPoints": { "service": "Service.qml", "barWidget": "BarWidget.qml" }
    
  2. In BarWidget.qml, add a diagnostic to confirm the failure, e.g. in a tooltipText:
    tooltipText: "bar=" + (root.bar ? "Y" : "N")
      + " shell=" + (root.bar && root.bar.shell ? "Y" : "N")
      + " serviceForFn=" + (root.bar && root.bar.shell && typeof root.bar.shell.serviceFor === "function" ? "Y" : "N")
      + " svc=" + (root.svc ? "Y" : "N")
    
    where svc is bar && bar.shell ? bar.shell.serviceFor(pluginId) : null.
  3. Restart the shell (omarchy restart shell) and hover the widget's bar icon.

Observed

bar=Y shell=Y serviceForFn=Y svc=N — the lookup function exists and is callable, but returns null.

Confirmed independently that the service itself is alive and controllable the whole time, e.g.:

quickshell -p /usr/share/omarchy/shell ipc call <service-ipc-target> <method> <args>

correctly mutates and persists the plugin's own state file, while the widget's bar.shell.serviceFor(pluginId) keeps returning null.

Expected

bar.shell.serviceFor(pluginId) should return the live service instance for a plugin's own service (same id in both manifest.entryPoints.service and the widget's own serviceFor() call), matching how _services[pluginId] is populated by shell.qml's ensureService/_syncServices.

Scope / reproducibility

This was reproduced independently on two unrelated third-party plugins installed on the same system (both declaring service + bar-widget kinds), both showing svc=N in the same session — so this doesn't look specific to one plugin's code, but to how bar.shell gets constructed for third-party service+bar-widget plugins (Bar.qml's pluginBarApiFor / shell.qml's pluginShellForId → scopedPluginShellForId → pluginShellFor → createScopedPluginShell → _serviceLookup → pluginServiceFor → pluginOwnsTarget/resolveEnabledId chain). A full omarchy restart shell (fresh process) did not clear the problem, so it isn't just a stale in-memory cache from a hot-reload.

System info

  • omarchy version: 4.0.3-1
  • Quickshell: 0.3.0 (revision 28771c7c74b42e20afca0b1b63980cb46515537c, AUR quickshell-git)
  • Hyprland: 0.56.2 (v0.56.2, commit efb50993780079460b0cbed1363e2166a2de1d9f)

n30nf4nt0m avatar Sep 14 '26 13:09 n30nf4nt0m

Confirmed on omarchy 4.0.4-1 (Arch) with service+bar-widget plugins (tiedeyez.omatree, slcode777.omagotchi) under a third-party bar (jimmie.bar). This matches the canonical issue and I believe I have the second, less obvious short-circuit plus a tested fix.

Why serviceFor() never reaches the fallback

There are two scoped-shell paths, and the overridden case is the bar's own shell, not the widget's entry facade:

  • A widget hosted on a third-party bar calls bar.shell.serviceFor(id) where bar.shell is the bar plugin's own PluginShellApi (built by createScopedPluginShell with allowOwnService = true).
  • Its _serviceLookup is exactly return allowOwnService ? shell.pluginServiceFor(key, requestedId) : null. Because the requested id is not owned by the bar plugin, pluginServiceFor() returns null and the function returns immediately — any later fallback branch is dead code for bar shells. The service can be live, enabled, and sitting in the bar layout and the lookup still yields null.
  • The widget's bridge fallback then rebuilds the whole display from the persisted state file (read-only), so every care/control action silently no-ops with zero errors.

Proposed fix (tested, minimal)

In createScopedPluginShell's _serviceLookup, try the owned service first, then fall through to a bounded bar-configured lookup — only when the shell has bar capabilities, the target is a non-authentication plugin that is currently enabled and configured in the bar's layout, and via resolveEnabledId so a cloned id still resolves to its parent:

_serviceLookup: function(requestedId) {
  if (allowOwnService) {
    var ownedService = shell.pluginServiceFor(key, requestedId)
    if (ownedService) return ownedService
  }
  if (!hasCurrentBarCapabilities()) return null
  var id = shell.pluginRegistry.resolveEnabledId(String(requestedId || ""))
  var target = shell.pluginRegistry.installedPlugins[id]
  if (!target || shell.isAuthenticationService(target, id)) return null
  if (!shell.barEntryConfigured(id)) return null
  return shell.serviceFor(id)
},

This deliberately does not restore the generic facade factory removed in #9618: the caller still cannot reach arbitrary services — only non-auth plugins currently configured in the active bar. Full patch: 0001-shell-let-a-bar-scoped-shell-resolve-bar-configured-live-services.patch in the attached gist/PR.

Verification

Runtime instrumentation on both widgets after the change (fresh shell, 4.0.4):

shell=jimmie.bar svc=true live=true ready=true

Watering/feeding the omatree and omagotchi now mutates the live service (levels drop, state persists); before the change the same log line read svc=false live=false. No errors in the shell log from the patch.

Design note

This lands on the bar-owned shell, so it is slightly broader than the per-widget scoping #11713 asks about (the bar can reach any of its own configured services rather than only the widget's). If the maintainers prefer the tighter per-widget facade, the same barEntryConfigured gate can be applied inside pluginShellForBarEntry — but for the reported plugins the bar-shell path is what actually runs, so it must be addressed there regardless.

Tiedeyez avatar Sep 22 '26 15:09 Tiedeyez

I reproduced this on a worker running the shell from current quattro (9480d1b6a), using a minimal third-party plugin with "kinds": ["service", "bar-widget"] whose widget calls bar.shell.serviceFor(<its own id>). The result depends on which bar is active:

  • Built-in bar (omarchy.bar): the lookup returns the live service. The widget logged bar=Y shell=Y fn=Y svc=Y, and calls made through svc reached the running service.
  • A third-party replacement bar (a copy of the built-in bar installed under a non-reserved id and selected as bar.id in shell.json): the same widget logged bar=Y shell=Y fn=Y svc=N, which is exactly the result in this report.

The cause is in the replacement-bar path. A third-party bar's shell has no pluginShellForId, so pluginBarApiFor in shell/plugins/bar/Bar.qml:252 falls back to pluginShellForBarEntry (shell/shell.qml:705). That facade is built without a _serviceLookup, so serviceFor() exists but always returns null. This is intentional and came in with #9618, so that a third-party bar cannot get another plugin's live service object. manual/32-shell-plugins.md also documents it: service-backed widgets have reduced functionality on a replacement bar, and the fix it suggests is switching back to omarchy.bar. #11713 already asks whether replacement bars should get a trusted way to host service-backed widgets. That is the open question behind this report.

About the patch proposed in the comment above: it would let a third-party bar fetch the raw service object of any non-authentication plugin configured in its layout. That widens the boundary #9618 drew, so it is a policy decision rather than a contained bug fix. It also changes only createScopedPluginShell. The entry facade that pluginShellForBarEntry builds is separate and would still have no service lookup. Because this is a decision about the plugin security boundary, I have not opened a pull request.

@n30nf4nt0m, which bar were you running when you saw this? The "id" under "bar" in ~/.config/omarchy/shell.json shows it. If it was omarchy.bar, please also share the plugin ids, because then this is something my reproduction did not catch.

Reviewed by Claude Opus 5.5 and, as a second opinion, Codex Medium. Codex reached the same mechanism; its review is not guaranteed to be independent. It added the point about the entry facade. Whether replacement bars should get service access is waiting on the maintainer, alongside #11713.

omarchybot avatar Oct 12 '26 00:10 omarchybot

Still seeing this on 4.0.4 with multi-kind plugins. Related null lookup: #13304 (firstPartyServiceFor("omarchy.lock")).

Likely the bar host's service map only registers first-party / differently keyed IDs. A fix that makes serviceFor resolve the plugin's own service instance for service+bar-widget manifests would unblock third-party bars.

jandrusk avatar Oct 13 '26 16:10 jandrusk

I checked the new comment against current quattro (84cfb9395). The code behind this issue has not changed since my earlier reply, so that finding still stands: on the built-in bar (omarchy.bar) a service+bar-widget plugin's bar.shell.serviceFor(<its own id>) returns its live service, and on a third-party replacement bar it returns null by design.

Two points from the comment above, checked in source:

  • Third-party services are registered under their own plugin id. _syncServices() starts every enabled service manifest, first-party or not, and ensureService() publishes it in _services keyed by that id (shell/shell.qml:922, :962). The null does not come from a missing or differently keyed entry. It comes from the facade a replacement bar hands its widgets: pluginShellForBarEntry (shell/shell.qml:705, built at :723) supplies no _serviceLookup, so serviceFor() returns null (shell/services/PluginShellApi.qml:20). manual/32-shell-plugins.md:42 documents that limitation.
  • #13304 is a different mechanism. There the lookup is for omarchy.lock, which declares the authentication capability, and authentication services are deliberately kept out of _services and held in AuthServiceStore (shell/shell.qml:954). Here the service is in the map, and the replacement bar's facade does not hand it out.

Letting a replacement bar reach a widget's own service is the open question in #11713, and that decision is the maintainer's. @jandrusk, which bar are you running (the "id" under "bar" in ~/.config/omarchy/shell.json)? If it is omarchy.bar, please share the plugin ids, because my reproduction did not catch that case. The same question to @n30nf4nt0m is still open.

Reviewed by Claude Opus 5.5 and, as a second opinion, Codex Medium, both by reading the source at this revision. Nothing was run this time. Codex independently confirmed all three points above, though its independence is not guaranteed. This is still waiting on the maintainer, alongside #11713.

omarchybot avatar Oct 14 '26 13:10 omarchybot