add verbose

This commit is contained in:
Vaxry 2023-12-06 22:36:39 +00:00
parent ea304efd96
commit 8a99b94e76
3 changed files with 57 additions and 41 deletions

View file

@ -27,6 +27,28 @@ std::string execAndGet(std::string cmd) {
return result; return result;
} }
SHyprlandVersion CPluginManager::getHyprlandVersion() {
const auto HLVERCALL = execAndGet("hyprctl version");
if (m_bVerbose)
std::cout << Colors::BLUE << "[v] " << Colors::RESET << "version returned: " << HLVERCALL << "\n";
if (!HLVERCALL.contains("Tag:")) {
std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " You don't seem to be running Hyprland.";
return SHyprlandVersion{};
}
std::string hlcommit = HLVERCALL.substr(HLVERCALL.find("at commit") + 10);
hlcommit = hlcommit.substr(0, hlcommit.find_first_of(' '));
std::string hlbranch = HLVERCALL.substr(HLVERCALL.find("from branch") + 12);
hlbranch = hlbranch.substr(0, hlbranch.find(" at commit "));
if (m_bVerbose)
std::cout << Colors::BLUE << "[v] " << Colors::RESET << "parsed commit " << hlcommit << " at branch " << hlbranch << "\n";
return SHyprlandVersion{hlbranch, hlcommit};
}
bool CPluginManager::addNewPluginRepo(const std::string& url) { bool CPluginManager::addNewPluginRepo(const std::string& url) {
if (DataState::pluginRepoExists(url)) { if (DataState::pluginRepoExists(url)) {
@ -155,6 +177,10 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) {
if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) { if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) {
std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " Plugin " << p.name << " failed to build.\n"; std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " Plugin " << p.name << " failed to build.\n";
if (m_bVerbose)
std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n";
return false; return false;
} }
@ -216,13 +242,7 @@ bool CPluginManager::removePluginRepo(const std::string& urlOrName) {
} }
eHeadersErrors CPluginManager::headersValid() { eHeadersErrors CPluginManager::headersValid() {
const auto HLVERCALL = execAndGet("hyprctl version"); const auto HLVER = getHyprlandVersion();
if (!HLVERCALL.contains("Tag:"))
return HEADERS_NOT_HYPRLAND;
std::string hlcommit = HLVERCALL.substr(HLVERCALL.find("at commit") + 10);
hlcommit = hlcommit.substr(0, hlcommit.find_first_of(' '));
// find headers commit // find headers commit
auto headers = execAndGet("pkg-config --cflags hyprland"); auto headers = execAndGet("pkg-config --cflags hyprland");
@ -265,7 +285,7 @@ eHeadersErrors CPluginManager::headersValid() {
hash = hash.substr(hash.find_first_of('"') + 1); hash = hash.substr(hash.find_first_of('"') + 1);
hash = hash.substr(0, hash.find_first_of('"')); hash = hash.substr(0, hash.find_first_of('"'));
if (hash != hlcommit) if (hash != HLVER.hash)
return HEADERS_MISMATCHED; return HEADERS_MISMATCHED;
return HEADERS_OK; return HEADERS_OK;
@ -273,18 +293,7 @@ eHeadersErrors CPluginManager::headersValid() {
bool CPluginManager::updateHeaders() { bool CPluginManager::updateHeaders() {
const auto HLVERCALL = execAndGet("hyprctl version"); const auto HLVER = getHyprlandVersion();
if (!HLVERCALL.contains("Tag:")) {
std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " You don't seem to be running Hyprland.";
return false;
}
std::string hlcommit = HLVERCALL.substr(HLVERCALL.find("at commit") + 10);
hlcommit = hlcommit.substr(0, hlcommit.find_first_of(' '));
std::string hlbranch = HLVERCALL.substr(HLVERCALL.find("from branch") + 12);
hlbranch = hlbranch.substr(0, hlbranch.find(" at commit "));
if (!std::filesystem::exists("/tmp/hyprpm")) { if (!std::filesystem::exists("/tmp/hyprpm")) {
std::filesystem::create_directory("/tmp/hyprpm"); std::filesystem::create_directory("/tmp/hyprpm");
@ -294,7 +303,7 @@ 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";
auto GLOBALSTATE = DataState::getGlobalState(); auto GLOBALSTATE = DataState::getGlobalState();
GLOBALSTATE.headersHashCompiled = hlcommit; GLOBALSTATE.headersHashCompiled = HLVER.hash;
DataState::updateGlobalState(GLOBALSTATE); DataState::updateGlobalState(GLOBALSTATE);
return true; return true;
} }
@ -324,7 +333,8 @@ 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 + " 2>&1 && git submodule update --init 2>&1 && git reset --hard --recurse-submodules " + hlcommit); ret =
execAndGet("cd /tmp/hyprpm/hyprland && git checkout " + HLVER.branch + " 2>&1 && git submodule update --init 2>&1 && git reset --hard --recurse-submodules " + HLVER.hash);
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;
@ -346,6 +356,9 @@ bool CPluginManager::updateHeaders() {
ret = execAndGet("pkexec sh \"-c\" \"cd /tmp/hyprpm/hyprland && make installheaders\""); ret = execAndGet("pkexec sh \"-c\" \"cd /tmp/hyprpm/hyprland && make installheaders\"");
if (m_bVerbose)
std::cout << Colors::BLUE << "[v] " << Colors::RESET << "pkexec returned: " << ret << "\n";
// remove build files // remove build files
std::filesystem::remove_all("/tmp/hyprpm/hyprland"); std::filesystem::remove_all("/tmp/hyprpm/hyprland");
@ -357,7 +370,7 @@ bool CPluginManager::updateHeaders() {
progress.print(); progress.print();
auto GLOBALSTATE = DataState::getGlobalState(); auto GLOBALSTATE = DataState::getGlobalState();
GLOBALSTATE.headersHashCompiled = hlcommit; GLOBALSTATE.headersHashCompiled = HLVER.hash;
DataState::updateGlobalState(GLOBALSTATE); DataState::updateGlobalState(GLOBALSTATE);
std::cout << "\n"; std::cout << "\n";
@ -388,15 +401,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
return true; return true;
} }
const auto HLVERCALL = execAndGet("hyprctl version"); const auto HLVER = getHyprlandVersion();
if (!HLVERCALL.contains("Tag:")) {
std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " You don't seem to be running Hyprland.";
return false;
}
std::string hlcommit = HLVERCALL.substr(HLVERCALL.find("at commit") + 10);
hlcommit = hlcommit.substr(0, hlcommit.find_first_of(' '));
CProgressBar progress; CProgressBar progress;
progress.m_iMaxSteps = REPOS.size() * 2 + 1; progress.m_iMaxSteps = REPOS.size() * 2 + 1;
@ -477,7 +482,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
progress.printMessageAbove(std::string{Colors::RESET} + " → Manifest has " + std::to_string(pManifest->m_sRepository.commitPins.size()) + " pins, checking"); progress.printMessageAbove(std::string{Colors::RESET} + " → Manifest has " + std::to_string(pManifest->m_sRepository.commitPins.size()) + " pins, checking");
for (auto& [hl, plugin] : pManifest->m_sRepository.commitPins) { for (auto& [hl, plugin] : pManifest->m_sRepository.commitPins) {
if (hl != hlcommit) if (hl != HLVER.hash)
continue; continue;
progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " commit pin " + plugin + " matched hl, resetting"); progress.printMessageAbove(std::string{Colors::GREEN} + "" + Colors::RESET + " commit pin " + plugin + " matched hl, resetting");
@ -499,6 +504,8 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
if (!std::filesystem::exists("/tmp/hyprpm/update/" + p.output)) { if (!std::filesystem::exists("/tmp/hyprpm/update/" + p.output)) {
std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " Plugin " << p.name << " failed to build.\n"; std::cerr << "\n" << Colors::RED << "" << Colors::RESET << " Plugin " << p.name << " failed to build.\n";
failed = true; failed = true;
if (m_bVerbose)
std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n";
break; break;
} }

View file

@ -3,8 +3,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
enum eHeadersErrors enum eHeadersErrors {
{
HEADERS_OK = 0, HEADERS_OK = 0,
HEADERS_NOT_HYPRLAND, HEADERS_NOT_HYPRLAND,
HEADERS_MISSING, HEADERS_MISSING,
@ -12,8 +11,7 @@ enum eHeadersErrors
HEADERS_MISMATCHED, HEADERS_MISMATCHED,
}; };
enum eNotifyIcons enum eNotifyIcons {
{
ICON_WARNING = 0, ICON_WARNING = 0,
ICON_INFO, ICON_INFO,
ICON_HINT, ICON_HINT,
@ -23,14 +21,18 @@ enum eNotifyIcons
ICON_NONE ICON_NONE
}; };
enum ePluginLoadStateReturn enum ePluginLoadStateReturn {
{
LOADSTATE_OK = 0, LOADSTATE_OK = 0,
LOADSTATE_FAIL, LOADSTATE_FAIL,
LOADSTATE_PARTIAL_FAIL, LOADSTATE_PARTIAL_FAIL,
LOADSTATE_HEADERS_OUTDATED LOADSTATE_HEADERS_OUTDATED
}; };
struct SHyprlandVersion {
std::string branch;
std::string hash;
};
class CPluginManager { class CPluginManager {
public: public:
bool addNewPluginRepo(const std::string& url); bool addNewPluginRepo(const std::string& url);
@ -47,8 +49,11 @@ class CPluginManager {
ePluginLoadStateReturn ensurePluginsLoadState(); ePluginLoadStateReturn ensurePluginsLoadState();
bool loadUnloadPlugin(const std::string& path, bool load); bool loadUnloadPlugin(const std::string& path, bool load);
SHyprlandVersion getHyprlandVersion();
void notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message); void notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message);
bool m_bVerbose = false;
}; };
inline std::unique_ptr<CPluginManager> g_pPluginManager; inline std::unique_ptr<CPluginManager> g_pPluginManager;

View file

@ -22,6 +22,7 @@ const std::string HELP = R"#(┏ hyprpm, a Hyprland Plugin Manager
--notify | -n Send a hyprland notification for important events (e.g. load fail) --notify | -n Send a hyprland notification for important events (e.g. load fail)
--help | -h Show this menu --help | -h Show this menu
--verbose | -v Enable too much logging
)#"; )#";
@ -37,7 +38,7 @@ int main(int argc, char** argv, char** envp) {
} }
std::vector<std::string> command; std::vector<std::string> command;
bool notify = false; bool notify = false, verbose = false;
for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) {
if (ARGS[i].starts_with("-")) { if (ARGS[i].starts_with("-")) {
@ -46,6 +47,8 @@ int main(int argc, char** argv, char** envp) {
return 0; return 0;
} else if (ARGS[i] == "--notify" || ARGS[i] == "-n") { } else if (ARGS[i] == "--notify" || ARGS[i] == "-n") {
notify = true; notify = true;
} else if (ARGS[i] == "--verbose" || ARGS[i] == "-v") {
verbose = true;
} else { } else {
std::cerr << "Unrecognized option " << ARGS[i]; std::cerr << "Unrecognized option " << ARGS[i];
return 1; return 1;
@ -56,6 +59,7 @@ int main(int argc, char** argv, char** envp) {
} }
g_pPluginManager = std::make_unique<CPluginManager>(); g_pPluginManager = std::make_unique<CPluginManager>();
g_pPluginManager->m_bVerbose = verbose;
if (command[0] == "add") { if (command[0] == "add") {
if (command.size() < 2) { if (command.size() < 2) {