From a75f88ed1a01e8f12926230e57778ff61b0a62bb Mon Sep 17 00:00:00 2001 From: wAABBsif Date: Wed, 21 Jan 2026 14:15:31 -0500 Subject: [PATCH] Run Linux music attenuation code on timer --- UnleashedRecomp/os/linux/media_linux.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/UnleashedRecomp/os/linux/media_linux.cpp b/UnleashedRecomp/os/linux/media_linux.cpp index 91347193..0274508c 100644 --- a/UnleashedRecomp/os/linux/media_linux.cpp +++ b/UnleashedRecomp/os/linux/media_linux.cpp @@ -2,6 +2,13 @@ #include #include +#include "app.h" + +#define MEDIA_CHECK_RATE 1 + +static float g_mediaCheckTimer; +static bool g_mediaLastResult; + static DBusConnection* CreateDBusConnection() { DBusError dbusError; @@ -170,6 +177,13 @@ static bool IsMediaPlayerPlaying(DBusConnection* connection, const std::string& bool os::media::IsExternalMediaPlaying() { + //Calling D-Bus functions too much seems cause D-Bus to stop working, so perhaps it should be run less often. + g_mediaCheckTimer -= App::s_deltaTime; + if (g_mediaCheckTimer > 0) + return g_mediaLastResult; + + g_mediaCheckTimer = MEDIA_CHECK_RATE; + const auto dbusConnection = CreateDBusConnection(); if (!dbusConnection) return false; @@ -187,5 +201,6 @@ bool os::media::IsExternalMediaPlaying() } DestroyDBusConnection(dbusConnection); + g_mediaLastResult = result; return result; } \ No newline at end of file