diff options
author | vaxerski <[email protected]> | 2024-01-07 18:15:51 +0100 |
---|---|---|
committer | vaxerski <[email protected]> | 2024-01-07 18:15:51 +0100 |
commit | 9f2bde925bde09b4820a2cef369e9ddd930a746b (patch) | |
tree | 54d33a02f7b3c52364bf6fb10a7c367df658967e /hyprpm/src | |
parent | 7904188de9ca631436484cde733ef871f518d962 (diff) | |
download | Hyprland-9f2bde925bde09b4820a2cef369e9ddd930a746b.tar.gz Hyprland-9f2bde925bde09b4820a2cef369e9ddd930a746b.zip |
hyprpm: handle failed compilations gracefully
Diffstat (limited to 'hyprpm/src')
-rw-r--r-- | hyprpm/src/core/DataState.cpp | 11 | ||||
-rw-r--r-- | hyprpm/src/core/Manifest.hpp | 1 | ||||
-rw-r--r-- | hyprpm/src/core/Plugin.hpp | 3 | ||||
-rw-r--r-- | hyprpm/src/core/PluginManager.cpp | 17 |
4 files changed, 24 insertions, 8 deletions
diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp index d95f10bb..724c40ac 100644 --- a/hyprpm/src/core/DataState.cpp +++ b/hyprpm/src/core/DataState.cpp @@ -47,7 +47,8 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) { DATA.emplace(p.name, toml::table{ {"filename", p.name + ".so"}, - {"enabled", p.enabled} + {"enabled", p.enabled}, + {"failed", p.failed} }); } // clang-format on @@ -172,9 +173,10 @@ std::vector<SPluginRepository> DataState::getAllRepositories() { continue; const auto ENABLED = STATE[key]["enabled"].value_or(false); + const auto FAILED = STATE[key]["failed"].value_or(false); const auto FILENAME = STATE[key]["filename"].value_or(""); - repo.plugins.push_back(SPlugin{std::string{key.str()}, FILENAME, ENABLED}); + repo.plugins.push_back(SPlugin{std::string{key.str()}, FILENAME, ENABLED, FAILED}); } repos.push_back(repo); @@ -201,6 +203,11 @@ bool DataState::setPluginEnabled(const std::string& name, bool enabled) { if (key.str() != name) continue; + const auto FAILED = STATE[key]["failed"].value_or(false); + + if (FAILED) + return false; + (*STATE[key].as_table()).insert_or_assign("enabled", enabled); std::ofstream state(entry.path().string() + "/state.toml", std::ios::trunc); diff --git a/hyprpm/src/core/Manifest.hpp b/hyprpm/src/core/Manifest.hpp index 63e1791f..55b4a7f0 100644 --- a/hyprpm/src/core/Manifest.hpp +++ b/hyprpm/src/core/Manifest.hpp @@ -19,6 +19,7 @@ class CManifest { std::vector<std::string> authors; std::vector<std::string> buildSteps; std::string output; + bool failed = false; }; struct { diff --git a/hyprpm/src/core/Plugin.hpp b/hyprpm/src/core/Plugin.hpp index 32c02a49..a69478d1 100644 --- a/hyprpm/src/core/Plugin.hpp +++ b/hyprpm/src/core/Plugin.hpp @@ -6,7 +6,8 @@ struct SPlugin { std::string name; std::string filename; - bool enabled; + bool enabled = false; + bool failed = false; }; struct SPluginRepository { diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 3c091242..4cc93d4b 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -195,12 +195,14 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) { } if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) { - std::cerr << "\n" << Colors::RED << "✖" << Colors::RESET << " Plugin " << p.name << " failed to build.\n"; + progress.printMessageAbove(std::string{Colors::RED} + "✖" + Colors::RESET + " Plugin " + p.name + " failed to build.\n"); if (m_bVerbose) std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; - return false; + p.failed = true; + + continue; } progress.printMessageAbove(std::string{Colors::GREEN} + "✔" + Colors::RESET + " built " + p.name + " into " + p.output); @@ -220,7 +222,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) { repo.url = url; repo.hash = repohash; for (auto& p : pManifest->m_vPlugins) { - repo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/new/" + p.output, false}); + repo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/new/" + p.output, false, p.failed}); } DataState::addNewPluginRepo(repo); @@ -696,8 +698,13 @@ void CPluginManager::listAllPlugins() { std::cout << std::string{Colors::RESET} + " → Repository " + r.name + ":\n"; for (auto& p : r.plugins) { - std::cout << std::string{Colors::RESET} + " │ Plugin " + p.name + "\n └─ enabled: " << (p.enabled ? Colors::GREEN : Colors::RED) << (p.enabled ? "true" : "false") - << Colors::RESET << "\n"; + + std::cout << std::string{Colors::RESET} + " │ Plugin " + p.name; + + if (!p.failed) + std::cout << "\n └─ enabled: " << (p.enabled ? Colors::GREEN : Colors::RED) << (p.enabled ? "true" : "false") << Colors::RESET << "\n"; + else + std::cout << "\n └─ enabled: " << Colors::RED << "Plugin failed to build" << Colors::RESET << "\n"; } } } |