diff --git a/docs/omarchy-service-contract.md b/docs/omarchy-service-contract.md index 31260077..e7ee7406 100644 --- a/docs/omarchy-service-contract.md +++ b/docs/omarchy-service-contract.md @@ -8,7 +8,9 @@ release; they are not a cross-version interface for retained older services. `manifest.json` declares one kept-loaded `service` and one `bar-widget` under the stable plugin ID `io.github.ilyazar.syncthing`. The panel resolves the -service with `bar.shell.serviceFor(moduleName)`. +service with `bar.shell.serviceFor(moduleName)`. Replacement bars return no +service there, so the panel falls back to the instance the service publishes in +`hosts/omarchy/Bridge.js`. The supported update sequence is a normal Omarchy plugin update followed by a shell restart. Omarchy may retain an older service before that restart; diff --git a/hosts/omarchy/Bridge.js b/hosts/omarchy/Bridge.js new file mode 100644 index 00000000..c403dd53 --- /dev/null +++ b/hosts/omarchy/Bridge.js @@ -0,0 +1,11 @@ +.pragma library + +// Replacement bars give widgets a shell whose serviceFor returns null, so the +// service publishes itself here. This file must sit beside Service.qml and the +// widget that reads it: a library imported from elsewhere would be a separate copy. +var active = null + +function publish(service) { active = service } +function current() { return active } +// A retired service must not clear a replacement published during hot reload. +function clear(service) { if (active === service) active = null } diff --git a/hosts/omarchy/OmarchyPanel.qml b/hosts/omarchy/OmarchyPanel.qml index d96368d7..0a1b4c83 100644 --- a/hosts/omarchy/OmarchyPanel.qml +++ b/hosts/omarchy/OmarchyPanel.qml @@ -11,13 +11,16 @@ import "ui/UiConstants.js" as UiConstants import "models/PanelModel.js" as PanelModel import "models/ThemePaletteModel.js" as ThemePaletteModel import "../../shared/Paths.js" as Paths +import "Bridge.js" as Bridge Panel { id: root ipcTarget: moduleName - readonly property var syncthing: bar && bar.shell && moduleName ? bar.shell.serviceFor(moduleName) : null + readonly property var directService: bar && bar.shell && moduleName ? bar.shell.serviceFor(moduleName) : null + property var bridgedService: null + readonly property var syncthing: directService || bridgedService readonly property color foreground: bar ? bar.foreground : Commons.Color.foreground readonly property color urgent: bar ? bar.urgent : Commons.Color.urgent readonly property color warning: syncthing ? syncthing.warning : ThemePaletteModel.DefaultYellow @@ -724,6 +727,14 @@ Panel { } Component.onCompleted: configureService() + Timer { + interval: 1000 + running: !root.directService + repeat: true + triggeredOnStart: true + onTriggered: root.bridgedService = Bridge.current() + } + Timer { id: noticeDisplayTimer interval: UiConstants.NOTICE_VISIBLE_MS diff --git a/hosts/omarchy/OmarchyService.qml b/hosts/omarchy/OmarchyService.qml index 295f9396..31435114 100644 --- a/hosts/omarchy/OmarchyService.qml +++ b/hosts/omarchy/OmarchyService.qml @@ -5,6 +5,7 @@ import "controllers" import "ui/UiConstants.js" as UiConstants import "models/FacadeModel.js" as FacadeModel import "../../shared/Paths.js" as Paths +import "Bridge.js" as Bridge QtObject { id: root @@ -652,4 +653,7 @@ QtObject { repeat: false onTriggered: root.recentlyLinkedFolderId = "" } + + Component.onCompleted: Bridge.publish(root) + Component.onDestruction: Bridge.clear(root) } diff --git a/tests/plugin-ui.test.sh b/tests/plugin-ui.test.sh index d8797656..56354acd 100755 --- a/tests/plugin-ui.test.sh +++ b/tests/plugin-ui.test.sh @@ -13,7 +13,7 @@ node --test tests/folder-creation.test.mjs tests/bar-click.test.mjs tests/device for name in architecture plugin-acceptance-lint \ dropdown-search folder-overview busy-button \ adapter-service core-process install-recovery refresh-recovery \ - self-removal settings-migration theme-palette \ + self-removal settings-migration theme-palette replacement-bar \ caelestia-adapter dux-shell-adapter illogical-impulse-adapter \ waybar-adapter; do printf '\n==> %s\n' "$name" diff --git a/tests/replacement-bar.qml b/tests/replacement-bar.qml new file mode 100644 index 00000000..938322d0 --- /dev/null +++ b/tests/replacement-bar.qml @@ -0,0 +1,63 @@ +import QtQuick +import Quickshell +import "../hosts/omarchy" +import "../hosts/omarchy/Bridge.js" as Bridge + +ShellRoot { + id: root + + property QtObject direct: QtObject { + function setRefreshInterval(seconds) {} + } + + component FakeBar: QtObject { + property var service: null + property color foreground: "white" + property color urgent: "red" + property string fontFamily: "sans" + readonly property var shell: ({ + serviceFor: () => service + }) + } + + function check(value, message) { + if (!value) { + console.error(message); + service.core.terminate(); + Qt.exit(1); + throw new Error(message); + } + } + + OmarchyService { + id: service + } + + OmarchyPanel { + id: replacementBarPanel + moduleName: "test.replacement" + bar: FakeBar {} + } + + OmarchyPanel { + id: nativeBarPanel + moduleName: "test.native" + bar: FakeBar { + service: root.direct + } + } + + Timer { + interval: 1500 + running: true + onTriggered: { + root.check(replacementBarPanel.syncthing === service, "replacement bar panel did not find the published service"); + root.check(nativeBarPanel.syncthing === root.direct, "native bar lookup must win over the bridge"); + Bridge.clear(root.direct); + root.check(Bridge.current() === service, "retired service cleared its replacement"); + service.core.terminate(); + console.log("replacement bar tests passed"); + Qt.quit(); + } + } +} diff --git a/tests/replacement-bar.test.sh b/tests/replacement-bar.test.sh new file mode 100644 index 00000000..b349cf1a --- /dev/null +++ b/tests/replacement-bar.test.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euo pipefail + +# shellcheck source=qml-test-helper.sh +source "$(dirname -- "${BASH_SOURCE[0]}")/qml-test-helper.sh" +stage_omarchy_test replacement-bar hosts/omarchy shared assets +mkdir -p -- "$test_root/home" "$test_root/config" "$test_root/state" +# The panel needs the desktop's Wayland session, so keep XDG_RUNTIME_DIR. +export HOME=$test_root/home XDG_CONFIG_HOME=$test_root/config XDG_STATE_HOME=$test_root/state +cp "$root/tests/core-process-mock.sh" "$test_root/bin/syncshell-core" +chmod 755 "$test_root/bin/syncshell-core" +timeout 15s quickshell --no-color -p "$test_root/shell.qml" +printf 'replacement bar tests passed\n'