PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

Persist Peek volume setting across sessions

Open ThanhNguyxn opened this issue 3 weeks ago • 1 comments

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:

  1. Settings Layer (PeekProperties.cs):

    • Added MediaVolume as a DoubleProperty with default value of 1.0 (100%)
  2. User Settings (IUserSettings.cs, UserSettings.cs):

    • Added MediaVolume property with getter/setter
    • Implemented save-to-settings logic that persists volume changes immediately
    • Added value clamping between 0.0 and 1.0
  3. ViewModel (MainWindowViewModel.cs):

    • Added MediaVolume property that delegates to IUserSettings
    • Updated constructor to accept IUserSettings via DI
  4. AudioControl (AudioControl.xaml.cs):

    • Added MediaVolumeProperty DependencyProperty
    • Added VolumeChanged event that fires when user changes volume via transport controls
    • Added volume tracking with _isSettingVolume flag to prevent recursive updates
  5. FilePreview (FilePreview.xaml, FilePreview.xaml.cs):

    • Added MediaVolumeProperty DependencyProperty
    • Added MediaVolumeChanged event
    • Added ApplyMediaVolume() method that sets volume on both video and audio players
    • Subscribes to volume changes from both VideoPreview.MediaPlayer and AudioPreview
  6. MainWindow (MainWindow.xaml, MainWindow.xaml.cs):

    • Added MediaVolume binding to FilePreview
    • Added MediaVolumeChanged event handler that updates ViewModel

How it works

  1. When Peek loads, it reads the saved MediaVolume from settings
  2. The volume flows from MainWindowViewModelFilePreviewAudioControl/VideoPreview
  3. When user adjusts volume via transport controls, the change bubbles up via events
  4. MainWindowViewModel updates IUserSettings.MediaVolume, which saves to settings file
  5. Next time Peek opens or a new file is previewed, the saved volume is applied

Validation Steps Performed

  1. Open Peek with an audio file, adjust volume to 50%
  2. Navigate to another audio file - volume should remain at 50%
  3. Close and reopen Peek - volume should still be at 50%
  4. Open a video file - volume should be at 50%
  5. Adjust video volume to 75%
  6. Open an audio file - volume should be at 75%

ThanhNguyxn avatar Dec 03 '25 08:12 ThanhNguyxn

@microsoft-github-policy-service agree

ThanhNguyxn avatar Dec 03 '25 08:12 ThanhNguyxn