core: guard against dbus logind interface not existing and check if on_(un)lock_cmd is empty (#151)

* core: guard against dbus logind interface not existing

* core: check if on_(un)lock_cmd is empty
This commit is contained in:
Maximilian Seidler 2025-05-19 21:03:43 +00:00 committed by GitHub
parent ecf2a3649d
commit 4f1c165d3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -313,7 +313,7 @@ void CHypridle::onLocked() {
m_isLocked = true;
static const auto LOCKCMD = g_pConfigManager->getValue<Hyprlang::STRING>("general:on_lock_cmd");
if (*LOCKCMD)
if (!std::string{*LOCKCMD}.empty())
spawn(*LOCKCMD);
if (m_inhibitSleepBehavior == SLEEP_INHIBIT_LOCK_NOTIFY)
@ -328,7 +328,7 @@ void CHypridle::onUnlocked() {
inhibitSleep();
static const auto UNLOCKCMD = g_pConfigManager->getValue<Hyprlang::STRING>("general:on_unlock_cmd");
if (*UNLOCKCMD)
if (!std::string{*UNLOCKCMD}.empty())
spawn(*UNLOCKCMD);
}
@ -576,6 +576,11 @@ void CHypridle::handleInhibitOnDbusSleep(bool toSleep) {
}
void CHypridle::inhibitSleep() {
if (!m_sDBUSState.login) {
Debug::log(WARN, "Can't inhibit sleep. Dbus logind interface is not available.");
return;
}
if (m_sDBUSState.sleepInhibitFd.isValid()) {
Debug::log(WARN, "Called inhibitSleep, but previous sleep inhibitor is still active!");
m_sDBUSState.sleepInhibitFd.reset();