From 2d47c2ed1b547ff68a0af427170e5d9284cfa21a Mon Sep 17 00:00:00 2001 From: quadbyte Date: Sun, 10 Aug 2025 09:18:23 -0400 Subject: [PATCH] Settings: new json model structure --- Helpers/Holidays.js | 2 +- Modules/Bar/Bar.qml | 4 +- Services/Scaling.qml | 2 +- Services/Settings.qml | 194 +++++++++++++++++++++++++--------------- Services/Time.qml | 4 +- Services/Wallpapers.qml | 34 +++---- Widgets/NPanel.qml | 2 +- Widgets/NText.qml | 2 +- Widgets/NTooltip.qml | 4 +- shell.qml | 1 - 10 files changed, 149 insertions(+), 100 deletions(-) diff --git a/Helpers/Holidays.js b/Helpers/Holidays.js index 4bb3a60..1b67774 100644 --- a/Helpers/Holidays.js +++ b/Helpers/Holidays.js @@ -9,7 +9,7 @@ function getCountryCode(callback) { return; } var xhr = new XMLHttpRequest(); - xhr.open("GET", "https://nominatim.openstreetmap.org/search?city="+ Settings.settings.weatherCity+"&country=&format=json&addressdetails=1&extratags=1", true); + xhr.open("GET", "https://nominatim.openstreetmap.org/search?city="+ Settings.data.location.name+"&country=&format=json&addressdetails=1&extratags=1", true); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { var response = JSON.parse(xhr.responseText); diff --git a/Modules/Bar/Bar.qml b/Modules/Bar/Bar.qml index 88b3ced..0983e57 100644 --- a/Modules/Bar/Bar.qml +++ b/Modules/Bar/Bar.qml @@ -14,8 +14,8 @@ PanelWindow { screen: modelData implicitHeight: Style.barHeight * scaling color: "transparent" - visible: Settings.settings.barMonitors.includes(modelData.name) - || (Settings.settings.barMonitors.length === 0) + visible: Settings.data.bar.monitors.includes(modelData.name) + || (Settings.data.bar.monitors.length === 0) anchors { top: true diff --git a/Services/Scaling.qml b/Services/Scaling.qml index d71fef4..7c15215 100644 --- a/Services/Scaling.qml +++ b/Services/Scaling.qml @@ -15,7 +15,7 @@ Singleton { // // 1) Per-monitor override wins // try { - // const overrides = Settings.settings.monitorScaleOverrides || {}; + // const overrides = Settings.data.ui.monitorsScale || {}; // if (currentScreen && currentScreen.name && overrides[currentScreen.name] !== undefined) { // const overrideValue = overrides[currentScreen.name] // if (isFinite(overrideValue)) return overrideValue diff --git a/Services/Settings.qml b/Services/Settings.qml index 37b7a21..3873d99 100644 --- a/Services/Settings.qml +++ b/Services/Settings.qml @@ -1,22 +1,20 @@ -pragma Singleton - import QtQuick import Quickshell import Quickshell.Io import qs.Services +pragma Singleton Singleton { - - property string shellName: "Noctalia" + property string shellName: "noctalia" property string settingsDir: Quickshell.env("NOCTALIA_SETTINGS_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env( "HOME") + "/.config") + "/" + shellName + "/" property string settingsFile: Quickshell.env("NOCTALIA_SETTINGS_FILE") - || (settingsDir + "Settings.json") + || (settingsDir + "settings.json") property string colorsFile: Quickshell.env("NOCTALIA_COLORS_FILE") - || (settingsDir + "Colors.json") - property var settings: settingAdapter + || (settingsDir + "colors.json") + property var data: settingAdapter Item { Component.onCompleted: { @@ -26,7 +24,14 @@ Singleton { } FileView { + + // TBC ? needed for SWWW only ? + // Qt.callLater(function () { + // WallpaperManager.setCurrentWallpaper(settings.currentWallpaper, true); + // }) + id: settingFileView + path: settingsFile watchChanges: true onFileChanged: reload() @@ -34,80 +39,127 @@ Singleton { Component.onCompleted: function () { reload() } - onLoaded: function () {// Qt.callLater(function () { - // WallpaperManager.setCurrentWallpaper(settings.currentWallpaper, true); - // }) - } + onLoaded: function () {} onLoadFailed: function (error) { - if (error.toString().includes("No such file") || error === 2) { + if (error.toString().includes("No such file") || error === 2) // File doesn't exist, create it with default values 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 showActiveWindow: true - property bool showActiveWindowIcon: false - property bool showSystemInfoInBar: false - property bool showCorners: false - property bool showTaskbar: true - 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" - property bool reverseDayMonth: false - property bool use12HourClock: false - property bool dimPanels: true - property real fontSizeMultiplier: 1.0 // Font size multiplier (1.0 = normal, 1.2 = 20% larger, 0.8 = 20% smaller) - property int taskbarIconSize: 24 // Taskbar icon button size in pixels (default: 32, smaller: 24, larger: 40) - property var pinnedExecs: [] // Added for AppLauncher pinned apps - property bool showDock: true - property bool dockExclusive: false - property bool wifiEnabled: false - property bool bluetoothEnabled: false - property int recordingFrameRate: 60 - property string recordingQuality: "very_high" - property string recordingCodec: "h264" - property string audioCodec: "opus" - property bool showCursor: true - property string colorRange: "limited" + // bar + property JsonObject bar - // Monitor/Display Settings - property var barMonitors: [] // Array of monitor names to show the bar on - property var dockMonitors: [] // Array of monitor names to show the dock on - property var notificationMonitors: [] // Array of monitor names to show notifications on, "*" means all monitors - property var monitorScaleOverrides: { + bar: JsonObject { + property bool showActiveWindow: true + property bool showActiveWindowIcon: false + property bool showSystemInfo: false + property bool showMedia: false + property list monitors: [] + } - } // Map of monitor name -> scale override (e.g., 0.8..2.0). When set, Colors.scale() returns this value + // general + property JsonObject general - property string fontFamily: "Roboto" // Family for all text + general: JsonObject { + property string avatarImage: Quickshell.env("HOME") + "/.face" + property bool dimDesktop: true + property bool showScreenCorners: false + } + + // location + property JsonObject location + + location: JsonObject { + property bool name: true + property bool useFahrenheit: false + property bool reverseDayMonth: false + property bool use12HourClock: false + } + + // screen recorder + property JsonObject screenRecorder + + screenRecorder: JsonObject { + property string directory: "~/Videos" + property int frameRate: 60 + property string audioCodec: "opus" + property string videoCodec: "h264" + property string quality: "very_high" + property string colorRange: "limited" + property bool showCursor: true + } + + // wallpaper + property JsonObject wallpaper + + wallpaper: JsonObject { + property string directory: "/usr/share/wallpapers" + property string current: "" + property bool isRandom: false + property int randomInterval: 300 + property bool generateTheme: false + property JsonObject swww + + onDirectoryChanged: WallpaperManager.loadWallpapers() + onIsRandomChanged: WallpaperManager.toggleRandomWallpaper() + onRandomIntervalChanged: WallpaperManager.restartRandomWallpaperTimer() + + swww: JsonObject { + property bool enabled: false + property string resizeMethod: "crop" + property int transitionFps: 60 + property string transitionType: "random" + property real transitionDuration: 1.1 + } + } + + // applauncher + property JsonObject appLauncher + + appLauncher: JsonObject { + property list pinnedExecs: [] + } + + // dock + property JsonObject dock + + dock: JsonObject { + property bool exclusive: false + property list monitors: [] + } + + // network + property JsonObject network + + network: JsonObject { + property bool wifiEnabled: true + property bool bluetoothEnabled: true + } + + // notifications + property JsonObject notifications + + notifications: JsonObject { + property list monitors: [] + } + + // audioVisualizer + property JsonObject audioVisualizer + + audioVisualizer: JsonObject { + property string type: "radial" + } + + // ui + property JsonObject ui + + ui: JsonObject { + property string fontFamily: "Roboto" // Family for all text + property list monitorsScale: [] + } } } - - Connections { - target: settingAdapter - function onRandomWallpaperChanged() { - WallpaperManager.toggleRandomWallpaper() - } - function onWallpaperIntervalChanged() { - WallpaperManager.restartRandomWallpaperTimer() - } - function onWallpaperFolderChanged() { - WallpaperManager.loadWallpapers() - } - function onNotificationMonitorsChanged() {} - } } diff --git a/Services/Time.qml b/Services/Time.qml index 0d43a9e..c9838b8 100644 --- a/Services/Time.qml +++ b/Services/Time.qml @@ -8,7 +8,7 @@ Singleton { id: root property var date: new Date() - property string time: Settings.settings.use12HourClock ? Qt.formatDateTime( + property string time: Settings.data.location.use12HourClock ? Qt.formatDateTime( date, "h:mm AP") : Qt.formatDateTime( date, "HH:mm") @@ -36,7 +36,7 @@ Singleton { } let month = now.toLocaleDateString(Qt.locale(), "MMMM") let year = now.toLocaleDateString(Qt.locale(), "yyyy") - return `${dayName}, ` + (Settings.settings.reverseDayMonth ? `${month} ${day}${suffix} ${year}` : `${day}${suffix} ${month} ${year}`) + return `${dayName}, ` + (Settings.data.location.reverseDayMonth ? `${month} ${day}${suffix} ${year}` : `${day}${suffix} ${month} ${year}`) } Timer { diff --git a/Services/Wallpapers.qml b/Services/Wallpapers.qml index 54c1cfb..2540a7a 100644 --- a/Services/Wallpapers.qml +++ b/Services/Wallpapers.qml @@ -17,17 +17,17 @@ Singleton { } property var wallpaperList: [] - property string currentWallpaper: Settings.settings.currentWallpaper + property string currentWallpaper: Settings.data.wallpaper.current property bool scanning: false - property string transitionType: Settings.settings.transitionType + property string transitionType: Settings.data.wallpaper.swww.transitionType property var randomChoices: ["fade", "left", "right", "top", "bottom", "wipe", "wave", "grow", "center", "any", "outer"] function loadWallpapers() { scanning = true wallpaperList = [] folderModel.folder = "" - folderModel.folder = "file://" + (Settings.settings.wallpaperFolder - !== undefined ? Settings.settings.wallpaperFolder : "") + folderModel.folder = "file://" + (Settings.data.wallpaper.directory + !== undefined ? Settings.data.wallpaper.directory : "") } function changeWallpaper(path) { @@ -37,14 +37,14 @@ Singleton { function setCurrentWallpaper(path, isInitial) { currentWallpaper = path if (!isInitial) { - Settings.settings.currentWallpaper = path + Settings.data.wallpaper.current = path } - if (Settings.settings.useSWWW) { - if (Settings.settings.transitionType === "random") { + if (Settings.data.swww.enabled) { + if (Settings.data.swww.transitionType === "random") { transitionType = randomChoices[Math.floor(Math.random( ) * randomChoices.length)] } else { - transitionType = Settings.settings.transitionType + transitionType = Settings.data.swww.transitionType } changeWallpaperProcess.running = true } @@ -66,31 +66,31 @@ Singleton { } function toggleRandomWallpaper() { - if (Settings.settings.randomWallpaper && !randomWallpaperTimer.running) { + if (Settings.data.wallpaper.isRandom && !randomWallpaperTimer.running) { randomWallpaperTimer.start() setRandomWallpaper() - } else if (!Settings.settings.randomWallpaper + } else if (!Settings.data.randomWallpaper && randomWallpaperTimer.running) { randomWallpaperTimer.stop() } } function restartRandomWallpaperTimer() { - if (Settings.settings.randomWallpaper) { + if (Settings.data.wallpaper.isRandom) { randomWallpaperTimer.stop() randomWallpaperTimer.start() } } function generateTheme() { - if (Settings.settings.useWallpaperTheme) { + if (Settings.data.wallpaper.generateTheme) { generateThemeProcess.running = true } } Timer { id: randomWallpaperTimer - interval: Settings.settings.wallpaperInterval * 1000 + interval: Settings.data.wallpaper.randomInterval * 1000 running: false repeat: true onTriggered: setRandomWallpaper() @@ -108,8 +108,8 @@ Singleton { var files = [] var filesSwww = [] for (var i = 0; i < count; i++) { - var filepath = (Settings.settings.wallpaperFolder - !== undefined ? Settings.settings.wallpaperFolder : "") + "/" + get( + var filepath = (Settings.data.wallpaper.folder + !== undefined ? Settings.data.wallpaper.folder : "") + "/" + get( i, "fileName") files.push(filepath) } @@ -121,8 +121,8 @@ Singleton { Process { id: changeWallpaperProcess - command: ["swww", "img", "--resize", Settings.settings.wallpaperResize, "--transition-fps", Settings.settings.transitionFps.toString( - ), "--transition-type", transitionType, "--transition-duration", Settings.settings.transitionDuration.toString( + command: ["swww", "img", "--resize", Settings.data.wallpaper.swww.resizeMethod, "--transition-fps", Settings.data.wallpaper.swww.transitionFps.toString( + ), "--transition-type", transitionType, "--transition-duration", Settings.data.wallpaper.transitionDuration.toString( ), currentWallpaper] running: false } diff --git a/Widgets/NPanel.qml b/Widgets/NPanel.qml index 2c9362c..7733f4d 100644 --- a/Widgets/NPanel.qml +++ b/Widgets/NPanel.qml @@ -7,7 +7,7 @@ PanelWindow { id: outerPanel readonly property real scaling: Scaling.scale(screen) - property bool showOverlay: Settings.settings.dimPanels + property bool showOverlay: Settings.data.general.dimDesktop property int topMargin: Style.barHeight * scaling property color overlayColor: showOverlay ? Colors.overlay : "transparent" signal dismissed diff --git a/Widgets/NText.qml b/Widgets/NText.qml index a26cff1..0b9b13a 100644 --- a/Widgets/NText.qml +++ b/Widgets/NText.qml @@ -7,7 +7,7 @@ Text { readonly property real scaling: Scaling.scale(screen) - font.family: Settings.settings.fontFamily + font.family: Settings.data.ui.fontFamily font.pointSize: Style.fontSizeMedium * scaling font.weight: Font.Bold color: Colors.textPrimary diff --git a/Widgets/NTooltip.qml b/Widgets/NTooltip.qml index 38a1393..482f9e2 100644 --- a/Widgets/NTooltip.qml +++ b/Widgets/NTooltip.qml @@ -111,12 +111,10 @@ Window { z: 1 } - Text { + NText { id: tooltipText anchors.centerIn: parent text: root.text - color: Colors.textPrimary - font.family: Settings.settings.fontFamily font.pointSize: Style.fontSizeMedium * scaling horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter diff --git a/shell.qml b/shell.qml index 03df77d..c905a8b 100644 --- a/shell.qml +++ b/shell.qml @@ -1,4 +1,3 @@ - // Disable reload popup //@ pragma Env QS_NO_RELOAD_POPUP=1 import QtQuick