From 357ee55209fba2e0513b8b08053ae4fc22318ce3 Mon Sep 17 00:00:00 2001 From: lx-s Date: Wed, 8 Jul 2026 14:45:30 +0200 Subject: [PATCH] use new media playback controller. --- WinMute/MuteControl.cpp | 29 +++++------------------------ WinMute/MuteControl.h | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/WinMute/MuteControl.cpp b/WinMute/MuteControl.cpp index bf729ff..3141e69 100644 --- a/WinMute/MuteControl.cpp +++ b/WinMute/MuteControl.cpp @@ -45,21 +45,6 @@ static constexpr UINT_PTR BLUETOOTH_UNMUTE_TIMER_ID = 190502; static const wchar_t *MUTECONTROL_CLASS_NAME = L"WinMuteMuteControl"; -enum MuteType -{ - // With restore - MuteTypeWorkstationLock = 0, - MuteTypeRemoteSession, - MuteTypeDisplayStandby, - MuteTypeBluetoothDisconnect, - - // Without restore - MuteTypeLogout, - MuteTypeSuspend, - MuteTypeShutdown, - MuteTypeCount // Meta -}; - void CALLBACK DelayedMuteTimerProc(HWND hWnd, UINT, UINT_PTR, DWORD) { MuteControl *muteCtrl = reinterpret_cast(GetWindowLongPtrW(hWnd, GWLP_USERDATA)); @@ -304,10 +289,10 @@ void MuteControl::CompleteVolumeRestore() { bluetoothUnmuteTimerId_ = 0; winAudio_->RestoreMuteStatus(); - if (mediaWasPlaying_ && mediaConfig_.tryResume) + if (mediaConfig_.tryResume) { - MediaPlaybackController::TryPlayCurrentSession(); - mediaWasPlaying_ = false; + // Only resumes if a previous RequestPause actually paused the session. + mediaController_.RequestResume(); } } @@ -415,15 +400,11 @@ void MuteControl::MuteNow() winAudio_->SetMute(true); if (mediaConfig_.tryPause) { - bool did_pause = false; - if (MediaPlaybackController::TryPauseCurrentSession(did_pause)) - { - mediaWasPlaying_ = did_pause; - } + mediaController_.RequestPause(); } } -void MuteControl::NotifyRestoreCondition(int type, bool active, bool withDelay) +void MuteControl::NotifyRestoreCondition(MuteType type, bool active, bool withDelay) { if (active) { diff --git a/WinMute/MuteControl.h b/WinMute/MuteControl.h index 3127eb9..bb70353 100644 --- a/WinMute/MuteControl.h +++ b/WinMute/MuteControl.h @@ -97,6 +97,20 @@ public: void MuteDelayed(int magic); void CompleteVolumeRestore(); private: + enum MuteType + { + // With restore + MuteTypeWorkstationLock = 0, + MuteTypeRemoteSession, + MuteTypeDisplayStandby, + MuteTypeBluetoothDisconnect, + + // Without restore + MuteTypeLogout, + MuteTypeSuspend, + MuteTypeShutdown, + MuteTypeCount // Meta + }; struct MuteConfig { bool shouldMute; bool active; @@ -108,11 +122,11 @@ private: std::vector muteConfig_; bool restoreVolume_ = false; bool notificationsEnabled_ = false; - bool mediaWasPlaying_ = false; int muteDelaySeconds_ = 0; UINT_PTR delayedMuteTimerId_ = 0; UINT_PTR bluetoothUnmuteTimerId_ = 0; std::unique_ptr winAudio_; + MediaPlaybackController mediaController_; HWND hMuteCtrlWnd_ = nullptr; // Since a power message is sent right after registering @@ -121,7 +135,7 @@ private: const TrayIcon* trayIcon_ = nullptr; - void NotifyRestoreCondition(int type, bool active, bool withDelay = false); + void NotifyRestoreCondition(MuteType type, bool active, bool withDelay = false); void SaveMuteStatus(); void RestoreVolume(bool withDelay = false); void ShowNotification(const std::wstring& title, const std::wstring& text); -- 2.43.0