This commit is contained in:
Vaxry 2023-12-06 22:23:10 +00:00
parent 657cee2b98
commit ea304efd96
3 changed files with 40 additions and 6 deletions

View file

@ -118,6 +118,7 @@ void DataState::updateGlobalState(const SGlobalState& state) {
auto DATA = toml::table{ auto DATA = toml::table{
{"state", toml::table{ {"state", toml::table{
{"hash", state.headersHashCompiled}, {"hash", state.headersHashCompiled},
{"dont_warn_install", state.dontWarnInstall}
}} }}
}; };
// clang-format on // clang-format on
@ -127,6 +128,23 @@ void DataState::updateGlobalState(const SGlobalState& state) {
ofs.close(); ofs.close();
} }
SGlobalState DataState::getGlobalState() {
ensureStateStoreExists();
const auto PATH = getDataStatePath();
if (!std::filesystem::exists(PATH + "/state.toml"))
return SGlobalState{};
auto DATA = toml::parse_file(PATH + "/state.toml");
SGlobalState state;
state.headersHashCompiled = DATA["state"]["hash"].value_or("");
state.dontWarnInstall = DATA["state"]["dont_warn_install"].value_or(false);
return state;
}
std::vector<SPluginRepository> DataState::getAllRepositories() { std::vector<SPluginRepository> DataState::getAllRepositories() {
ensureStateStoreExists(); ensureStateStoreExists();

View file

@ -4,7 +4,8 @@
#include "Plugin.hpp" #include "Plugin.hpp"
struct SGlobalState { struct SGlobalState {
std::string headersHashCompiled; std::string headersHashCompiled = "";
bool dontWarnInstall = false;
}; };
namespace DataState { namespace DataState {
@ -14,6 +15,7 @@ namespace DataState {
void removePluginRepo(const std::string& urlOrName); void removePluginRepo(const std::string& urlOrName);
bool pluginRepoExists(const std::string& urlOrName); bool pluginRepoExists(const std::string& urlOrName);
void updateGlobalState(const SGlobalState& state); void updateGlobalState(const SGlobalState& state);
SGlobalState getGlobalState();
bool setPluginEnabled(const std::string& name, bool enabled); bool setPluginEnabled(const std::string& name, bool enabled);
std::vector<SPluginRepository> getAllRepositories(); std::vector<SPluginRepository> getAllRepositories();
}; };

View file

@ -34,6 +34,15 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) {
return false; return false;
} }
auto GLOBALSTATE = DataState::getGlobalState();
if (!GLOBALSTATE.dontWarnInstall) {
std::cout << Colors::YELLOW << "!" << Colors::RED << " Disclaimer:\n " << Colors::RESET
<< "plugins, especially not official, have no guarantee of stability, availablity or security.\n Run them at your own risk.\n "
<< "This message will not appear again.\n";
GLOBALSTATE.dontWarnInstall = true;
DataState::updateGlobalState(GLOBALSTATE);
}
std::cout << Colors::GREEN << "" << Colors::RESET << Colors::RED << " adding a new plugin repository " << Colors::RESET << "from " << url << "\n " << Colors::RED std::cout << Colors::GREEN << "" << Colors::RESET << Colors::RED << " adding a new plugin repository " << Colors::RESET << "from " << url << "\n " << Colors::RED
<< "MAKE SURE" << Colors::RESET << " that you trust the authors. " << Colors::RED << "DO NOT" << Colors::RESET << "MAKE SURE" << Colors::RESET << " that you trust the authors. " << Colors::RED << "DO NOT" << Colors::RESET
<< " install random plugins without verifying the code and author.\n " << " install random plugins without verifying the code and author.\n "
@ -284,7 +293,9 @@ bool CPluginManager::updateHeaders() {
if (headersValid() == HEADERS_OK) { if (headersValid() == HEADERS_OK) {
std::cout << "\n" << std::string{Colors::GREEN} + "" + Colors::RESET + " Your headers are already up-to-date.\n"; std::cout << "\n" << std::string{Colors::GREEN} + "" + Colors::RESET + " Your headers are already up-to-date.\n";
DataState::updateGlobalState(SGlobalState{hlcommit}); auto GLOBALSTATE = DataState::getGlobalState();
GLOBALSTATE.headersHashCompiled = hlcommit;
DataState::updateGlobalState(GLOBALSTATE);
return true; return true;
} }
@ -313,7 +324,7 @@ bool CPluginManager::updateHeaders() {
progress.m_szCurrentMessage = "Checking out sources"; progress.m_szCurrentMessage = "Checking out sources";
progress.print(); progress.print();
ret = execAndGet("cd /tmp/hyprpm/hyprland && git checkout " + hlbranch + " && git submodule update --init && git reset --hard --recurse-submodules " + hlcommit); ret = execAndGet("cd /tmp/hyprpm/hyprland && git checkout " + hlbranch + " 2>&1 && git submodule update --init 2>&1 && git reset --hard --recurse-submodules " + hlcommit);
progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " checked out to running ver"); progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " checked out to running ver");
progress.m_iSteps = 3; progress.m_iSteps = 3;
@ -338,17 +349,20 @@ bool CPluginManager::updateHeaders() {
// remove build files // remove build files
std::filesystem::remove_all("/tmp/hyprpm/hyprland"); std::filesystem::remove_all("/tmp/hyprpm/hyprland");
if (headersValid() == HEADERS_OK) { auto HEADERSVALID = headersValid();
if (HEADERSVALID == HEADERS_OK) {
progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " installed headers"); progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " installed headers");
progress.m_iSteps = 5; progress.m_iSteps = 5;
progress.m_szCurrentMessage = "Done!"; progress.m_szCurrentMessage = "Done!";
progress.print(); progress.print();
DataState::updateGlobalState(SGlobalState{hlcommit}); auto GLOBALSTATE = DataState::getGlobalState();
GLOBALSTATE.headersHashCompiled = hlcommit;
DataState::updateGlobalState(GLOBALSTATE);
std::cout << "\n"; std::cout << "\n";
} else { } else {
progress.printMessageAbove(std::string{Colors::RED} + "" + Colors::RESET + " failed to install headers"); progress.printMessageAbove(std::string{Colors::RED} + "" + Colors::RESET + " failed to install headers with error code " + std::to_string((int)HEADERSVALID));
progress.m_iSteps = 5; progress.m_iSteps = 5;
progress.m_szCurrentMessage = "Failed"; progress.m_szCurrentMessage = "Failed";
progress.print(); progress.print();