Skip to content

Commit

Permalink
glaze, getpluginstates, ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
zjeffer committed Dec 25, 2024
1 parent 9c578d2 commit f4ff963
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 70 deletions.
9 changes: 9 additions & 0 deletions .github/actions/setup_base/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ runs:
librsvg \
re2
- name: Get glaze
shell: bash
run: |
git clone https://github.com/stephenberry/glaze.git
cd glaze
cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build
cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF`
cmake --install build
- name: Get hyprwayland-scanner-git
shell: bash
run: |
Expand Down
5 changes: 3 additions & 2 deletions hyprpm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp")

set(CMAKE_CXX_STANDARD 23)

pkg_check_modules(hyprpm_deps REQUIRED IMPORTED_TARGET tomlplusplus nlohmann_json hyprutils>=0.2.4)
pkg_check_modules(hyprpm_deps REQUIRED IMPORTED_TARGET tomlplusplus hyprutils>=0.2.4)
find_package(glaze REQUIRED)

add_executable(hyprpm ${SRCFILES})

target_link_libraries(hyprpm PUBLIC PkgConfig::hyprpm_deps)
target_link_libraries(hyprpm PUBLIC PkgConfig::hyprpm_deps glaze::glaze)

# binary
install(TARGETS hyprpm)
Expand Down
82 changes: 34 additions & 48 deletions hyprpm/src/core/DataState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ std::string DataState::getHeadersPath() {
return getDataStatePath() / "headersRoot";
}

std::vector<std::filesystem::path> DataState::getPluginStates() {
ensureStateStoreExists();

std::vector<std::filesystem::path> states;
for (const auto& entry : std::filesystem::directory_iterator(getDataStatePath())) {
if (!entry.is_directory() || entry.path().stem() == "headersRoot")
continue;

const auto stateFile = entry.path() / "state.toml";
if (!std::filesystem::exists(stateFile))
continue;

states.emplace_back(stateFile);
}
return states;
}

void DataState::ensureStateStoreExists() {
const auto PATH = getDataStatePath();

Expand Down Expand Up @@ -73,18 +90,10 @@ bool DataState::pluginRepoExists(const std::string& urlOrName) {

const auto PATH = getDataStatePath();

for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
if (!entry.is_directory() || entry.path().stem() == "headersRoot")
continue;

const auto stateFile = entry.path() / "state.toml";
if (!std::filesystem::exists(stateFile))
continue;

auto STATE = toml::parse_file(stateFile.c_str());

const auto NAME = STATE["repository"]["name"].value_or("");
const auto URL = STATE["repository"]["url"].value_or("");
for (const auto& stateFile : getPluginStates()) {
const auto STATE = toml::parse_file(stateFile.c_str());
const auto NAME = STATE["repository"]["name"].value_or("");
const auto URL = STATE["repository"]["url"].value_or("");

if (URL == urlOrName || NAME == urlOrName)
return true;
Expand All @@ -98,30 +107,22 @@ void DataState::removePluginRepo(const std::string& urlOrName) {

const auto PATH = getDataStatePath();

for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
if (!entry.is_directory() || entry.path().stem() == "headersRoot")
continue;

const auto stateFile = entry.path() / "state.toml";
if (!std::filesystem::exists(stateFile))
continue;

auto STATE = toml::parse_file(stateFile.c_str());

const auto NAME = STATE["repository"]["name"].value_or("");
const auto URL = STATE["repository"]["url"].value_or("");
for (const auto& stateFile : getPluginStates()) {
const auto STATE = toml::parse_file(stateFile.c_str());
const auto NAME = STATE["repository"]["name"].value_or("");
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())) {
for (const auto& file : std::filesystem::directory_iterator(stateFile.parent_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(stateFile.parent_path());
return;
}
}
Expand Down Expand Up @@ -170,16 +171,8 @@ std::vector<SPluginRepository> DataState::getAllRepositories() {
const auto PATH = getDataStatePath();

std::vector<SPluginRepository> repos;

for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
if (!entry.is_directory() || entry.path().stem() == "headersRoot")
continue;

const auto stateFile = entry.path() / "state.toml";
if (!std::filesystem::exists(stateFile))
continue;

auto STATE = toml::parse_file(stateFile.c_str());
for (const auto& stateFile : getPluginStates()) {
const auto STATE = toml::parse_file(stateFile.c_str());

const auto NAME = STATE["repository"]["name"].value_or("");
const auto URL = STATE["repository"]["url"].value_or("");
Expand Down Expand Up @@ -214,16 +207,8 @@ bool DataState::setPluginEnabled(const std::string& name, bool enabled) {

const auto PATH = getDataStatePath();

for (const auto& entry : std::filesystem::directory_iterator(PATH)) {
if (!entry.is_directory() || entry.path().stem() == "headersRoot")
continue;

const auto stateFile = entry.path() / "state.toml";
if (!std::filesystem::exists(stateFile))
continue;

auto STATE = toml::parse_file(stateFile.c_str());

for (const auto& stateFile : getPluginStates()) {
const auto STATE = toml::parse_file(stateFile.c_str());
for (const auto& [key, val] : STATE) {
if (key == "repository")
continue;
Expand All @@ -236,10 +221,11 @@ bool DataState::setPluginEnabled(const std::string& name, bool enabled) {
if (FAILED)
return false;

(*STATE[key].as_table()).insert_or_assign("enabled", enabled);
auto modifiedState = STATE;
(*modifiedState[key].as_table()).insert_or_assign("enabled", enabled);

std::ofstream state(stateFile, std::ios::trunc);
state << STATE;
state << modifiedState;
state.close();

return true;
Expand Down
21 changes: 11 additions & 10 deletions hyprpm/src/core/DataState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ struct SGlobalState {
};

namespace DataState {
std::filesystem::path getDataStatePath();
std::string getHeadersPath();
void ensureStateStoreExists();
void addNewPluginRepo(const SPluginRepository& repo);
void removePluginRepo(const std::string& urlOrName);
bool pluginRepoExists(const std::string& urlOrName);
void updateGlobalState(const SGlobalState& state);
SGlobalState getGlobalState();
bool setPluginEnabled(const std::string& name, bool enabled);
std::vector<SPluginRepository> getAllRepositories();
std::filesystem::path getDataStatePath();
std::string getHeadersPath();
std::vector<std::filesystem::path> getPluginStates();
void ensureStateStoreExists();
void addNewPluginRepo(const SPluginRepository& repo);
void removePluginRepo(const std::string& urlOrName);
bool pluginRepoExists(const std::string& urlOrName);
void updateGlobalState(const SGlobalState& state);
SGlobalState getGlobalState();
bool setPluginEnabled(const std::string& name, bool enabled);
std::vector<SPluginRepository> getAllRepositories();
};
19 changes: 9 additions & 10 deletions hyprpm/src/core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <unistd.h>

#include <toml++/toml.hpp>
#include <nlohmann/json.hpp>
#include <glaze/glaze.hpp>

#include <hyprutils/string/String.hpp>
#include <hyprutils/os/Process.hpp>
Expand Down Expand Up @@ -794,20 +794,19 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
}
const auto HYPRPMPATH = DataState::getDataStatePath();

const auto json = nlohmann::json::parse(execAndGet("hyprctl plugins list -j"));

if (!json.is_array()) {
std::println(stderr, "PluginManager: couldn't parse plugin list");
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) {
if (!plugin.contains("name")) {
std::println(stderr, "PluginManager: plugin doesn't have a name?");
continue;
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.push_back(plugin["name"]);
loadedPlugins.emplace_back(plugin["name"].get<std::string>());
}

std::println("{}", successString("Ensuring plugin load state"));
Expand Down
1 change: 1 addition & 0 deletions hyprpm/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ executable(
dependency('hyprutils', version: '>= 0.1.1'),
dependency('threads'),
dependency('tomlplusplus'),
dependency('glaze'),
],
install: true,
)
Expand Down

0 comments on commit f4ff963

Please sign in to comment.