From 40d52ad466b687d4e22b7657f9c485b4606f4819 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 27 Sep 2026 11:59:32 +0000 Subject: [PATCH] Load settings once per preview and skip unchanged breadcrumb writes Every Space press called MiqSettings.Load twice (Prepare on the UI thread, then View's background task), and each Load unconditionally rewrote "MIQ settings location.txt" in the plugin folder: two ini reads and two file writes per preview, one of each on QuickLook's UI thread. - View reuses the settings Prepare loaded (still re-read every preview, so ini edits apply on the next Space); it loads its own only if the host skipped Prepare. MiqSettings holds only frozen WPF resources, so handing it to the background task is safe. - WriteBreadcrumb writes only when the file is missing or its text differs (wiped by an upgrade, or the settings path moved). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01XqBwhnTRsqxk3SEvp9z4T9 --- QuickLook.Plugin.MIQ/MiqSettings.cs | 9 +++++++-- QuickLook.Plugin.MIQ/Plugin.cs | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/QuickLook.Plugin.MIQ/MiqSettings.cs b/QuickLook.Plugin.MIQ/MiqSettings.cs index bf3f373..ede6026 100644 --- a/QuickLook.Plugin.MIQ/MiqSettings.cs +++ b/QuickLook.Plugin.MIQ/MiqSettings.cs @@ -157,10 +157,15 @@ private static void WriteBreadcrumb(string? pluginDir, string settingsPath) return; try { - File.WriteAllText(Path.Combine(pluginDir!, "MIQ settings location.txt"), + var breadcrumb = Path.Combine(pluginDir!, "MIQ settings location.txt"); + var text = "MIQ preview settings are stored outside this folder so they\r\n" + "survive plugin updates. Edit this file:\r\n\r\n " + - settingsPath + "\r\n"); + settingsPath + "\r\n"; + // Load() runs on every preview; write only when missing or stale + // (wiped by an upgrade, or the settings path moved). + if (File.Exists(breadcrumb) && File.ReadAllText(breadcrumb) == text) return; + File.WriteAllText(breadcrumb, text); } catch { /* best-effort breadcrumb */ } } diff --git a/QuickLook.Plugin.MIQ/Plugin.cs b/QuickLook.Plugin.MIQ/Plugin.cs index 4f2af8f..c2604f4 100644 --- a/QuickLook.Plugin.MIQ/Plugin.cs +++ b/QuickLook.Plugin.MIQ/Plugin.cs @@ -26,6 +26,9 @@ public sealed class Plugin : IViewer private MiqVolume? _volume; // Cancelled in Cleanup() so background tasks don't touch a recycled viewer. private CancellationTokenSource? _cts; + // Loaded once per preview in Prepare() and reused by View(), so the ini is + // read (and its breadcrumb checked) once per Space, not twice. + private MiqSettings? _settings; // Above QuickLook's generic ArchiveViewer, which otherwise grabs ".gz". public int Priority => 100; @@ -59,7 +62,9 @@ public bool CanHandle(string path) public void Prepare(string path, ContextObject context) { + // Re-read every preview so ini edits apply on the next Space. var settings = MiqSettings.Load(); + _settings = settings; context.PreferredSize = new WpfSize(settings.PreviewWidth, settings.PreviewHeight); context.Theme = Themes.Dark; } @@ -76,12 +81,14 @@ public void View(string path, ContextObject context) context.ViewerContent = _control; var control = _control; + // Frozen WPF resources only, so safe to hand to the background task. + // Load here only if the host skipped Prepare(). + var loaded = _settings; Task.Run(() => { try { - // Re-read every preview so ini edits apply on the next Space. - var settings = MiqSettings.Load(); + var settings = loaded ?? MiqSettings.Load(); var options = settings.Options; var kind = MiqFileKindExtensions.FromPath(path);