mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-02 14:26:00 +01:00
reload plugins after update
This commit is contained in:
parent
a1420968a5
commit
738ffb6e5f
4 changed files with 32 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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<CPluginManager> g_pPluginManager;
|
|
@ -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";
|
||||
|
|
Loading…
Reference in a new issue