From e8bca1722515487e35b9af715386710c2aacb755 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Thu, 19 Mar 2026 07:53:03 -0400 Subject: [PATCH] fix(config): ensure trailing slash --- Commons/Migrations/Migration44.qml | 5 ++--- Commons/Migrations/Migration46.qml | 4 ++-- Commons/Migrations/Migration47.qml | 6 ++---- Commons/Migrations/Migration56.qml | 3 ++- Commons/Settings.qml | 13 ++++++++++--- Scripts/python/src/theming/gtk-refresh.py | 9 ++++----- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Commons/Migrations/Migration44.qml b/Commons/Migrations/Migration44.qml index d13b21d13..a8623b7f6 100644 --- a/Commons/Migrations/Migration44.qml +++ b/Commons/Migrations/Migration44.qml @@ -1,5 +1,6 @@ import QtQuick import Quickshell +import qs.Commons QtObject { id: root @@ -7,9 +8,7 @@ QtObject { function migrate(adapter, logger, rawJson) { logger.i("Migration44", "Updating PAM pam/password.conf"); - // Copying logic from Settings.qml to avoid dependency on it - const shellName = "noctalia"; - const configDir = Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/" + shellName + "/"; + const configDir = Settings.configDir; const pamConfigDir = configDir + "pam"; const pamConfigFile = pamConfigDir + "/password.conf"; const pamConfigDirEsc = pamConfigDir.replace(/'/g, "'\\''"); diff --git a/Commons/Migrations/Migration46.qml b/Commons/Migrations/Migration46.qml index dc2482568..06a5aac32 100644 --- a/Commons/Migrations/Migration46.qml +++ b/Commons/Migrations/Migration46.qml @@ -1,5 +1,6 @@ import QtQuick import Quickshell +import qs.Commons QtObject { id: root @@ -7,8 +8,7 @@ QtObject { function migrate(adapter, logger, rawJson) { logger.i("Migration46", "Removing legacy PAM configuration file"); - const shellName = "noctalia"; - const configDir = Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/" + shellName + "/"; + const configDir = Settings.configDir; const pamConfigDir = configDir + "pam"; // Remove the entire pam directory if it exists const script = `rm -rf '${pamConfigDir}'`; diff --git a/Commons/Migrations/Migration47.qml b/Commons/Migrations/Migration47.qml index 30054010f..9eef2c014 100644 --- a/Commons/Migrations/Migration47.qml +++ b/Commons/Migrations/Migration47.qml @@ -1,5 +1,6 @@ import QtQuick import Quickshell +import qs.Commons QtObject { id: root @@ -7,10 +8,7 @@ QtObject { function migrate(adapter, logger, rawJson) { logger.i("Migration47", "Removing network_stats.json cache"); - // Remove the network_stats.json cache file (no longer used - autoscaling from history now) - const shellName = "noctalia"; - const cacheDir = Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env("HOME") + "/.cache") + "/" + shellName + "/"; - const networkStatsFile = cacheDir + "network_stats.json"; + const networkStatsFile = Settings.cacheDir + "network_stats.json"; Quickshell.execDetached(["rm", "-f", networkStatsFile]); logger.d("Migration47", "Removed network_stats.json"); diff --git a/Commons/Migrations/Migration56.qml b/Commons/Migrations/Migration56.qml index 1455d558e..95dec5397 100644 --- a/Commons/Migrations/Migration56.qml +++ b/Commons/Migrations/Migration56.qml @@ -1,5 +1,6 @@ import QtQuick import Quickshell +import qs.Commons QtObject { id: root @@ -8,7 +9,7 @@ QtObject { logger.i("Settings", "Migrating settings to v56 (Color Scheme Migration)"); const scriptPath = Quickshell.shellDir + "/Scripts/python/src/theming/migrate-colorschemes.py"; - const configDir = Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/noctalia"; + const configDir = Settings.configDir; logger.i("Settings", `Running color scheme migration script: ${scriptPath} with configDir: ${configDir}`); diff --git a/Commons/Settings.qml b/Commons/Settings.qml index 0b3a761ca..19a93a517 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -28,8 +28,9 @@ Singleton { readonly property int settingsVersion: 59 property bool isDebug: Quickshell.env("NOCTALIA_DEBUG") === "1" readonly property string shellName: "noctalia" - readonly property string configDir: Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/" + shellName + "/" - readonly property string cacheDir: Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env("HOME") + "/.cache") + "/" + shellName + "/" + readonly property string configDir: ensureTrailingSlash(Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/" + shellName + "/") + readonly property string cacheDir: ensureTrailingSlash(Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env("HOME") + "/.cache") + "/" + shellName + "/") + readonly property string settingsFile: Quickshell.env("NOCTALIA_SETTINGS_FILE") || (configDir + "settings.json") readonly property string defaultLocation: "Tokyo" readonly property string defaultAvatar: Quickshell.env("HOME") + "/.face" @@ -777,7 +778,13 @@ Singleton { } // ----------------------------------------------------- - // Function to preprocess paths by expanding "~" to user's home directory + // Preprocess paths by adding trailing "/" + function ensureTrailingSlash(path) { + return path.endsWith("/") ? path : path + "/"; + } + + // ----------------------------------------------------- + // Preprocess paths by expanding "~" to user's home directory function preprocessPath(path) { if (typeof path !== "string" || path === "") { return path; diff --git a/Scripts/python/src/theming/gtk-refresh.py b/Scripts/python/src/theming/gtk-refresh.py index 436bf91f0..2d6585279 100644 --- a/Scripts/python/src/theming/gtk-refresh.py +++ b/Scripts/python/src/theming/gtk-refresh.py @@ -121,15 +121,14 @@ async def refresh_theme(): async def get_config_dir() -> Path: - # 1. project-specific override - if value := os.environ.get("NOCTALIA_CONFIG_DIR"): - return Path(value).expanduser() + # Returns the XDG config home (e.g. ~/.config) + # GTK config lives at ~/.config/gtk-3.0/ and ~/.config/gtk-4.0/. - # 2. XDG standard + # 1. XDG standard if value := os.environ.get("XDG_CONFIG_HOME"): return Path(value).expanduser() - # 3. fallback + # 2. fallback return Path.home() / ".config"