mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-27 23:12:49 -05:00
Auto-detect wallpaper changes, prefs in ~/.config/DankMaterialShell
This commit is contained in:
106
Common/Prefs.qml
106
Common/Prefs.qml
@@ -1,40 +1,102 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
import Qt.labs.settings
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property alias themeIndex: settings.themeIndex
|
||||
property alias themeIsDynamic: settings.themeIsDynamic
|
||||
property int themeIndex: 0
|
||||
property bool themeIsDynamic: false
|
||||
|
||||
Settings {
|
||||
id: settings
|
||||
category: "theme"
|
||||
|
||||
// 0-9 = built-in static themes, 10 = Auto (dynamic)
|
||||
property int themeIndex: 0
|
||||
property bool themeIsDynamic: false
|
||||
}
|
||||
readonly property string configDir: Qt.resolvedUrl("file://" + Quickshell.env("HOME") + "/.config/DankMaterialDark")
|
||||
readonly property string configFile: configDir + "/settings.json"
|
||||
|
||||
// Apply theme when component is ready
|
||||
Component.onCompleted: {
|
||||
console.log("Prefs Component.onCompleted - themeIndex:", settings.themeIndex, "isDynamic:", settings.themeIsDynamic)
|
||||
loadSettings()
|
||||
Qt.callLater(applyStoredTheme)
|
||||
}
|
||||
|
||||
function applyStoredTheme() {
|
||||
console.log("Applying stored theme:", settings.themeIndex, settings.themeIsDynamic)
|
||||
Process {
|
||||
id: mkdirProcess
|
||||
running: false
|
||||
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
console.log("Config directory created successfully")
|
||||
}
|
||||
// Reload settings file after directory creation completes
|
||||
settingsFileView.reload()
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: writeProcess
|
||||
running: false
|
||||
|
||||
onExited: (exitCode) => {
|
||||
if (exitCode === 0) {
|
||||
console.log("Settings saved successfully")
|
||||
} else {
|
||||
console.error("Failed to save settings, exit code:", exitCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileView {
|
||||
id: settingsFileView
|
||||
path: "file://" + Quickshell.env("HOME") + "/.config/DankMaterialDark/settings.json"
|
||||
|
||||
onLoaded: {
|
||||
console.log("Settings file loaded successfully")
|
||||
try {
|
||||
var content = settingsFileView.text()
|
||||
console.log("Settings file content:", content)
|
||||
if (content && content.trim()) {
|
||||
var settings = JSON.parse(content)
|
||||
themeIndex = settings.themeIndex !== undefined ? settings.themeIndex : 0
|
||||
themeIsDynamic = settings.themeIsDynamic !== undefined ? settings.themeIsDynamic : false
|
||||
console.log("Loaded settings - themeIndex:", themeIndex, "isDynamic:", themeIsDynamic)
|
||||
} else {
|
||||
console.log("Settings file is empty")
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Could not parse settings, using defaults:", e)
|
||||
}
|
||||
}
|
||||
|
||||
onLoadFailed: (error) => {
|
||||
console.log("Settings file not found, using defaults. Error:", error)
|
||||
}
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
mkdirProcess.command = ["mkdir", "-p", Quickshell.env("HOME") + "/.config/DankMaterialDark"]
|
||||
mkdirProcess.running = true
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
var settings = {
|
||||
themeIndex: themeIndex,
|
||||
themeIsDynamic: themeIsDynamic
|
||||
}
|
||||
|
||||
var content = JSON.stringify(settings, null, 2)
|
||||
|
||||
writeProcess.command = ["sh", "-c", "echo '" + content + "' > '" + Quickshell.env("HOME") + "/.config/DankMaterialDark/settings.json'"]
|
||||
writeProcess.running = true
|
||||
console.log("Saving settings - themeIndex:", themeIndex, "isDynamic:", themeIsDynamic)
|
||||
}
|
||||
|
||||
function applyStoredTheme() {
|
||||
console.log("Applying stored theme:", themeIndex, themeIsDynamic)
|
||||
|
||||
// Make sure Theme is available
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.switchTheme(settings.themeIndex, settings.themeIsDynamic, false) // Don't save during startup
|
||||
Theme.switchTheme(themeIndex, themeIsDynamic, false)
|
||||
} else {
|
||||
// Try again in a moment
|
||||
Qt.callLater(() => {
|
||||
if (typeof Theme !== "undefined") {
|
||||
Theme.switchTheme(settings.themeIndex, settings.themeIsDynamic, false) // Don't save during startup
|
||||
Theme.switchTheme(themeIndex, themeIsDynamic, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -42,8 +104,8 @@ Singleton {
|
||||
|
||||
function setTheme(index, isDynamic) {
|
||||
console.log("Prefs setTheme called - themeIndex:", index, "isDynamic:", isDynamic)
|
||||
settings.themeIndex = index
|
||||
settings.themeIsDynamic = isDynamic
|
||||
console.log("Prefs saved - themeIndex:", settings.themeIndex, "isDynamic:", settings.themeIsDynamic)
|
||||
themeIndex = index
|
||||
themeIsDynamic = isDynamic
|
||||
saveSettings()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user