1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-30 08:22:51 -05:00

fix: Plugin settings not loading existing settings (#294)

I notice the plugin settings tab was not loading the
existing plugin settings from the settings file.

It was properly writting to the file, but not reloading
on initialization.

added a loadValue() function so PluginSettings can call when the
pluginService is injected. Added isLoading state flag to prevent
the onItemsChanged from saving back settings when loading is happening.
Added null wise checks for properties that may be not ready yet
when loading.
This commit is contained in:
Bruno Cesar Rocha
2025-10-02 19:24:28 +01:00
committed by GitHub
parent 6140c398f0
commit 16055fe96e

View File

@@ -15,14 +15,25 @@ Column {
width: parent.width width: parent.width
spacing: Theme.spacingM spacing: Theme.spacingM
property bool isLoading: false
Component.onCompleted: { Component.onCompleted: {
loadValue()
}
function loadValue() {
const settings = findSettings() const settings = findSettings()
if (settings) { if (settings) {
isLoading = true
items = settings.loadValue(settingKey, defaultValue) items = settings.loadValue(settingKey, defaultValue)
isLoading = false
} }
} }
onItemsChanged: { onItemsChanged: {
if (isLoading) {
return
}
const settings = findSettings() const settings = findSettings()
if (settings) { if (settings) {
settings.saveValue(settingKey, items) settings.saveValue(settingKey, items)
@@ -169,23 +180,37 @@ Column {
color: Theme.surfaceContainerHigh color: Theme.surfaceContainerHigh
border.width: 0 border.width: 0
required property int index
required property var modelData
Row { Row {
id: itemRow
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: Theme.spacingM anchors.leftMargin: Theme.spacingM
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingM spacing: Theme.spacingM
property var itemData: parent.modelData
Repeater { Repeater {
model: root.fields model: root.fields
StyledText { StyledText {
required property int index
required property var modelData
text: { text: {
const value = root.items[index][modelData.id] const field = modelData
const item = itemRow.itemData
if (!field || !field.id || !item) {
return ""
}
const value = item[field.id]
return value || "" return value || ""
} }
color: Theme.surfaceText color: Theme.surfaceText
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
width: modelData.width || 200 width: modelData ? (modelData.width || 200) : 200
elide: Text.ElideRight elide: Text.ElideRight
} }
} }
@@ -203,7 +228,7 @@ Column {
StyledText { StyledText {
anchors.centerIn: parent anchors.centerIn: parent
text: "Remove" text: "Remove"
color: Theme.errorText color: Theme.onError
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium font.weight: Font.Medium
} }