summaryrefslogtreecommitdiff
path: root/hyprpm/src/core/PluginManager.cpp
diff options
context:
space:
mode:
authorTuur Vanhoutte <4633209+zjeffer@users.noreply.github.com>2024-12-27 15:40:46 +0100
committerGitHub <noreply@github.com>2024-12-27 14:40:46 +0000
commit43ca66779b7d267cc6c52bdea75d3ff8eb60132f (patch)
tree0c4590d7def526cc88d5602f96781755db7e6c45 /hyprpm/src/core/PluginManager.cpp
parente75e2cdac79417ffdbbbe903f72668953483a4e7 (diff)
hyprpm: use glaze to parse hyprctl plugin list (#8812)
* Use std::filesystem::path in hyprpm DataState to avoid concatenating strings with (folder + "/" + file) * Added getPluginStates helper method in DataState * Small clang-tidy improvements
Diffstat (limited to 'hyprpm/src/core/PluginManager.cpp')
-rw-r--r--hyprpm/src/core/PluginManager.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp
index 48b108c8..a3bd5a09 100644
--- a/hyprpm/src/core/PluginManager.cpp
+++ b/hyprpm/src/core/PluginManager.cpp
@@ -7,10 +7,8 @@
#include <cstdio>
#include <iostream>
-#include <array>
#include <filesystem>
#include <print>
-#include <thread>
#include <fstream>
#include <algorithm>
#include <format>
@@ -21,6 +19,7 @@
#include <unistd.h>
#include <toml++/toml.hpp>
+#include <glaze/glaze.hpp>
#include <hyprutils/string/String.hpp>
#include <hyprutils/os/Process.hpp>
@@ -83,13 +82,13 @@ SHyprlandVersion CPluginManager::getHyprlandVersion(bool running) {
hlbranch = hlbranch.substr(0, hlbranch.find(" at commit "));
std::string hldate = HLVERCALL.substr(HLVERCALL.find("Date: ") + 6);
- hldate = hldate.substr(0, hldate.find("\n"));
+ hldate = hldate.substr(0, hldate.find('\n'));
std::string hlcommits;
if (HLVERCALL.contains("commits:")) {
hlcommits = HLVERCALL.substr(HLVERCALL.find("commits:") + 9);
- hlcommits = hlcommits.substr(0, hlcommits.find(" "));
+ hlcommits = hlcommits.substr(0, hlcommits.find(' '));
}
int commits = 0;
@@ -378,7 +377,7 @@ eHeadersErrors CPluginManager::headersValid() {
// find headers commit
const std::string& cmd = std::format("PKG_CONFIG_PATH=\"{}/share/pkgconfig\" pkgconf --cflags --keep-system-cflags hyprland", DataState::getHeadersPath());
- auto headers = execAndGet(cmd.c_str());
+ auto headers = execAndGet(cmd);
if (!headers.contains("-I/"))
return HEADERS_MISSING;
@@ -790,35 +789,28 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
const auto HOME = getenv("HOME");
const auto HIS = getenv("HYPRLAND_INSTANCE_SIGNATURE");
if (!HOME || !HIS) {
- std::println(stderr, "PluginManager: no $HOME or HIS");
+ std::println(stderr, "PluginManager: no $HOME or $HYPRLAND_INSTANCE_SIGNATURE");
return LOADSTATE_FAIL;
}
- const auto HYPRPMPATH = DataState::getDataStatePath() + "/";
+ const auto HYPRPMPATH = DataState::getDataStatePath();
- auto pluginLines = execAndGet("hyprctl plugins list | grep Plugin");
+ const auto json = glz::read_json<glz::json_t::array_t>(execAndGet("hyprctl plugins list -j"));
+ if (!json) {
+ std::println(stderr, "PluginManager: couldn't parse hyprctl output");
+ return LOADSTATE_FAIL;
+ }
std::vector<std::string> loadedPlugins;
+ for (const auto& plugin : json.value()) {
+ if (!plugin.is_object() || !plugin.contains("name")) {
+ std::println(stderr, "PluginManager: couldn't parse plugin object");
+ return LOADSTATE_FAIL;
+ }
+ loadedPlugins.emplace_back(plugin["name"].get<std::string>());
+ }
std::println("{}", successString("Ensuring plugin load state"));
- // iterate line by line
- while (!pluginLines.empty()) {
- auto plLine = pluginLines.substr(0, pluginLines.find('\n'));
-
- if (pluginLines.find('\n') != std::string::npos)
- pluginLines = pluginLines.substr(pluginLines.find('\n') + 1);
- else
- pluginLines = "";
-
- if (plLine.back() != ':')
- continue;
-
- plLine = plLine.substr(7);
- plLine = plLine.substr(0, plLine.find(" by "));
-
- loadedPlugins.push_back(plLine);
- }
-
// get state
const auto REPOS = DataState::getAllRepositories();
@@ -853,7 +845,7 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
for (auto const& p : loadedPlugins) {
if (!enabled(p)) {
// unload
- if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false)) {
+ if (!loadUnloadPlugin(HYPRPMPATH / repoForName(p) / (p + ".so"), false)) {
std::println("{}", infoString("{} will be unloaded after restarting Hyprland", p));
hyprlandVersionMismatch = true;
} else
@@ -870,7 +862,7 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
if (std::find_if(loadedPlugins.begin(), loadedPlugins.end(), [&](const auto& other) { return other == p.name; }) != loadedPlugins.end())
continue;
- if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true)) {
+ if (!loadUnloadPlugin(HYPRPMPATH / repoForName(p.name) / p.filename, true)) {
std::println("{}", infoString("{} will be loaded after restarting Hyprland", p.name));
hyprlandVersionMismatch = true;
} else