config: refuse to start with a bad config

This commit is contained in:
Vaxry
2026-01-02 18:21:20 +01:00
parent e4413583bc
commit 01e9c1f82b
3 changed files with 11 additions and 7 deletions

View File

@ -48,7 +48,7 @@ CConfigManager::CConfigManager(const std::string& configPath) :
m_currentConfigPath = configPath.empty() ? getMainConfigPath() : configPath; m_currentConfigPath = configPath.empty() ? getMainConfigPath() : configPath;
} }
void CConfigManager::init() { bool CConfigManager::init() {
m_config.addConfigValue("splash", Hyprlang::INT{1}); m_config.addConfigValue("splash", Hyprlang::INT{1});
m_config.addConfigValue("splash_offset", Hyprlang::INT{20}); m_config.addConfigValue("splash_offset", Hyprlang::INT{20});
m_config.addConfigValue("splash_opacity", Hyprlang::FLOAT{0.8}); m_config.addConfigValue("splash_opacity", Hyprlang::FLOAT{0.8});
@ -64,10 +64,13 @@ void CConfigManager::init() {
auto result = m_config.parse(); auto result = m_config.parse();
if (result.error) if (result.error) {
g_logger->log(LOG_ERR, "Config has errors:\n{}\nProceeding ignoring faulty entries", result.getError()); g_logger->log(LOG_ERR, "Config has errors:\n{}", result.getError());
return false;
}
g_matcher->addStates(getSettings()); g_matcher->addStates(getSettings());
return true;
} }
Hyprlang::CConfig* CConfigManager::hyprlang() { Hyprlang::CConfig* CConfigManager::hyprlang() {
@ -117,10 +120,10 @@ static std::expected<std::vector<std::string>, std::string> getFullPath(const st
if (std::filesystem::is_directory(resolvedPath)) if (std::filesystem::is_directory(resolvedPath))
for (const auto& entry : std::filesystem::directory_iterator(resolvedPath, std::filesystem::directory_options::skip_permission_denied)) { for (const auto& entry : std::filesystem::directory_iterator(resolvedPath, std::filesystem::directory_options::skip_permission_denied)) {
if (entry.is_regular_file() && isImage(entry.path())) if (entry.is_regular_file() && isImage(entry.path()))
result.push_back(entry.path()); result.push_back(entry.path());
if (result.size() >= maxImagesCount) if (result.size() >= maxImagesCount)
break; break;
} }
else if (isImage(resolvedPath)) else if (isImage(resolvedPath))

View File

@ -22,7 +22,7 @@ class CConfigManager {
constexpr static const uint32_t SETTING_INVALID = 0; constexpr static const uint32_t SETTING_INVALID = 0;
void init(); bool init();
Hyprlang::CConfig* hyprlang(); Hyprlang::CConfig* hyprlang();
std::vector<SSetting> getSettings(); std::vector<SSetting> getSettings();

View File

@ -31,7 +31,8 @@ int main(int argc, const char** argv, const char** envp) {
g_logger->log(LOG_DEBUG, "Welcome to hyprpaper!\nbuilt from commit {} ({})", GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE); g_logger->log(LOG_DEBUG, "Welcome to hyprpaper!\nbuilt from commit {} ({})", GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE);
g_config = makeUnique<CConfigManager>(std::string{parser.getString("config").value_or("")}); g_config = makeUnique<CConfigManager>(std::string{parser.getString("config").value_or("")});
g_config->init(); if (!g_config->init())
return 1;
g_ui = makeUnique<CUI>(); g_ui = makeUnique<CUI>();
g_ui->run(); g_ui->run();