implement theme file storage

This commit is contained in:
Benjamin Palko 2025-09-05 13:12:40 -04:00
parent c53f0c2c41
commit a44b6f5e44
2 changed files with 41 additions and 8 deletions

View file

@ -14,13 +14,8 @@ Singleton {
property string fontFamily: "JetBrainsMono Nerd Font"
property var palette: theme.palette
property list<string> themes: []
onThemesChanged: {
if (!themes.includes(currentTheme)) {
currentTheme = "dark";
}
}
property string currentTheme: "dark"
property alias themes: cache.themes
property alias currentTheme: cache.current
Process {
running: true
@ -41,7 +36,28 @@ Singleton {
}
FileView {
id: jsonFile
path: `${Paths.cache}/theme.json`
watchChanges: true
onFileChanged: reload()
// when changes are made to properties in the adapter, save them
onAdapterUpdated: writeAdapter()
JsonAdapter {
id: cache
property string current: "dark"
property list<string> themes: ["dark"]
onThemesChanged: {
if (!themes.includes(current)) {
current = themes[0];
}
}
}
}
FileView {
path: `${Paths.config}/themes/${root.currentTheme}.json`
watchChanges: true
onFileChanged: reload()

View file

@ -61,6 +61,23 @@ StyledWindow {
}
}
ColumnLayout {
StyledText {
text: "Theme Selector"
font.pixelSize: 18
}
RowLayout {
Repeater {
model: Theme.themes
delegate: StyledButton {
required property var modelData
text: modelData
onClicked: Theme.currentTheme = modelData
}
}
}
}
ColumnLayout {
StyledText {
text: "Switch"