mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-25 08:49:49 +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 <iostream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include "PluginManager.hpp"
|
||||||
|
|
||||||
std::string DataState::getDataStatePath() {
|
std::string DataState::getDataStatePath() {
|
||||||
const auto HOME = getenv("HOME");
|
const auto HOME = getenv("HOME");
|
||||||
|
@ -92,6 +93,15 @@ void DataState::removePluginRepo(const std::string& urlOrName) {
|
||||||
const auto URL = STATE["repository"]["url"].value_or("");
|
const auto URL = STATE["repository"]["url"].value_or("");
|
||||||
|
|
||||||
if (URL == urlOrName || NAME == urlOrName) {
|
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());
|
std::filesystem::remove_all(entry.path());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,13 +494,15 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
|
||||||
// add repo toml to DataState
|
// add repo toml to DataState
|
||||||
SPluginRepository newrepo = repo;
|
SPluginRepository newrepo = repo;
|
||||||
newrepo.plugins.clear();
|
newrepo.plugins.clear();
|
||||||
std::string repohash = execAndGet(
|
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
|
"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)
|
if (repohash.length() > 0)
|
||||||
repohash.pop_back();
|
repohash.pop_back();
|
||||||
newrepo.hash = repohash;
|
newrepo.hash = repohash;
|
||||||
for (auto& p : pManifest->m_vPlugins) {
|
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::removePluginRepo(newrepo.name);
|
||||||
DataState::addNewPluginRepo(newrepo);
|
DataState::addNewPluginRepo(newrepo);
|
||||||
|
@ -545,7 +547,7 @@ void CPluginManager::ensurePluginsLoadState() {
|
||||||
std::cerr << "PluginManager: no $HOME or HIS\n";
|
std::cerr << "PluginManager: no $HOME or HIS\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto HYPRPMPATH = std::string(HOME) + "/.hyprpm/";
|
const auto HYPRPMPATH = DataState::getDataStatePath() + "/";
|
||||||
|
|
||||||
auto pluginLines = execAndGet("hyprctl plugins list | grep Plugin");
|
auto pluginLines = execAndGet("hyprctl plugins list | grep Plugin");
|
||||||
|
|
||||||
|
@ -600,7 +602,7 @@ void CPluginManager::ensurePluginsLoadState() {
|
||||||
for (auto& p : loadedPlugins) {
|
for (auto& p : loadedPlugins) {
|
||||||
if (!enabled(p)) {
|
if (!enabled(p)) {
|
||||||
// unload
|
// 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";
|
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())
|
if (std::find_if(loadedPlugins.begin(), loadedPlugins.end(), [&](const auto& other) { return other == p.name; }) != loadedPlugins.end())
|
||||||
continue;
|
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 << " Loaded " << p.name << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << Colors::GREEN << "✔" << Colors::RESET << " Plugin load state ensured\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 enablePlugin(const std::string& name);
|
||||||
bool disablePlugin(const std::string& name);
|
bool disablePlugin(const std::string& name);
|
||||||
void ensurePluginsLoadState();
|
void ensurePluginsLoadState();
|
||||||
|
|
||||||
|
bool loadUnloadPlugin(const std::string& path, bool load);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CPluginManager> g_pPluginManager;
|
inline std::unique_ptr<CPluginManager> g_pPluginManager;
|
|
@ -48,8 +48,10 @@ int main(int argc, char** argv, char** envp) {
|
||||||
} else if (ARGS[1] == "update") {
|
} else if (ARGS[1] == "update") {
|
||||||
bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
|
bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
|
||||||
bool headers = g_pPluginManager->updateHeaders();
|
bool headers = g_pPluginManager->updateHeaders();
|
||||||
if (headers)
|
if (headers) {
|
||||||
g_pPluginManager->updatePlugins(!headersValid);
|
g_pPluginManager->updatePlugins(!headersValid);
|
||||||
|
g_pPluginManager->ensurePluginsLoadState();
|
||||||
|
}
|
||||||
} else if (ARGS[1] == "enable") {
|
} else if (ARGS[1] == "enable") {
|
||||||
if (ARGS.size() < 3) {
|
if (ARGS.size() < 3) {
|
||||||
std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for enable.\n";
|
std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for enable.\n";
|
||||||
|
|
Loading…
Reference in a new issue