From 7c7368a579afd908f3a4ca732d6fa47ee6d5796e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 30 Nov 2025 15:02:19 +0000 Subject: [PATCH] fix --- src/config/ConfigManager.cpp | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index cb4b6e8..36c2e07 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -7,6 +7,8 @@ #include "../helpers/Logger.hpp" #include "WallpaperMatcher.hpp" +using namespace std::string_literals; + static std::string getMainConfigPath() { static const auto paths = Hyprutils::Path::findConfig("hyprpaper"); @@ -42,6 +44,31 @@ Hyprlang::CConfig* CConfigManager::hyprlang() { return &m_config; } +static std::expected resolvePath(const std::string_view& sv) { + std::error_code ec; + const auto CAN = std::filesystem::canonical(sv, ec); + + if (ec) + return std::unexpected(std::format("invalid path: {}", ec.message())); + + return CAN; +} + +static std::expected getFullPath(const std::string_view& sv) { + if (sv.empty()) + return std::unexpected("empty path"); + + if (sv[0] == '~') { + static auto HOME = getenv("HOME"); + if (!HOME || HOME[0] == '\0') + return std::unexpected("home path but no $HOME"); + + return resolvePath(std::string{HOME} + "/"s + std::string{sv.substr(1)}); + } + + return resolvePath(sv); +} + std::vector CConfigManager::getSettings() { std::vector result; @@ -60,14 +87,14 @@ std::vector CConfigManager::getSettings() { continue; } - std::error_code ec; - auto canonical = std::filesystem::canonical(path, ec); - if (ec) { - g_logger->log(LOG_ERR, "Failed parsing wallpaper for key {}: path {} is not valid", key, path); + const auto RESOLVE_PATH = getFullPath(path); + + if (!RESOLVE_PATH) { + g_logger->log(LOG_ERR, "Failed to resolve path {}: {}", path, RESOLVE_PATH.error()); continue; } - result.emplace_back(SSetting{.monitor = std::move(monitor), .fitMode = std::move(fitMode), .path = std::move(canonical), .id = ++m_maxId}); + result.emplace_back(SSetting{.monitor = std::move(monitor), .fitMode = std::move(fitMode), .path = RESOLVE_PATH.value(), .id = ++m_maxId}); } return result;