aboutsummaryrefslogtreecommitdiffhomepage
path: root/hyprpm/src
diff options
context:
space:
mode:
Diffstat (limited to 'hyprpm/src')
-rw-r--r--hyprpm/src/core/PluginManager.cpp68
-rw-r--r--hyprpm/src/core/PluginManager.hpp5
-rw-r--r--hyprpm/src/main.cpp9
3 files changed, 62 insertions, 20 deletions
diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp
index db3893b5..48b108c8 100644
--- a/hyprpm/src/core/PluginManager.cpp
+++ b/hyprpm/src/core/PluginManager.cpp
@@ -50,17 +50,26 @@ static std::string getTempRoot() {
return STR;
}
-SHyprlandVersion CPluginManager::getHyprlandVersion() {
- static SHyprlandVersion ver;
- static bool once = false;
+SHyprlandVersion CPluginManager::getHyprlandVersion(bool running) {
+ static bool onceRunning = false;
+ static bool onceInstalled = false;
+ static SHyprlandVersion verRunning;
+ static SHyprlandVersion verInstalled;
- if (once)
- return ver;
+ if (onceRunning && running)
+ return verRunning;
- once = true;
- const auto HLVERCALL = execAndGet("hyprctl version");
+ if (onceInstalled && !running)
+ return verInstalled;
+
+ if (running)
+ onceRunning = true;
+ else
+ onceInstalled = true;
+
+ const auto HLVERCALL = running ? execAndGet("hyprctl version") : execAndGet("Hyprland --version");
if (m_bVerbose)
- std::println("{}", verboseString("version returned: {}", HLVERCALL));
+ std::println("{}", verboseString("{} version returned: {}", running ? "running" : "installed", HLVERCALL));
if (!HLVERCALL.contains("Tag:")) {
std::println(stderr, "\n{}", failureString("You don't seem to be running Hyprland."));
@@ -91,7 +100,13 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() {
if (m_bVerbose)
std::println("{}", verboseString("parsed commit {} at branch {} on {}, commits {}", hlcommit, hlbranch, hldate, commits));
- ver = SHyprlandVersion{hlbranch, hlcommit, hldate, commits};
+ auto ver = SHyprlandVersion{hlbranch, hlcommit, hldate, commits};
+
+ if (running)
+ verRunning = ver;
+ else
+ verInstalled = ver;
+
return ver;
}
@@ -356,7 +371,7 @@ bool CPluginManager::removePluginRepo(const std::string& urlOrName) {
}
eHeadersErrors CPluginManager::headersValid() {
- const auto HLVER = getHyprlandVersion();
+ const auto HLVER = getHyprlandVersion(false);
if (!std::filesystem::exists(DataState::getHeadersPath() + "/share/pkgconfig/hyprland.pc"))
return HEADERS_MISSING;
@@ -418,7 +433,7 @@ bool CPluginManager::updateHeaders(bool force) {
DataState::ensureStateStoreExists();
- const auto HLVER = getHyprlandVersion();
+ const auto HLVER = getHyprlandVersion(false);
if (!hasDeps()) {
std::println("\n{}", failureString("Could not update. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio, pkg-config"));
@@ -580,7 +595,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
return true;
}
- const auto HLVER = getHyprlandVersion();
+ const auto HLVER = getHyprlandVersion(false);
CProgressBar progress;
progress.m_iMaxSteps = REPOS.size() * 2 + 2;
@@ -829,12 +844,20 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
return "";
};
+ // if any of the loadUnloadPlugin calls return false, this is true
+ // bcs that means the header version doesn't match the running version
+ // (and Hyprland needs to restart)
+ bool hyprlandVersionMismatch = false;
+
// unload disabled plugins
for (auto const& p : loadedPlugins) {
if (!enabled(p)) {
// unload
- loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false);
- std::println("{}", successString("Unloaded {}", p));
+ if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false)) {
+ std::println("{}", infoString("{} will be unloaded after restarting Hyprland", p));
+ hyprlandVersionMismatch = true;
+ } else
+ std::println("{}", successString("Unloaded {}", p));
}
}
@@ -847,17 +870,28 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
if (std::find_if(loadedPlugins.begin(), loadedPlugins.end(), [&](const auto& other) { return other == p.name; }) != loadedPlugins.end())
continue;
- loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true);
- std::println("{}", successString("Loaded {}", p.name));
+ if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true)) {
+ std::println("{}", infoString("{} will be loaded after restarting Hyprland", p.name));
+ hyprlandVersionMismatch = true;
+ } else
+ std::println("{}", successString("Loaded {}", p.name));
}
}
std::println("{}", successString("Plugin load state ensured"));
- return LOADSTATE_OK;
+ return hyprlandVersionMismatch ? LOADSTATE_HYPRLAND_UPDATED : LOADSTATE_OK;
}
bool CPluginManager::loadUnloadPlugin(const std::string& path, bool load) {
+ auto state = DataState::getGlobalState();
+ auto HLVER = getHyprlandVersion(true);
+
+ if (state.headersHashCompiled != HLVER.hash) {
+ std::println("{}", infoString("Running Hyprland version differs from plugin state, please restart Hyprland."));
+ return false;
+ }
+
if (load)
execAndGet("hyprctl plugin load " + path);
else
diff --git a/hyprpm/src/core/PluginManager.hpp b/hyprpm/src/core/PluginManager.hpp
index d4603084..7502cc04 100644
--- a/hyprpm/src/core/PluginManager.hpp
+++ b/hyprpm/src/core/PluginManager.hpp
@@ -27,7 +27,8 @@ enum ePluginLoadStateReturn {
LOADSTATE_OK = 0,
LOADSTATE_FAIL,
LOADSTATE_PARTIAL_FAIL,
- LOADSTATE_HEADERS_OUTDATED
+ LOADSTATE_HEADERS_OUTDATED,
+ LOADSTATE_HYPRLAND_UPDATED
};
struct SHyprlandVersion {
@@ -53,7 +54,7 @@ class CPluginManager {
ePluginLoadStateReturn ensurePluginsLoadState();
bool loadUnloadPlugin(const std::string& path, bool load);
- SHyprlandVersion getHyprlandVersion();
+ SHyprlandVersion getHyprlandVersion(bool running = true);
void notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message);
diff --git a/hyprpm/src/main.cpp b/hyprpm/src/main.cpp
index 55fb57e2..8e67af99 100644
--- a/hyprpm/src/main.cpp
+++ b/hyprpm/src/main.cpp
@@ -103,7 +103,7 @@ int main(int argc, char** argv, char** envp) {
bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
bool headers = g_pPluginManager->updateHeaders(force);
if (headers) {
- const auto HLVER = g_pPluginManager->getHyprlandVersion();
+ const auto HLVER = g_pPluginManager->getHyprlandVersion(false);
auto GLOBALSTATE = DataState::getGlobalState();
const auto COMPILEDOUTDATED = HLVER.hash != GLOBALSTATE.headersHashCompiled;
@@ -114,6 +114,9 @@ int main(int argc, char** argv, char** envp) {
auto ret2 = g_pPluginManager->ensurePluginsLoadState();
+ if (ret2 == LOADSTATE_HYPRLAND_UPDATED)
+ g_pPluginManager->notify(ICON_INFO, 0, 10000, "[hyprpm] Updated plugins, but Hyprland was updated. Please restart Hyprland.");
+
if (ret2 != LOADSTATE_OK)
return 1;
} else if (notify)
@@ -130,6 +133,10 @@ int main(int argc, char** argv, char** envp) {
}
auto ret = g_pPluginManager->ensurePluginsLoadState();
+
+ if (ret == LOADSTATE_HYPRLAND_UPDATED)
+ g_pPluginManager->notify(ICON_INFO, 0, 10000, "[hyprpm] Enabled plugin, but Hyprland was updated. Please restart Hyprland.");
+
if (ret != LOADSTATE_OK)
return 1;
} else if (command[0] == "disable") {