mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
Merge branch 'gui-cs:v2_develop' into v2_develop
This commit is contained in:
@@ -11,6 +11,8 @@ internal sealed class MainLoopSyncContext : SynchronizationContext
|
||||
public override void Post (SendOrPostCallback d, object state)
|
||||
{
|
||||
// Queue the task
|
||||
if (ApplicationImpl.Instance.IsLegacy)
|
||||
{
|
||||
Application.MainLoop?.TimedEvents.Add (TimeSpan.Zero,
|
||||
() =>
|
||||
{
|
||||
@@ -21,6 +23,11 @@ internal sealed class MainLoopSyncContext : SynchronizationContext
|
||||
);
|
||||
Application.MainLoop?.Wakeup ();
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplicationImpl.Instance.Invoke (() => { d (state); });
|
||||
}
|
||||
}
|
||||
|
||||
//_mainLoop.Driver.Wakeup ();
|
||||
public override void Send (SendOrPostCallback d, object state)
|
||||
|
||||
@@ -245,12 +245,13 @@ public partial class View : IDisposable, ISupportInitializeNotification
|
||||
}
|
||||
}
|
||||
|
||||
if (ApplicationImpl.Instance.IsLegacy)
|
||||
{
|
||||
// TODO: Figure out how to move this out of here and just depend on LayoutNeeded in Mainloop
|
||||
// Force a layout each time a View is initialized
|
||||
// See: https://github.com/gui-cs/Terminal.Gui/issues/3951
|
||||
// See: https://github.com/gui-cs/Terminal.Gui/issues/4204
|
||||
Layout (); // the EventLog in AllViewsTester fails to layout correctly if this is not here (convoluted Dim.Fill(Func)).
|
||||
}
|
||||
|
||||
// Complex layout scenarios (e.g. DimAuto and PosAlign) may require multiple layouts to be performed.
|
||||
// Thus, we call SetNeedsLayout() to ensure that the layout is performed at least once.
|
||||
SetNeedsLayout ();
|
||||
|
||||
Initialized?.Invoke (this, EventArgs.Empty);
|
||||
|
||||
@@ -21,23 +21,40 @@ public class SyncrhonizationContextTests
|
||||
Application.Shutdown ();
|
||||
}
|
||||
|
||||
private object _lockPost = new ();
|
||||
|
||||
[Theory]
|
||||
[InlineData (typeof (FakeDriver))]
|
||||
[InlineData (typeof (NetDriver))]
|
||||
[InlineData (typeof (WindowsDriver))]
|
||||
[InlineData (typeof (CursesDriver))]
|
||||
public void SynchronizationContext_Post (Type driverType)
|
||||
[InlineData (typeof (ConsoleDriverFacade<WindowsConsole.InputRecord>), "v2win")]
|
||||
[InlineData (typeof (ConsoleDriverFacade<ConsoleKeyInfo>), "v2net")]
|
||||
public void SynchronizationContext_Post (Type driverType, string driverName = null)
|
||||
{
|
||||
lock (_lockPost)
|
||||
{
|
||||
ConsoleDriver.RunningUnitTests = true;
|
||||
|
||||
if (driverType.Name.Contains ("ConsoleDriverFacade"))
|
||||
{
|
||||
Application.Init (driverName: driverName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Init (driverName: driverType.Name);
|
||||
}
|
||||
|
||||
SynchronizationContext context = SynchronizationContext.Current;
|
||||
|
||||
var success = false;
|
||||
|
||||
Task.Run (
|
||||
() =>
|
||||
Task.Run (() =>
|
||||
{
|
||||
while (Application.Top is null || Application.Top is { Running: false })
|
||||
{
|
||||
Thread.Sleep (500);
|
||||
}
|
||||
|
||||
// non blocking
|
||||
context.Post (
|
||||
@@ -50,15 +67,28 @@ public class SyncrhonizationContextTests
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
if (Application.Top is { Running: true })
|
||||
{
|
||||
Assert.False (success);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// blocks here until the RequestStop is processed at the end of the test
|
||||
Application.Run ().Dispose ();
|
||||
Assert.True (success);
|
||||
|
||||
if (ApplicationImpl.Instance is ApplicationV2)
|
||||
{
|
||||
ApplicationImpl.Instance.Shutdown ();
|
||||
}
|
||||
else
|
||||
{
|
||||
Application.Shutdown ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[AutoInitShutdown]
|
||||
|
||||
Reference in New Issue
Block a user