Skip to content
Closed
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
27 changes: 26 additions & 1 deletion shell/services/PluginRegistry.qml
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@ QtObject {
return ""
}

// A clone of sourceId other than exceptId whose widget is on the bar.
function barCloneFor(config, sourceId, exceptId) {
for (var candidate in installedPlugins) {
if (candidate === exceptId) continue
var candidateManifest = installedPlugins[candidate]
var candidateMetadata = candidateManifest && Util.isPlainObject(candidateManifest.omarchy)
? candidateManifest.omarchy : null
if (!candidateMetadata || String(candidateMetadata.clonedFrom || "") !== sourceId) continue
if (findEntryLocation(config, candidate).kind === "bar") return candidate
}
return ""
}

function restoreCloneSource(config, cloneId, sourceId) {
var cloneManifest = installedPlugins[cloneId]
var isBarOption = cloneManifest && Array.isArray(cloneManifest.kinds)
Expand Down Expand Up @@ -584,7 +597,19 @@ QtObject {
return
}

if (clonedFrom) restoreCloneSource(config, key, clonedFrom)
// Another clone of the same source still has its widget on the bar, so
// the source is not put back beside it: that clone puts it back when it
// goes.
var barClone = clonedFrom ? barCloneFor(config, clonedFrom, key) : ""
if (barClone) {
var cloneBarLocation = findBarLocation(config, key, "")
if (cloneBarLocation.found) config.bar.layout[cloneBarLocation.section].splice(cloneBarLocation.index, 1)
config.plugins = config.plugins.filter(function(entry) {
return !entry || Util.canonicalWidgetId(String(entry.id)) !== key
})
if (cloneShouldRestoreSource(config, key)) setCloneShouldRestoreSource(config, barClone, true)
setCloneShouldRestoreSource(config, key, false)
} else if (clonedFrom) restoreCloneSource(config, key, clonedFrom)
else if (location.kind === "bar") config.bar.layout[location.section].splice(location.index, 1)
else if (location.kind === "plugin") config.plugins.splice(location.index, 1)

Expand Down
41 changes: 41 additions & 0 deletions test/shell.d/fixtures/plugin-registry/shell.qml
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,18 @@ ShellRoot {
var localWidget = manifest("local.first-widget", ["bar-widget"], { barWidget: "Widget.qml" })
localWidget.omarchy = { clonedFrom: "omarchy.first-widget" }
scan += block("thirdparty", "/third/local-widget", localWidget)
var sharedWidget = manifest("shared.first-widget", ["bar-widget"], { barWidget: "Widget.qml" })
sharedWidget.omarchy = { clonedFrom: "omarchy.first-widget" }
scan += block("thirdparty", "/third/shared-widget", sharedWidget)
var localWeather = manifest("local.weather", ["bar-widget"], { barWidget: "Widget.qml" })
localWeather.omarchy = { clonedFrom: "omarchy.weather" }
scan += block("thirdparty", "/third/local-weather", localWeather)
var localHybrid = manifest("local.hybrid", ["menu", "bar-widget"], { menu: "Menu.qml", barWidget: "Widget.qml" })
localHybrid.omarchy = { clonedFrom: "omarchy.hybrid" }
scan += block("thirdparty", "/third/local-hybrid", localHybrid)
var sharedHybrid = manifest("shared.hybrid", ["menu", "bar-widget"], { menu: "Menu.qml", barWidget: "Widget.qml" })
sharedHybrid.omarchy = { clonedFrom: "omarchy.hybrid" }
scan += block("thirdparty", "/third/shared-hybrid", sharedHybrid)
var localPanel = manifest("local.grouped-panel", ["panel"], { panel: "Panel.qml" })
localPanel.omarchy = { clonedFrom: "omarchy.grouped-panel" }
scan += block("thirdparty", "/third/local-panel", localPanel)
Expand Down Expand Up @@ -141,6 +147,8 @@ ShellRoot {
"omarchy.future-auth",
"omarchy.grouped-panel",
"omarchy.hybrid",
"shared.first-widget",
"shared.hybrid",
"third.bar",
"third.begin-widget",
"third.center-widget",
Expand Down Expand Up @@ -395,6 +403,39 @@ ShellRoot {
"disabling a widget clone restores its source in place"
)

registry.setEnabled("local.first-widget", true)
registry.setEnabled("shared.first-widget", true)
registry.setEnabled("shared.first-widget", false)
var afterSecondClone = JSON.parse(JSON.stringify(root.config.bar.layout))
root.config.plugins.push({ id: "shared.first-widget" })
registry.setEnabled("local.first-widget", false)
var afterLastClone = JSON.parse(JSON.stringify(root.config.bar.layout))

root.config = {
version: 1,
bar: { layout: { left: [{ id: "omarchy.hybrid" }], center: [], right: [] } },
plugins: []
}
registry.setEnabled("local.hybrid", true)
registry.setEnabled("shared.hybrid", true)
root.config.plugins.push({ id: "local.hybrid" })
registry.setEnabled("local.hybrid", false)
var afterFirstHybrid = JSON.parse(JSON.stringify({
left: root.config.bar.layout.left,
centerEnd: root.config.bar.layout.centerEnd,
plugins: root.config.plugins,
receiver: registry.resolveEnabledId("omarchy.hybrid")
}))
registry.setEnabled("shared.hybrid", false)
root.assertDeepEqual(
[afterSecondClone.center, afterSecondClone.centerEnd, afterLastClone.center,
afterFirstHybrid, root.config.bar.layout.centerEnd, root.config.disabledPlugins === undefined],
[[{ id: "local.first-widget", size: 4 }], [], [{ id: "omarchy.first-widget", size: 4 }],
{ left: [], centerEnd: [{ id: "shared.hybrid" }], plugins: [], receiver: "shared.hybrid" },
[{ id: "omarchy.hybrid" }], true],
"disabling a clone while another stays on the bar drops every record of it, and the last clone on the bar restores its source"
)

root.config = {
version: 1,
bar: { layout: { left: [], center: ["omarchy.first-widget"], right: [] } },
Expand Down
Loading