From fa111538aee1b19c6240e0726cf1bd23374bab1e Mon Sep 17 00:00:00 2001 From: leileizhang Date: Mon, 16 Jun 2025 13:39:56 +0800 Subject: [PATCH] Fix Peek always showing warning message by updating IsWarningMessageVisible logic (#40056) ## Summary of the Pull Request This PR fixes an issue where the warning message in Peek was always displayed, even when not applicable. **Root cause** When non-video files were triggered, the logic did not call `IsWarningMessageVisible(string? missingCodecName)` as expected. As a result, the default UI state caused the warning message to always appear. **Fix** Updated the method signature and call sites to: `public Visibility IsWarningMessageVisible(IPreviewer? previewer, PreviewState? state)` This ensures that the logic is consistently triggered across different preview handlers and has access to the necessary context to determine whether the warning message should be shown. ## PR Checklist - [ ] **Closes:** #xxx - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --- src/modules/peek/Peek.FilePreviewer/FilePreview.xaml | 2 +- src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml index 311fbd0227..e7f6db1652 100644 --- a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml +++ b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml @@ -65,7 +65,7 @@ HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{StaticResource TextFillColorSecondaryBrush}" - Visibility="{x:Bind IsWarningMessageVisible(VideoPreviewer.MissingCodecName), Mode=OneWay}"> + Visibility="{x:Bind IsWarningMessageVisible(VideoPreviewer, Previewer.State), Mode=OneWay}"> diff --git a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs index 59bdd9d2e5..7166de69a5 100644 --- a/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs +++ b/src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs @@ -150,9 +150,9 @@ namespace Peek.FilePreviewer return isValidPreview ? Visibility.Visible : Visibility.Collapsed; } - public Visibility IsWarningMessageVisible(string? missingCodecName) + public Visibility IsWarningMessageVisible(IPreviewer? previewer, PreviewState? state) { - var shouldShow = !string.IsNullOrEmpty(missingCodecName); + var shouldShow = previewer is IVideoPreviewer videoPreviewer && MatchPreviewState(state, PreviewState.Loaded) && !string.IsNullOrEmpty(videoPreviewer.MissingCodecName); return shouldShow ? Visibility.Visible : Visibility.Collapsed; }