From 738ffb6e5f9de0404f6727d887080d7516e10bb5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 6 Dec 2023 18:08:36 +0000 Subject: [PATCH] reload plugins after update --- hyprpm/src/core/DataState.cpp | 10 ++++++++++ hyprpm/src/core/PluginManager.cpp | 23 +++++++++++++++++------ hyprpm/src/core/PluginManager.hpp | 2 ++ hyprpm/src/main.cpp | 4 +++- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp index 81aebeb2..af888898 100644 --- a/hyprpm/src/core/DataState.cpp +++ b/hyprpm/src/core/DataState.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "PluginManager.hpp" std::string DataState::getDataStatePath() { const auto HOME = getenv("HOME"); @@ -92,6 +93,15 @@ void DataState::removePluginRepo(const std::string& urlOrName) { const auto URL = STATE["repository"]["url"].value_or(""); if (URL == urlOrName || NAME == urlOrName) { + + // unload the plugins!! + for (const auto& file : std::filesystem::directory_iterator(entry.path())) { + if (!file.path().string().ends_with(".so")) + continue; + + g_pPluginManager->loadUnloadPlugin(std::filesystem::absolute(file.path()), false); + } + std::filesystem::remove_all(entry.path()); return; } diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 5f379587..b50fb040 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -494,13 +494,15 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { // add repo toml to DataState SPluginRepository newrepo = repo; newrepo.plugins.clear(); - std::string repohash = execAndGet( - "cd /tmp/hyprpm/update/ && git pull --recurse-submodules && git reset --hard --recurse-submodules && git rev-parse HEAD"); // repo hash in the state.toml has to match head and not any pin + execAndGet( + "cd /tmp/hyprpm/update/ && git pull --recurse-submodules && git reset --hard --recurse-submodules"); // repo hash in the state.toml has to match head and not any pin + std::string repohash = execAndGet("git rev-parse HEAD"); if (repohash.length() > 0) repohash.pop_back(); newrepo.hash = repohash; for (auto& p : pManifest->m_vPlugins) { - newrepo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/update/" + p.output, false}); + const auto OLDPLUGINIT = std::find_if(repo.plugins.begin(), repo.plugins.end(), [&](const auto& other) { return other.name == p.name; }); + newrepo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/update/" + p.output, OLDPLUGINIT != repo.plugins.end() ? OLDPLUGINIT->enabled : false}); } DataState::removePluginRepo(newrepo.name); DataState::addNewPluginRepo(newrepo); @@ -545,7 +547,7 @@ void CPluginManager::ensurePluginsLoadState() { std::cerr << "PluginManager: no $HOME or HIS\n"; return; } - const auto HYPRPMPATH = std::string(HOME) + "/.hyprpm/"; + const auto HYPRPMPATH = DataState::getDataStatePath() + "/"; auto pluginLines = execAndGet("hyprctl plugins list | grep Plugin"); @@ -600,7 +602,7 @@ void CPluginManager::ensurePluginsLoadState() { for (auto& p : loadedPlugins) { if (!enabled(p)) { // unload - execAndGet("hyprctl plugin unload " + HYPRPMPATH + repoForName(p) + "/" + p + ".so"); + loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false); std::cout << Colors::GREEN << "✔" << Colors::RESET << " Unloaded " << p << "\n"; } } @@ -614,10 +616,19 @@ void CPluginManager::ensurePluginsLoadState() { if (std::find_if(loadedPlugins.begin(), loadedPlugins.end(), [&](const auto& other) { return other == p.name; }) != loadedPlugins.end()) continue; - execAndGet("hyprctl plugin load " + HYPRPMPATH + repoForName(p.name) + "/" + p.filename); + loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true); std::cout << Colors::GREEN << "✔" << Colors::RESET << " Loaded " << p.name << "\n"; } } std::cout << Colors::GREEN << "✔" << Colors::RESET << " Plugin load state ensured\n"; +} + +bool CPluginManager::loadUnloadPlugin(const std::string& path, bool load) { + if (load) + execAndGet("hyprctl plugin load " + path); + else + execAndGet("hyprctl plugin unload " + path); + + return true; } \ No newline at end of file diff --git a/hyprpm/src/core/PluginManager.hpp b/hyprpm/src/core/PluginManager.hpp index 9cd6ddfa..f344c59d 100644 --- a/hyprpm/src/core/PluginManager.hpp +++ b/hyprpm/src/core/PluginManager.hpp @@ -24,6 +24,8 @@ class CPluginManager { bool enablePlugin(const std::string& name); bool disablePlugin(const std::string& name); void ensurePluginsLoadState(); + + bool loadUnloadPlugin(const std::string& path, bool load); }; inline std::unique_ptr g_pPluginManager; \ No newline at end of file diff --git a/hyprpm/src/main.cpp b/hyprpm/src/main.cpp index 62d4cee1..941692e4 100644 --- a/hyprpm/src/main.cpp +++ b/hyprpm/src/main.cpp @@ -48,8 +48,10 @@ int main(int argc, char** argv, char** envp) { } else if (ARGS[1] == "update") { bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK; bool headers = g_pPluginManager->updateHeaders(); - if (headers) + if (headers) { g_pPluginManager->updatePlugins(!headersValid); + g_pPluginManager->ensurePluginsLoadState(); + } } else if (ARGS[1] == "enable") { if (ARGS.size() < 3) { std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for enable.\n";