From 335daba4c8a20c8da813158d765b1f4bf31a4a27 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 13:57:52 +0900 Subject: [PATCH] =?UTF-8?q?=E8=B5=B0=E6=9F=BB=E3=81=A7=E3=82=B9=E3=83=AC?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=81=AE=E3=83=A2=E3=83=BC=E3=83=80=E3=83=AB?= =?UTF-8?q?=E7=8A=B6=E6=85=8B=E3=82=82=E8=A6=8B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge.Tests/ExportWindowWatcherTests.cs | 48 ++++++++++++++++++++ ProxyForge/Export/ExportWindowWatcher.cs | 3 +- tools/mutations.json | 6 +++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/ProxyForge.Tests/ExportWindowWatcherTests.cs b/ProxyForge.Tests/ExportWindowWatcherTests.cs index ce45bf0..3831e82 100644 --- a/ProxyForge.Tests/ExportWindowWatcherTests.cs +++ b/ProxyForge.Tests/ExportWindowWatcherTests.cs @@ -1,3 +1,4 @@ +using System.Runtime.InteropServices; using System.Windows; using System.Windows.Interop; using System.Windows.Threading; @@ -333,6 +334,49 @@ public sealed class ExportWindowWatcherTests Assert.Equal(ExportPhase.Idle, after); } + [Fact] + public void TheScanTreatsAModalDialogWithoutAnOwnerAsPreparing() + { + var (during, after) = Watch(() => + { + var dialog = CreateWindow("Dialog"); + ExportPhase? during = null; + Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => + { + during = ExportWindowWatcher.Scan(); + dialog.Close(); + }), DispatcherPriority.ContextIdle); + dialog.ShowDialog(); + Pump(); + return (during, ExportWindowWatcher.Scan()); + }); + + Assert.Equal(ExportPhase.Preparing, during); + Assert.Equal(ExportPhase.Idle, after); + } + + [Fact] + public void TheScanTreatsADisabledVisibleWindowAsPreparing() + { + var (disabled, enabled) = Watch(() => + { + var window = CreateWindow("Owner"); + window.Show(); + Pump(); + var handle = new WindowInteropHelper(window).Handle; + EnableWindow(handle, false); + var disabled = ExportWindowWatcher.Scan(); + EnableWindow(handle, true); + var enabled = ExportWindowWatcher.Scan(); + window.Close(); + Pump(); + return (disabled, enabled); + }); + + Assert.Equal(ExportPhase.Preparing, disabled); + Assert.Equal(ExportPhase.Idle, enabled); + } + [Fact] public void ThePhaseIsResolvedOnTheWatchingThread() { @@ -377,4 +421,8 @@ public sealed class ExportWindowWatcherTests Assert.Equal(ExportPhase.Exporting, phase); } + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool EnableWindow(nint window, [MarshalAs(UnmanagedType.Bool)] bool enable); } diff --git a/ProxyForge/Export/ExportWindowWatcher.cs b/ProxyForge/Export/ExportWindowWatcher.cs index 78a48b6..e5fc786 100644 --- a/ProxyForge/Export/ExportWindowWatcher.cs +++ b/ProxyForge/Export/ExportWindowWatcher.cs @@ -1,5 +1,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Windows.Interop; using System.Windows.Threading; using YukkuriMovieMaker.Commons; @@ -91,7 +92,7 @@ internal static unsafe partial class ExportWindowWatcher if (detector is null) return null; - scanned = ExportPhase.Idle; + scanned = ComponentDispatcher.IsThreadModal ? ExportPhase.Preparing : ExportPhase.Idle; EnumThreadWindows(threadId, &OnWindowEnumerated, 0); return scanned; } diff --git a/tools/mutations.json b/tools/mutations.json index bfac3ef..6b64003 100644 --- a/tools/mutations.json +++ b/tools/mutations.json @@ -281,6 +281,12 @@ "find": " if (!IsWindowEnabled(window))\r\n scanned = ExportPhase.Preparing;", "replace": "" }, + { + "name": "走査でスレッドのモーダル状態を見ない", + "file": "ProxyForge/Export/ExportWindowWatcher.cs", + "find": "scanned = ComponentDispatcher.IsThreadModal ? ExportPhase.Preparing : ExportPhase.Idle;", + "replace": "scanned = ExportPhase.Idle;" + }, { "name": "走査で隠れたウィンドウも数える", "file": "ProxyForge/Export/ExportWindowWatcher.cs",