Skip to content

Commit

Permalink
Add timeouts to media status functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xanderfrangos committed Dec 3, 2024
1 parent 5c7bf3c commit 5f8ebca
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/modules/tt-windows-utils/windows_media_status.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 5f8ebca

Please sign in to comment.