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

Migrate plugin settings to separate file

This commit is contained in:
bbedward
2025-10-07 08:22:21 -04:00
parent 43970d34aa
commit 7e49631912
2 changed files with 67 additions and 4 deletions

View File

@@ -172,6 +172,7 @@ Singleton {
readonly property string _homeUrl: StandardPaths.writableLocation(StandardPaths.HomeLocation) readonly property string _homeUrl: StandardPaths.writableLocation(StandardPaths.HomeLocation)
readonly property string _configUrl: StandardPaths.writableLocation(StandardPaths.ConfigLocation) readonly property string _configUrl: StandardPaths.writableLocation(StandardPaths.ConfigLocation)
readonly property string _configDir: Paths.strip(_configUrl) readonly property string _configDir: Paths.strip(_configUrl)
readonly property string pluginSettingsPath: _configDir + "/DankMaterialShell/plugin_settings.json"
signal forceDankBarLayoutRefresh signal forceDankBarLayoutRefresh
signal forceDockLayoutRefresh signal forceDockLayoutRefresh
@@ -179,6 +180,7 @@ Singleton {
signal workspaceIconsUpdated signal workspaceIconsUpdated
property bool _loading: false property bool _loading: false
property bool _pluginSettingsLoading: false
property var pluginSettings: ({}) property var pluginSettings: ({})
@@ -223,13 +225,41 @@ Singleton {
_loading = true _loading = true
parseSettings(settingsFile.text()) parseSettings(settingsFile.text())
_loading = false _loading = false
loadPluginSettings()
}
function loadPluginSettings() {
_pluginSettingsLoading = true
parsePluginSettings(pluginSettingsFile.text())
_pluginSettingsLoading = false
}
function parsePluginSettings(content) {
_pluginSettingsLoading = true
try {
if (content && content.trim()) {
pluginSettings = JSON.parse(content)
} else {
pluginSettings = {}
}
} catch (e) {
console.warn("SettingsData: Failed to parse plugin settings:", e.message)
pluginSettings = {}
} finally {
_pluginSettingsLoading = false
}
} }
function parseSettings(content) { function parseSettings(content) {
_loading = true _loading = true
var shouldMigrate = false
try { try {
if (content && content.trim()) { if (content && content.trim()) {
var settings = JSON.parse(content) var settings = JSON.parse(content)
if (settings.pluginSettings !== undefined) {
pluginSettings = settings.pluginSettings
shouldMigrate = true
}
// Auto-migrate from old theme system // Auto-migrate from old theme system
if (settings.themeIndex !== undefined || settings.themeIsDynamic !== undefined) { if (settings.themeIndex !== undefined || settings.themeIsDynamic !== undefined) {
const themeNames = ["blue", "deepBlue", "purple", "green", "orange", "red", "cyan", "pink", "amber", "coral"] const themeNames = ["blue", "deepBlue", "purple", "green", "orange", "red", "cyan", "pink", "amber", "coral"]
@@ -381,7 +411,6 @@ Singleton {
widgetBackgroundColor = settings.widgetBackgroundColor !== undefined ? settings.widgetBackgroundColor : "sch" widgetBackgroundColor = settings.widgetBackgroundColor !== undefined ? settings.widgetBackgroundColor : "sch"
surfaceBase = settings.surfaceBase !== undefined ? settings.surfaceBase : "s" surfaceBase = settings.surfaceBase !== undefined ? settings.surfaceBase : "s"
screenPreferences = settings.screenPreferences !== undefined ? settings.screenPreferences : ({}) screenPreferences = settings.screenPreferences !== undefined ? settings.screenPreferences : ({})
pluginSettings = settings.pluginSettings !== undefined ? settings.pluginSettings : ({})
animationSpeed = settings.animationSpeed !== undefined ? settings.animationSpeed : SettingsData.AnimationSpeed.Short animationSpeed = settings.animationSpeed !== undefined ? settings.animationSpeed : SettingsData.AnimationSpeed.Short
applyStoredTheme() applyStoredTheme()
detectAvailableIconThemes() detectAvailableIconThemes()
@@ -396,6 +425,11 @@ Singleton {
} finally { } finally {
_loading = false _loading = false
} }
if (shouldMigrate) {
savePluginSettings()
saveSettings()
}
} }
function saveSettings() { function saveSettings() {
@@ -507,11 +541,16 @@ Singleton {
"notificationPopupPosition": notificationPopupPosition, "notificationPopupPosition": notificationPopupPosition,
"osdAlwaysShowValue": osdAlwaysShowValue, "osdAlwaysShowValue": osdAlwaysShowValue,
"screenPreferences": screenPreferences, "screenPreferences": screenPreferences,
"pluginSettings": pluginSettings,
"animationSpeed": animationSpeed "animationSpeed": animationSpeed
}, null, 2)) }, null, 2))
} }
function savePluginSettings() {
if (_pluginSettingsLoading)
return
pluginSettingsFile.setText(JSON.stringify(pluginSettings, null, 2))
}
function setShowWorkspaceIndex(enabled) { function setShowWorkspaceIndex(enabled) {
showWorkspaceIndex = enabled showWorkspaceIndex = enabled
saveSettings() saveSettings()
@@ -1334,13 +1373,13 @@ Singleton {
pluginSettings[pluginId] = {} pluginSettings[pluginId] = {}
} }
pluginSettings[pluginId][key] = value pluginSettings[pluginId][key] = value
saveSettings() savePluginSettings()
} }
function removePluginSettings(pluginId) { function removePluginSettings(pluginId) {
if (pluginSettings[pluginId]) { if (pluginSettings[pluginId]) {
delete pluginSettings[pluginId] delete pluginSettings[pluginId]
saveSettings() savePluginSettings()
} }
} }
@@ -1424,6 +1463,26 @@ Singleton {
} }
} }
FileView {
id: pluginSettingsFile
path: isGreeterMode ? "" : pluginSettingsPath
blockLoading: true
blockWrites: true
atomicWrites: true
watchChanges: !isGreeterMode
onLoaded: {
if (!isGreeterMode) {
parsePluginSettings(pluginSettingsFile.text())
}
}
onLoadFailed: error => {
if (!isGreeterMode) {
pluginSettings = {}
}
}
}
Process { Process {
id: systemDefaultDetectionProcess id: systemDefaultDetectionProcess

View File

@@ -459,6 +459,10 @@ Singleton {
return SettingsData.getPluginSetting(pluginId, key, defaultValue) return SettingsData.getPluginSetting(pluginId, key, defaultValue)
} }
function saveAllPluginSettings() {
SettingsData.savePluginSettings()
}
function createPluginDirectory() { function createPluginDirectory() {
var mkdirProcess = Qt.createComponent("data:text/plain,import Quickshell.Io; Process { }") var mkdirProcess = Qt.createComponent("data:text/plain,import Quickshell.Io; Process { }")
if (mkdirProcess.status === Component.Ready) { if (mkdirProcess.status === Component.Ready) {