mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-23 17:09:49 +01:00
hyprpm: target installed instead of running version (#8634)
--------- Signed-off-by: rooot <hey@rooot.gay>
This commit is contained in:
parent
e892310953
commit
33f271c29a
3 changed files with 62 additions and 20 deletions
|
@ -50,17 +50,26 @@ static std::string getTempRoot() {
|
||||||
return STR;
|
return STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHyprlandVersion CPluginManager::getHyprlandVersion() {
|
SHyprlandVersion CPluginManager::getHyprlandVersion(bool running) {
|
||||||
static SHyprlandVersion ver;
|
static bool onceRunning = false;
|
||||||
static bool once = false;
|
static bool onceInstalled = false;
|
||||||
|
static SHyprlandVersion verRunning;
|
||||||
|
static SHyprlandVersion verInstalled;
|
||||||
|
|
||||||
if (once)
|
if (onceRunning && running)
|
||||||
return ver;
|
return verRunning;
|
||||||
|
|
||||||
once = true;
|
if (onceInstalled && !running)
|
||||||
const auto HLVERCALL = execAndGet("hyprctl version");
|
return verInstalled;
|
||||||
|
|
||||||
|
if (running)
|
||||||
|
onceRunning = true;
|
||||||
|
else
|
||||||
|
onceInstalled = true;
|
||||||
|
|
||||||
|
const auto HLVERCALL = running ? execAndGet("hyprctl version") : execAndGet("Hyprland --version");
|
||||||
if (m_bVerbose)
|
if (m_bVerbose)
|
||||||
std::println("{}", verboseString("version returned: {}", HLVERCALL));
|
std::println("{}", verboseString("{} version returned: {}", running ? "running" : "installed", HLVERCALL));
|
||||||
|
|
||||||
if (!HLVERCALL.contains("Tag:")) {
|
if (!HLVERCALL.contains("Tag:")) {
|
||||||
std::println(stderr, "\n{}", failureString("You don't seem to be running Hyprland."));
|
std::println(stderr, "\n{}", failureString("You don't seem to be running Hyprland."));
|
||||||
|
@ -91,7 +100,13 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() {
|
||||||
if (m_bVerbose)
|
if (m_bVerbose)
|
||||||
std::println("{}", verboseString("parsed commit {} at branch {} on {}, commits {}", hlcommit, hlbranch, hldate, commits));
|
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;
|
return ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +371,7 @@ bool CPluginManager::removePluginRepo(const std::string& urlOrName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
eHeadersErrors CPluginManager::headersValid() {
|
eHeadersErrors CPluginManager::headersValid() {
|
||||||
const auto HLVER = getHyprlandVersion();
|
const auto HLVER = getHyprlandVersion(false);
|
||||||
|
|
||||||
if (!std::filesystem::exists(DataState::getHeadersPath() + "/share/pkgconfig/hyprland.pc"))
|
if (!std::filesystem::exists(DataState::getHeadersPath() + "/share/pkgconfig/hyprland.pc"))
|
||||||
return HEADERS_MISSING;
|
return HEADERS_MISSING;
|
||||||
|
@ -418,7 +433,7 @@ bool CPluginManager::updateHeaders(bool force) {
|
||||||
|
|
||||||
DataState::ensureStateStoreExists();
|
DataState::ensureStateStoreExists();
|
||||||
|
|
||||||
const auto HLVER = getHyprlandVersion();
|
const auto HLVER = getHyprlandVersion(false);
|
||||||
|
|
||||||
if (!hasDeps()) {
|
if (!hasDeps()) {
|
||||||
std::println("\n{}", failureString("Could not update. Dependencies not satisfied. Hyprpm requires: cmake, meson, cpio, pkg-config"));
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto HLVER = getHyprlandVersion();
|
const auto HLVER = getHyprlandVersion(false);
|
||||||
|
|
||||||
CProgressBar progress;
|
CProgressBar progress;
|
||||||
progress.m_iMaxSteps = REPOS.size() * 2 + 2;
|
progress.m_iMaxSteps = REPOS.size() * 2 + 2;
|
||||||
|
@ -829,12 +844,20 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
|
||||||
return "";
|
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
|
// unload disabled plugins
|
||||||
for (auto const& p : loadedPlugins) {
|
for (auto const& p : loadedPlugins) {
|
||||||
if (!enabled(p)) {
|
if (!enabled(p)) {
|
||||||
// unload
|
// unload
|
||||||
loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false);
|
if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false)) {
|
||||||
std::println("{}", successString("Unloaded {}", p));
|
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())
|
if (std::find_if(loadedPlugins.begin(), loadedPlugins.end(), [&](const auto& other) { return other == p.name; }) != loadedPlugins.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true);
|
if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true)) {
|
||||||
std::println("{}", successString("Loaded {}", p.name));
|
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"));
|
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) {
|
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)
|
if (load)
|
||||||
execAndGet("hyprctl plugin load " + path);
|
execAndGet("hyprctl plugin load " + path);
|
||||||
else
|
else
|
||||||
|
|
|
@ -27,7 +27,8 @@ enum ePluginLoadStateReturn {
|
||||||
LOADSTATE_OK = 0,
|
LOADSTATE_OK = 0,
|
||||||
LOADSTATE_FAIL,
|
LOADSTATE_FAIL,
|
||||||
LOADSTATE_PARTIAL_FAIL,
|
LOADSTATE_PARTIAL_FAIL,
|
||||||
LOADSTATE_HEADERS_OUTDATED
|
LOADSTATE_HEADERS_OUTDATED,
|
||||||
|
LOADSTATE_HYPRLAND_UPDATED
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SHyprlandVersion {
|
struct SHyprlandVersion {
|
||||||
|
@ -53,7 +54,7 @@ class CPluginManager {
|
||||||
ePluginLoadStateReturn ensurePluginsLoadState();
|
ePluginLoadStateReturn ensurePluginsLoadState();
|
||||||
|
|
||||||
bool loadUnloadPlugin(const std::string& path, bool load);
|
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);
|
void notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message);
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ int main(int argc, char** argv, char** envp) {
|
||||||
bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
|
bool headersValid = g_pPluginManager->headersValid() == HEADERS_OK;
|
||||||
bool headers = g_pPluginManager->updateHeaders(force);
|
bool headers = g_pPluginManager->updateHeaders(force);
|
||||||
if (headers) {
|
if (headers) {
|
||||||
const auto HLVER = g_pPluginManager->getHyprlandVersion();
|
const auto HLVER = g_pPluginManager->getHyprlandVersion(false);
|
||||||
auto GLOBALSTATE = DataState::getGlobalState();
|
auto GLOBALSTATE = DataState::getGlobalState();
|
||||||
const auto COMPILEDOUTDATED = HLVER.hash != GLOBALSTATE.headersHashCompiled;
|
const auto COMPILEDOUTDATED = HLVER.hash != GLOBALSTATE.headersHashCompiled;
|
||||||
|
|
||||||
|
@ -114,6 +114,9 @@ int main(int argc, char** argv, char** envp) {
|
||||||
|
|
||||||
auto ret2 = g_pPluginManager->ensurePluginsLoadState();
|
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)
|
if (ret2 != LOADSTATE_OK)
|
||||||
return 1;
|
return 1;
|
||||||
} else if (notify)
|
} else if (notify)
|
||||||
|
@ -130,6 +133,10 @@ int main(int argc, char** argv, char** envp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ret = g_pPluginManager->ensurePluginsLoadState();
|
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)
|
if (ret != LOADSTATE_OK)
|
||||||
return 1;
|
return 1;
|
||||||
} else if (command[0] == "disable") {
|
} else if (command[0] == "disable") {
|
||||||
|
|
Loading…
Reference in a new issue