mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
moar
This commit is contained in:
@@ -8,7 +8,8 @@ Column {
|
||||
required property string settingKey
|
||||
required property string label
|
||||
property string description: ""
|
||||
property var items: []
|
||||
property var defaultValue: []
|
||||
property var items: defaultValue
|
||||
property Component delegate: null
|
||||
|
||||
width: parent.width
|
||||
@@ -17,7 +18,7 @@ Column {
|
||||
Component.onCompleted: {
|
||||
const settings = findSettings()
|
||||
if (settings) {
|
||||
items = settings.loadValue(settingKey, [])
|
||||
items = settings.loadValue(settingKey, defaultValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ Column {
|
||||
required property string label
|
||||
property string description: ""
|
||||
property var fields: []
|
||||
property var items: []
|
||||
property var defaultValue: []
|
||||
property var items: defaultValue
|
||||
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
@@ -17,7 +18,7 @@ Column {
|
||||
Component.onCompleted: {
|
||||
const settings = findSettings()
|
||||
if (settings) {
|
||||
items = settings.loadValue(settingKey, [])
|
||||
items = settings.loadValue(settingKey, defaultValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
Item {
|
||||
id: root
|
||||
@@ -9,11 +10,20 @@ Item {
|
||||
property var pluginService: null
|
||||
default property alias content: settingsColumn.children
|
||||
|
||||
implicitHeight: settingsColumn.implicitHeight
|
||||
implicitHeight: hasPermission ? settingsColumn.implicitHeight : errorText.implicitHeight
|
||||
height: implicitHeight
|
||||
|
||||
readonly property bool hasPermission: pluginService && pluginService.hasPermission ? pluginService.hasPermission(pluginId, "settings_write") : true
|
||||
|
||||
function saveValue(key, value) {
|
||||
if (pluginService && pluginService.savePluginData) {
|
||||
if (!pluginService) {
|
||||
return
|
||||
}
|
||||
if (!hasPermission) {
|
||||
console.warn("PluginSettings: Plugin", pluginId, "does not have settings_write permission")
|
||||
return
|
||||
}
|
||||
if (pluginService.savePluginData) {
|
||||
pluginService.savePluginData(pluginId, key, value)
|
||||
}
|
||||
}
|
||||
@@ -25,8 +35,21 @@ Item {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: errorText
|
||||
visible: pluginService && !root.hasPermission
|
||||
anchors.fill: parent
|
||||
text: "This plugin does not have 'settings_write' permission.\n\nAdd \"permissions\": [\"settings_read\", \"settings_write\"] to plugin.json"
|
||||
color: Theme.error
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
wrapMode: Text.WordWrap
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
Column {
|
||||
id: settingsColumn
|
||||
visible: root.hasPermission
|
||||
width: parent.width
|
||||
spacing: Theme.spacingM
|
||||
}
|
||||
|
||||
76
Modules/Plugins/SliderSetting.qml
Normal file
76
Modules/Plugins/SliderSetting.qml
Normal file
@@ -0,0 +1,76 @@
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
import qs.Widgets
|
||||
|
||||
Column {
|
||||
id: root
|
||||
|
||||
required property string settingKey
|
||||
required property string label
|
||||
property string description: ""
|
||||
property int defaultValue: 0
|
||||
property int value: defaultValue
|
||||
property int minimum: 0
|
||||
property int maximum: 100
|
||||
property string leftIcon: ""
|
||||
property string rightIcon: ""
|
||||
property string unit: ""
|
||||
|
||||
width: parent.width
|
||||
spacing: Theme.spacingS
|
||||
|
||||
Component.onCompleted: {
|
||||
const settings = findSettings()
|
||||
if (settings) {
|
||||
value = settings.loadValue(settingKey, defaultValue)
|
||||
}
|
||||
}
|
||||
|
||||
onValueChanged: {
|
||||
const settings = findSettings()
|
||||
if (settings) {
|
||||
settings.saveValue(settingKey, value)
|
||||
}
|
||||
}
|
||||
|
||||
function findSettings() {
|
||||
let item = parent
|
||||
while (item) {
|
||||
if (item.saveValue !== undefined && item.loadValue !== undefined) {
|
||||
return item
|
||||
}
|
||||
item = item.parent
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: root.label
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
font.weight: Font.Medium
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: root.description
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Theme.surfaceVariantText
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
visible: root.description !== ""
|
||||
}
|
||||
|
||||
DankSlider {
|
||||
width: parent.width
|
||||
value: root.value
|
||||
minimum: root.minimum
|
||||
maximum: root.maximum
|
||||
leftIcon: root.leftIcon
|
||||
rightIcon: root.rightIcon
|
||||
unit: root.unit
|
||||
wheelEnabled: false
|
||||
onSliderValueChanged: newValue => {
|
||||
root.value = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -271,22 +271,25 @@ Item {
|
||||
id: pluginToggle
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
checked: PluginService.isPluginLoaded(pluginDelegate.pluginId)
|
||||
onToggled: (isChecked) => {
|
||||
onToggled: isChecked => {
|
||||
const currentPluginId = pluginDelegate.pluginId
|
||||
const currentPluginName = pluginDelegate.pluginName
|
||||
|
||||
if (isChecked) {
|
||||
if (PluginService.enablePlugin(pluginDelegate.pluginId)) {
|
||||
ToastService.showInfo("Plugin enabled: " + pluginDelegate.pluginName)
|
||||
if (PluginService.enablePlugin(currentPluginId)) {
|
||||
ToastService.showInfo("Plugin enabled: " + currentPluginName)
|
||||
} else {
|
||||
ToastService.showError("Failed to enable plugin: " + pluginDelegate.pluginName)
|
||||
ToastService.showError("Failed to enable plugin: " + currentPluginName)
|
||||
checked = false
|
||||
}
|
||||
} else {
|
||||
if (PluginService.disablePlugin(pluginDelegate.pluginId)) {
|
||||
ToastService.showInfo("Plugin disabled: " + pluginDelegate.pluginName)
|
||||
if (pluginsTab.expandedPluginId === pluginDelegate.pluginId) {
|
||||
pluginsTab.expandedPluginId = ""
|
||||
if (PluginService.disablePlugin(currentPluginId)) {
|
||||
ToastService.showInfo("Plugin disabled: " + currentPluginName)
|
||||
if (pluginDelegate.isExpanded) {
|
||||
expandedPluginId = ""
|
||||
}
|
||||
} else {
|
||||
ToastService.showError("Failed to disable plugin: " + pluginDelegate.pluginName)
|
||||
ToastService.showError("Failed to disable plugin: " + currentPluginName)
|
||||
checked = true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user