Merge pull request #478 from lonerOrz/feature/widget-usage-badge

feat(settings): Add usage badges to widget selector
This commit is contained in:
Lemmy
2025-10-14 19:31:48 -04:00
committed by GitHub
9 changed files with 117 additions and 46 deletions
+40 -10
View File
@@ -303,9 +303,7 @@ ColumnLayout {
Layout.bottomMargin: Style.marginXL
}
// ---------------------------------
// Signal functions
// ---------------------------------
function _addWidgetToSection(widgetId, section) {
var newWidget = {
"id": widgetId
@@ -375,19 +373,51 @@ ColumnLayout {
}
}
// Data model functions
function getWidgetLocations(widgetId) {
if (!BarService)
return []
const instances = BarService.getAllRegisteredWidgets()
const locations = {}
for (var i = 0; i < instances.length; i++) {
if (instances[i].widgetId === widgetId) {
const section = instances[i].section
if (section === "left")
locations["L"] = true
else if (section === "center")
locations["C"] = true
else if (section === "right")
locations["R"] = true
}
}
return Object.keys(locations).join('')
}
function updateAvailableWidgetsModel() {
availableWidgets.clear()
const widgets = BarWidgetRegistry.getAvailableWidgets()
widgets.forEach(entry => {
availableWidgets.append({
"key": entry,
"name": entry,
"badgeLocations": getWidgetLocations(entry)
})
})
}
// Base list model for all combo boxes
ListModel {
id: availableWidgets
}
Component.onCompleted: {
// Fill out availableWidgets ListModel
availableWidgets.clear()
BarWidgetRegistry.getAvailableWidgets().forEach(entry => {
availableWidgets.append({
"key": entry,
"name": entry
})
})
updateAvailableWidgetsModel()
}
Connections {
target: BarService
function onActiveWidgetsChanged() {
updateAvailableWidgetsModel()
}
}
}