Persist Peek volume setting across sessions
Summary of the Pull Request
This PR implements volume persistence for the Peek utility, addressing issue #31810. When users adjust the volume slider for audio or video files in Peek, the volume level is now remembered and applied to subsequent files across sessions.
PR Checklist
- [x] Closes #31810
- [x] Communication: I've discussed this with core contributors and this is an approved change
- [x] Tests: I have verified these changes work locally
- [x] Localization: No new localizable strings added
- [x] Documentation: Feature behavior follows existing UI patterns
- [x] Accessibility: Uses existing MediaPlayerElement transport controls
Detailed Description of the Pull Request / Additional comments
Implementation Details
The implementation follows the same pattern used for ConfirmFileDelete - a setting that can be modified directly by Peek and synced back to the settings file.
Changes:
-
Settings Layer (
PeekProperties.cs):- Added
MediaVolumeas aDoublePropertywith default value of 1.0 (100%)
- Added
-
User Settings (
IUserSettings.cs,UserSettings.cs):- Added
MediaVolumeproperty with getter/setter - Implemented save-to-settings logic that persists volume changes immediately
- Added value clamping between 0.0 and 1.0
- Added
-
ViewModel (
MainWindowViewModel.cs):- Added
MediaVolumeproperty that delegates toIUserSettings - Updated constructor to accept
IUserSettingsvia DI
- Added
-
AudioControl (
AudioControl.xaml.cs):- Added
MediaVolumePropertyDependencyProperty - Added
VolumeChangedevent that fires when user changes volume via transport controls - Added volume tracking with
_isSettingVolumeflag to prevent recursive updates
- Added
-
FilePreview (
FilePreview.xaml,FilePreview.xaml.cs):- Added
MediaVolumePropertyDependencyProperty - Added
MediaVolumeChangedevent - Added
ApplyMediaVolume()method that sets volume on both video and audio players - Subscribes to volume changes from both
VideoPreview.MediaPlayerandAudioPreview
- Added
-
MainWindow (
MainWindow.xaml,MainWindow.xaml.cs):- Added
MediaVolumebinding toFilePreview - Added
MediaVolumeChangedevent handler that updates ViewModel
- Added
How it works
- When Peek loads, it reads the saved
MediaVolumefrom settings - The volume flows from
MainWindowViewModel→FilePreview→AudioControl/VideoPreview - When user adjusts volume via transport controls, the change bubbles up via events
MainWindowViewModelupdatesIUserSettings.MediaVolume, which saves to settings file- Next time Peek opens or a new file is previewed, the saved volume is applied
Validation Steps Performed
- Open Peek with an audio file, adjust volume to 50%
- Navigate to another audio file - volume should remain at 50%
- Close and reopen Peek - volume should still be at 50%
- Open a video file - volume should be at 50%
- Adjust video volume to 75%
- Open an audio file - volume should be at 75%
@microsoft-github-policy-service agree