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",