aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2023-12-06 19:45:49 +0000
committerVaxry <[email protected]>2023-12-06 23:31:04 +0000
commitd5e404fbcb946115ac2319fae8bee09b4188cc0b (patch)
tree7ddf149c029e33c75097193aa22286340ecf4235
parent51fb8686abc24aa7673252a6445fd0ecf17b3351 (diff)
downloadHyprland-d5e404fbcb946115ac2319fae8bee09b4188cc0b.tar.gz
Hyprland-d5e404fbcb946115ac2319fae8bee09b4188cc0b.zip
add --notify
-rw-r--r--hyprpm/src/core/PluginManager.cpp12
-rw-r--r--hyprpm/src/core/PluginManager.hpp43
-rw-r--r--hyprpm/src/main.cpp88
3 files changed, 107 insertions, 36 deletions
diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp
index 46b6db23..080a0bd1 100644
--- a/hyprpm/src/core/PluginManager.cpp
+++ b/hyprpm/src/core/PluginManager.cpp
@@ -535,17 +535,17 @@ bool CPluginManager::disablePlugin(const std::string& name) {
return ret;
}
-void CPluginManager::ensurePluginsLoadState() {
+ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
if (headersValid() != HEADERS_OK) {
std::cerr << "\n" << std::string{Colors::RED} + "✖" + Colors::RESET + " headers are not up-to-date, please run hyprpm update.";
- return;
+ return LOADSTATE_HEADERS_OUTDATED;
}
const auto HOME = getenv("HOME");
const auto HIS = getenv("HYPRLAND_INSTANCE_SIGNATURE");
if (!HOME || !HIS) {
std::cerr << "PluginManager: no $HOME or HIS\n";
- return;
+ return LOADSTATE_FAIL;
}
const auto HYPRPMPATH = DataState::getDataStatePath() + "/";
@@ -622,6 +622,8 @@ void CPluginManager::ensurePluginsLoadState() {
}
std::cout << Colors::GREEN << "✔" << Colors::RESET << " Plugin load state ensured\n";
+
+ return LOADSTATE_OK;
}
bool CPluginManager::loadUnloadPlugin(const std::string& path, bool load) {
@@ -644,4 +646,8 @@ void CPluginManager::listAllPlugins() {
<< Colors::RESET << "\n";
}
}
+}
+
+void CPluginManager::notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message) {
+ execAndGet("hyprctl notify " + std::to_string((int)icon) + " " + std::to_string(durationMs) + " " + std::to_string(color) + " " + message);
} \ No newline at end of file
diff --git a/hyprpm/src/core/PluginManager.hpp b/hyprpm/src/core/PluginManager.hpp
index 5c587c8a..a1c925d2 100644
--- a/hyprpm/src/core/PluginManager.hpp
+++ b/hyprpm/src/core/PluginManager.hpp
@@ -5,29 +5,50 @@
enum eHeadersErrors
{
- HEADERS_OK,
+ HEADERS_OK = 0,
HEADERS_NOT_HYPRLAND,
HEADERS_MISSING,
HEADERS_CORRUPTED,
HEADERS_MISMATCHED,
};
+enum eNotifyIcons
+{
+ ICON_WARNING = 0,
+ ICON_INFO,
+ ICON_HINT,
+ ICON_ERROR,
+ ICON_CONFUSED,
+ ICON_OK,
+ ICON_NONE
+};
+
+enum ePluginLoadStateReturn
+{
+ LOADSTATE_OK = 0,
+ LOADSTATE_FAIL,
+ LOADSTATE_PARTIAL_FAIL,
+ LOADSTATE_HEADERS_OUTDATED
+};
+
class CPluginManager {
public:
- bool addNewPluginRepo(const std::string& url);
- bool removePluginRepo(const std::string& urlOrName);
+ bool addNewPluginRepo(const std::string& url);
+ bool removePluginRepo(const std::string& urlOrName);
+
+ eHeadersErrors headersValid();
+ bool updateHeaders();
+ bool updatePlugins(bool forceUpdateAll);
- eHeadersErrors headersValid();
- bool updateHeaders();
- bool updatePlugins(bool forceUpdateAll);
+ void listAllPlugins();
- void listAllPlugins();
+ bool enablePlugin(const std::string& name);
+ bool disablePlugin(const std::string& name);
+ ePluginLoadStateReturn ensurePluginsLoadState();
- bool enablePlugin(const std::string& name);
- bool disablePlugin(const std::string& name);
- void ensurePluginsLoadState();
+ bool loadUnloadPlugin(const std::string& path, bool load);
- bool loadUnloadPlugin(const std::string& path, bool load);
+ void notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message);
};
inline std::unique_ptr<CPluginManager> g_pPluginManager; \ No newline at end of file
diff --git a/hyprpm/src/main.cpp b/hyprpm/src/main.cpp
index 02131df3..a6e31d87 100644
--- a/hyprpm/src/main.cpp
+++ b/hyprpm/src/main.cpp
@@ -26,61 +26,105 @@ int main(int argc, char** argv, char** envp) {
ARGS[i] = std::string{argv[i]};
}
- if (ARGS.size() < 2 || ARGS[1] == "--help" || ARGS[1] == "-h") {
+ if (ARGS.size() < 2) {
std::cout << HELP;
return 1;
}
+ std::vector<std::string> command;
+ bool notify = false;
+
+ for (int i = 1; i < argc; ++i) {
+ if (ARGS[i].starts_with("-")) {
+ if (ARGS[i] == "--help" || ARGS[i] == "-h") {
+ std::cout << HELP;
+ return 0;
+ } else if (ARGS[i] == "--notify" || ARGS[i] == "-n") {
+ notify = true;
+ } else {
+ std::cerr << "Unrecognized option " << ARGS[i];
+ return 1;
+ }
+ } else {
+ command.push_back(ARGS[i]);
+ }
+ }
+
g_pPluginManager = std::make_unique<CPluginManager>();
- if (ARGS[1] == "add") {
- if (ARGS.size() < 3) {
+ if (command[0] == "add") {
+ if (command.size() < 2) {
std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for add.\n";
return 1;
}
- return g_pPluginManager->addNewPluginRepo(ARGS[2]) ? 0 : 1;
- } else if (ARGS[1] == "remove") {
- if (ARGS.size() < 3) {
+ return g_pPluginManager->addNewPluginRepo(command[1]) ? 0 : 1;
+ } else if (command[0] == "remove") {
+ if (ARGS.size() < 2) {
std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for remove.\n";
return 1;
}
- return g_pPluginManager->removePluginRepo(ARGS[2]) ? 0 : 1;
- } else if (ARGS[1] == "update") {
+ return g_pPluginManager->removePluginRepo(command[1]) ? 0 : 1;
+ } else if (command[0] == "update") {
bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
bool headers = g_pPluginManager->updateHeaders();
if (headers) {
- g_pPluginManager->updatePlugins(!headersValid);
- g_pPluginManager->ensurePluginsLoadState();
- }
- } else if (ARGS[1] == "enable") {
- if (ARGS.size() < 3) {
+ bool ret1 = g_pPluginManager->updatePlugins(!headersValid);
+
+ if (!ret1)
+ return 1;
+
+ auto ret2 = g_pPluginManager->ensurePluginsLoadState();
+
+ if (ret2 != LOADSTATE_OK)
+ return 1;
+ } else if (notify)
+ g_pPluginManager->notify(ICON_ERROR, 0, 10000, "[hyprpm] Couldn't update headers");
+ } else if (command[0] == "enable") {
+ if (ARGS.size() < 2) {
std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for enable.\n";
return 1;
}
- if (!g_pPluginManager->enablePlugin(ARGS[2])) {
+ if (!g_pPluginManager->enablePlugin(command[1])) {
std::cerr << Colors::RED << "✖" << Colors::RESET << " Couldn't enable plugin (missing?)\n";
return 1;
}
- g_pPluginManager->ensurePluginsLoadState();
- } else if (ARGS[1] == "disable") {
- if (ARGS.size() < 3) {
+ auto ret = g_pPluginManager->ensurePluginsLoadState();
+ if (ret != LOADSTATE_OK)
+ return 1;
+ } else if (command[0] == "disable") {
+ if (command.size() < 2) {
std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for disable.\n";
return 1;
}
- if (!g_pPluginManager->disablePlugin(ARGS[2])) {
+ if (!g_pPluginManager->disablePlugin(command[1])) {
std::cerr << Colors::RED << "✖" << Colors::RESET << " Couldn't disable plugin (missing?)\n";
return 1;
}
- g_pPluginManager->ensurePluginsLoadState();
- } else if (ARGS[1] == "load") {
- g_pPluginManager->ensurePluginsLoadState();
- } else if (ARGS[1] == "list") {
+ auto ret = g_pPluginManager->ensurePluginsLoadState();
+ if (ret != LOADSTATE_OK)
+ return 1;
+ } else if (command[0] == "load") {
+ auto ret = g_pPluginManager->ensurePluginsLoadState();
+
+ if (ret != LOADSTATE_OK && notify) {
+ switch (ret) {
+ case LOADSTATE_FAIL:
+ case LOADSTATE_PARTIAL_FAIL: g_pPluginManager->notify(ICON_ERROR, 0, 10000, "[hyprpm] Failed to load plugins"); break;
+ case LOADSTATE_HEADERS_OUTDATED:
+ g_pPluginManager->notify(ICON_ERROR, 0, 10000, "[hyprpm] Failed to load plugins: Outdated headers. Please run hyprpm update manually.");
+ break;
+ default: break;
+ }
+ } else if (notify) {
+ g_pPluginManager->notify(ICON_OK, 0, 4000, "[hyprpm] Loaded plugins");
+ }
+ } else if (command[0] == "list") {
g_pPluginManager->listAllPlugins();
} else {
std::cout << HELP;