]> repos.lx-s.de Git - winmute.git/commitdiff
use new media playback controller.
authorlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 12:45:30 +0000 (14:45 +0200)
committerlx-s <lx-s@users.noreply.github.com>
Wed, 8 Jul 2026 12:45:30 +0000 (14:45 +0200)
WinMute/MuteControl.cpp
WinMute/MuteControl.h

index bf729ffdec1e747537557d4bc129621758644861..3141e6982eff1a593cc643774baf0ae8a0eff599 100644 (file)
@@ -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<MuteControl *>(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)
    {
index 3127eb9da79474d29eaff52ba8f281dea0867503..bb70353a4e501641d617424854821c8dad7706b7 100644 (file)
@@ -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> 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> 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);