diff --git a/config/Theme.qml b/config/Theme.qml index afc58e4..b686079 100644 --- a/config/Theme.qml +++ b/config/Theme.qml @@ -14,13 +14,8 @@ Singleton { property string fontFamily: "JetBrainsMono Nerd Font" property var palette: theme.palette - property list 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 themes: ["dark"] + onThemesChanged: { + if (!themes.includes(current)) { + current = themes[0]; + } + } + } + } + + FileView { path: `${Paths.config}/themes/${root.currentTheme}.json` watchChanges: true onFileChanged: reload() diff --git a/modules/storybook/Storybook.qml b/modules/storybook/Storybook.qml index 5d9d10d..4e60d14 100644 --- a/modules/storybook/Storybook.qml +++ b/modules/storybook/Storybook.qml @@ -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"