feat: settings is now json, refactor panels to be able to dismiss by clicking outside

This commit is contained in:
ferreo 2025-07-18 15:43:22 +01:00
parent 8a3d610d22
commit a498671ef1
36 changed files with 1282 additions and 1300 deletions

View file

@ -1,98 +1,66 @@
pragma Singleton
import QtQuick
import QtCore
import Quickshell
import Quickshell.Io
import qs.Services
QtObject {
Singleton {
Component.onCompleted: {
Qt.application.name = "quickshell"
Qt.application.organization = "quickshell"
Qt.application.domain = "quickshell.app"
loadSettings()
}
property string weatherCity: "Dinslaken"
property string profileImage: "/home/" + Quickshell.env("USER") + "/.face"
property bool useFahrenheit: false
property string wallpaperFolder: "/usr/share/wallpapers"
property string currentWallpaper: ""
property string videoPath: "~/Videos/"
property bool showActiveWindowIcon: false
property bool useSWWW: false
property bool randomWallpaper: false
property bool useWallpaperTheme: false
property bool showSystemInfoInBar: true
property bool showMediaInBar: false
property int wallpaperInterval: 300
property string wallpaperResize: "crop"
property int transitionFps: 60
property string transitionType: "random"
property real transitionDuration: 1.1
property string visualizerType: "radial" // Options: "fire", "diamond", "radial"
property string shellName: "Noctalia"
property string settingsDir: Quickshell.env("HOME") + "/.config/" + shellName + "/"
property string settingsFile: settingsDir + "Settings.json"
property var settings: settingAdapter
// Settings persistence
property var settings: Settings {
category: "quickshell"
Item {
Component.onCompleted: {
// ensure settings dir
Quickshell.execDetached(["mkdir", "-p", settingsDir]);
}
}
function loadSettings() {
weatherCity = settings.value("weatherCity", weatherCity)
profileImage = settings.value("profileImage", profileImage)
let tempUnit = settings.value("weatherTempUnit", "celsius")
useFahrenheit = (tempUnit === "fahrenheit")
wallpaperFolder = settings.value("wallpaperFolder", wallpaperFolder)
currentWallpaper = settings.value("currentWallpaper", currentWallpaper)
videoPath = settings.value("videoPath", videoPath)
let showActiveWindowIconFlag = settings.value("showActiveWindowIconFlag", "false")
showActiveWindowIcon = showActiveWindowIconFlag === "true"
let showSystemInfoInBarFlag = settings.value("showSystemInfoInBarFlag", "true")
showSystemInfoInBar = showSystemInfoInBarFlag === "true"
let showMediaInBarFlag = settings.value("showMediaInBarFlag", "true")
showMediaInBar = showMediaInBarFlag === "true"
let useSWWWFlag = settings.value("useSWWWFlag", "false")
useSWWW = useSWWWFlag === "true"
let randomWallpaperFlag = settings.value("randomWallpaperFlag", "false")
randomWallpaper = randomWallpaperFlag === "true"
let useWallpaperThemeFlag = settings.value("useWallpaperThemeFlag", "false")
useWallpaperTheme = useWallpaperThemeFlag === "true"
wallpaperInterval = settings.value("wallpaperInterval", wallpaperInterval)
wallpaperResize = settings.value("wallpaperResize", wallpaperResize)
transitionFps = settings.value("transitionFps", transitionFps)
transitionType = settings.value("transitionType", transitionType)
transitionDuration = settings.value("transitionDuration", transitionDuration)
visualizerType = settings.value("visualizerType", visualizerType)
WallpaperManager.setCurrentWallpaper(currentWallpaper, true);
FileView {
id: settingFileView
path: settingsFile
watchChanges: true
onFileChanged: reload()
onAdapterUpdated: writeAdapter()
Component.onCompleted: function() {
reload()
}
onLoaded: function() {
WallpaperManager.setCurrentWallpaper(settings.currentWallpaper, true);
}
onLoadFailed: function(error) {
settingAdapter = {}
writeAdapter()
}
JsonAdapter {
id: settingAdapter
property string weatherCity: "Dinslaken"
property string profileImage: Quickshell.env("HOME") + "/.face"
property bool useFahrenheit: false
property string wallpaperFolder: "/usr/share/wallpapers"
property string currentWallpaper: ""
property string videoPath: "~/Videos/"
property bool showActiveWindowIcon: false
property bool showSystemInfoInBar: false
property bool showMediaInBar: false
property bool useSWWW: false
property bool randomWallpaper: false
property bool useWallpaperTheme: false
property int wallpaperInterval: 300
property string wallpaperResize: "crop"
property int transitionFps: 60
property string transitionType: "random"
property real transitionDuration: 1.1
property string visualizerType: "radial"
}
}
function saveSettings() {
settings.setValue("weatherCity", weatherCity)
settings.setValue("profileImage", profileImage)
settings.setValue("weatherTempUnit", useFahrenheit ? "fahrenheit" : "celsius")
settings.setValue("wallpaperFolder", wallpaperFolder)
settings.setValue("currentWallpaper", currentWallpaper)
settings.setValue("videoPath", videoPath)
settings.setValue("showActiveWindowIconFlag", showActiveWindowIcon ? "true" : "false")
settings.setValue("showSystemInfoInBarFlag", showSystemInfoInBar ? "true" : "false")
settings.setValue("showMediaInBarFlag", showMediaInBar ? "true" : "false")
settings.setValue("useSWWWFlag", useSWWW ? "true" : "false")
settings.setValue("randomWallpaperFlag", randomWallpaper ? "true" : "false")
settings.setValue("useWallpaperThemeFlag", useWallpaperTheme ? "true" : "false")
settings.setValue("wallpaperInterval", wallpaperInterval)
settings.setValue("wallpaperResize", wallpaperResize)
settings.setValue("transitionFps", transitionFps)
settings.setValue("transitionType", transitionType)
settings.setValue("transitionDuration", transitionDuration)
settings.setValue("visualizerType", visualizerType)
settings.sync()
Connections {
target: settingAdapter
function onRandomWallpaperChanged() { WallpaperManager.toggleRandomWallpaper() }
function onWallpaperIntervalChanged() { WallpaperManager.restartRandomWallpaperTimer() }
function onWallpaperFolderChanged() { WallpaperManager.loadWallpapers() }
}
// Property change handlers to auto-save (all commented out for explicit save only)
// onWeatherCityChanged: saveSettings()
// onProfileImageChanged: saveSettings()
// onUseFahrenheitChanged: saveSettings()
onRandomWallpaperChanged: WallpaperManager.toggleRandomWallpaper()
onWallpaperIntervalChanged: WallpaperManager.restartRandomWallpaperTimer()
onWallpaperFolderChanged: WallpaperManager.loadWallpapers()
}
}

View file

@ -3,6 +3,7 @@ pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Settings
Singleton {
id: root
@ -14,11 +15,16 @@ Singleton {
// FileView to load theme data from JSON file
FileView {
id: themeFile
path: Quickshell.configDir + "/Settings/Theme.json"
path: Settings.settingsDir + "Theme.json"
watchChanges: true
onFileChanged: reload()
onAdapterUpdated: writeAdapter()
onLoadFailed: function(error) {
if (error.includes("No such file")) {
themeData = {}
writeAdapter()
}
}
JsonAdapter {
id: themeData