Skip to content

Fix dark mode bug on second instance dialog and SVG preview default theme - #2003

Open
BerryUIKI wants to merge 1 commit into
QL-Win:masterfrom
BerryUIKI:fix/dark-mode-and-svg-theme
Open

BerryUIKI wants to merge 1 commit into
QL-Win:masterfrom
BerryUIKI:fix/dark-mode-and-svg-theme

Conversation

@BerryUIKI

@BerryUIKI BerryUIKI commented Sep 18, 2026

Copy link
Copy Markdown

PR Checklist

  • Functionality has been tested, no obvious bugs
  • Code style follows project conventions
  • Documentation/comments updated (if applicable)

Brief Description of Changes

  1. Fix duplicate instance reminder dialog theme:
    • In App.xaml.cs, EnsureFirstInstance previously called MessageBox.Show before ThemeManager.Apply(...) and MessageBoxPatcher.Initialize() were executed. This caused the duplicate instance notification dialog to stay in light mode even when Windows was in dark mode.
    • Added an idempotency check _isInitialized in MessageBoxPatcher.Initialize() and ensured ThemeManager.Apply and MessageBoxPatcher.Initialize are initialized before showing the message box in EnsureFirstInstance.
  2. Follow system theme for SVG and image previews:
    • In QuickLook.Plugin.ImageViewer, context.Theme hardcoded 1 (Themes.Dark) as fallback when reading LastTheme.
    • Updated Plugin.cs and Webview/WebHandler.cs to default to OSThemeHelper.AppsUseDarkTheme() ? Themes.Dark : Themes.Light.
    • Updated OPTIONS.md documentation for to reflect the default value

Summary by Sourcery

Fix theme initialization for duplicate-instance dialogs and default image previews to the operating system theme.

Bug Fixes:

  • Ensure duplicate-instance notification dialogs use the system light or dark theme.
  • Make SVG and image previews follow the system theme when no explicit preview theme is configured.

Enhancements:

  • Make message-box patch initialization safe to invoke multiple times.

Documentation:

  • Update ImageViewer options documentation to describe system-theme behavior for the default preview theme.

@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes dark-mode handling for duplicate-instance dialogs by applying the theme and MessageBox patches before the dialog is shown, with idempotent patch initialization. It also changes ImageViewer SVG/image previews to follow the system theme when LastTheme is unset or None, and aligns the configuration documentation with that behavior.

Sequence diagram for themed duplicate-instance dialog

sequenceDiagram
    participant App as QuickLookApp
    participant ThemeManager
    participant OSThemeHelper
    participant MessageBoxPatcher
    participant MessageBox

    App->>App: EnsureFirstInstance(args)
    App->>ThemeManager: Apply(OSThemeHelper.AppsUseDarkTheme())
    App->>MessageBoxPatcher: Initialize()
    alt patcher already initialized
        MessageBoxPatcher-->>App: return
    else first initialization
        MessageBoxPatcher-->>App: apply Harmony patches
    end
    App->>MessageBox: Show(duplicate instance notification)
    MessageBox-->>App: OK
Loading

Flow diagram for system-based ImageViewer preview theme

flowchart TD
    A[Prepare or TryPrepare preview] --> B[Read LastTheme]
    B --> C{LastTheme is None or unset?}
    C -->|Yes| D["OSThemeHelper.AppsUseDarkTheme()"]
    C -->|No| E[Use configured LastTheme]
    D --> F[Set context.Theme to Dark or Light]
    E --> F
Loading

File-Level Changes

Change Details Files
Initializes application theming and MessageBox patching before any duplicate-instance notification is displayed, while making patch setup idempotent.
  • Centralizes theme and patcher initialization in a reusable startup helper.
  • Invokes the helper from the second-instance path before showing the dialog.
  • Guards Harmony patch registration against repeated initialization.
QuickLook/App.xaml.cs
QuickLook/Helpers/MessageBoxPatcher.cs
Makes image and SVG preview themes follow the operating-system theme when no explicit preview theme is configured.
  • Uses the current system dark/light preference as the LastTheme fallback.
  • Resolves the None setting to the current system theme in both preview preparation paths.
  • Updates LastTheme documentation to describe the system-following default.
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs
QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Webview/WebHandler.cs
OPTIONS.md

Possibly linked issues

  • #SVG preview window is always dark: PR changes ImageViewer defaults and None handling to follow system light/dark theme, directly fixing dark SVG previews.
  • #Fix Dark Mode Bug: The PR initializes theming before the duplicate-instance message box, directly fixing the reported light-mode dialog bug.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant