From 5f8ebcae0739bdbe02e3a8da69d5b2f54fb588c3 Mon Sep 17 00:00:00 2001 From: Xander Frangos <33106561+xanderfrangos@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:06:20 -0500 Subject: [PATCH] Add timeouts to media status functions --- .../tt-windows-utils/windows_media_status.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/modules/tt-windows-utils/windows_media_status.cc b/src/modules/tt-windows-utils/windows_media_status.cc index 3c1907eb..1102731e 100644 --- a/src/modules/tt-windows-utils/windows_media_status.cc +++ b/src/modules/tt-windows-utils/windows_media_status.cc @@ -19,7 +19,12 @@ typedef Windows::Media::MediaPlaybackType MediaPlaybackType; Napi::String getPlaybackStatus(const Napi::CallbackInfo &info) { std::string statusStr = "closed"; - GSMTCSM manager = GSMTCSM::RequestAsync().get(); + auto session_async = GSMTCSM::RequestAsync(); + if (session_async.wait_for(std::chrono::seconds{ 1 }) != winrt::Windows::Foundation::AsyncStatus::Completed) { + return Napi::String::New(info.Env(), statusStr); + } + + GSMTCSM manager = session_async.get(); GlobalSystemMediaTransportControlsSession session = manager.GetCurrentSession(); @@ -51,7 +56,11 @@ Napi::String getPlaybackStatus(const Napi::CallbackInfo &info) { Napi::Object getPlaybackInfo(const Napi::CallbackInfo &info) { Napi::Object obj = Napi::Object::New(info.Env()); - GSMTCSM manager = GSMTCSM::RequestAsync().get(); + auto session_async = GSMTCSM::RequestAsync(); + if (session_async.wait_for(std::chrono::seconds{ 1 }) != winrt::Windows::Foundation::AsyncStatus::Completed) { + return obj; + } + GSMTCSM manager = session_async.get(); GlobalSystemMediaTransportControlsSession session = manager.GetCurrentSession();