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));
{
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();
}
}
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)
{
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;
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
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);