Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/omarchy-service-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions hosts/omarchy/Bridge.js
Original file line number Diff line number Diff line change
@@ -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 }
13 changes: 12 additions & 1 deletion hosts/omarchy/OmarchyPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions hosts/omarchy/OmarchyService.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -652,4 +653,7 @@ QtObject {
repeat: false
onTriggered: root.recentlyLinkedFolderId = ""
}

Component.onCompleted: Bridge.publish(root)
Component.onDestruction: Bridge.clear(root)
}
2 changes: 1 addition & 1 deletion tests/plugin-ui.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
63 changes: 63 additions & 0 deletions tests/replacement-bar.qml
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
13 changes: 13 additions & 0 deletions tests/replacement-bar.test.sh
Original file line number Diff line number Diff line change
@@ -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'
Loading