Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hyprpm: target installed instead of running version #8634

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 46 additions & 15 deletions hyprpm/src/core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = true) {
vaxerski marked this conversation as resolved.
Show resolved Hide resolved
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."));
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -829,11 +844,17 @@ 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);
if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false))
RoootTheFox marked this conversation as resolved.
Show resolved Hide resolved
hyprlandVersionMismatch = true;
std::println("{}", successString("Unloaded {}", p));
}
}
Expand All @@ -847,17 +868,27 @@ 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);
if (!loadUnloadPlugin(HYPRPMPATH + repoForName(p.name) + "/" + p.filename, true))
hyprlandVersionMismatch = true;
RoootTheFox marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
5 changes: 3 additions & 2 deletions hyprpm/src/core/PluginManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -53,7 +54,7 @@ class CPluginManager {
ePluginLoadStateReturn ensurePluginsLoadState();

bool loadUnloadPlugin(const std::string& path, bool load);
SHyprlandVersion getHyprlandVersion();
SHyprlandVersion getHyprlandVersion(bool running);

void notify(const eNotifyIcons icon, uint32_t color, int durationMs, const std::string& message);

Expand Down
13 changes: 10 additions & 3 deletions hyprpm/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -114,7 +114,10 @@ int main(int argc, char** argv, char** envp) {

auto ret2 = g_pPluginManager->ensurePluginsLoadState();

if (ret2 != LOADSTATE_OK)
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 || ret2 == LOADSTATE_HYPRLAND_UPDATED)
RoootTheFox marked this conversation as resolved.
Show resolved Hide resolved
return 1;
} else if (notify)
g_pPluginManager->notify(ICON_ERROR, 0, 10000, "[hyprpm] Couldn't update headers");
Expand All @@ -130,7 +133,11 @@ int main(int argc, char** argv, char** envp) {
}

auto ret = g_pPluginManager->ensurePluginsLoadState();
if (ret != LOADSTATE_OK)

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 || ret == LOADSTATE_HYPRLAND_UPDATED)
RoootTheFox marked this conversation as resolved.
Show resolved Hide resolved
return 1;
} else if (command[0] == "disable") {
if (command.size() < 2) {
Expand Down
Loading