Skip to content

Commit

Permalink
Prevent crashes when creating new workspaces with a YAML config (#1068)
Browse files Browse the repository at this point in the history
This PR fixes a critical crash which would occur when creating a workspace during runtime (after startup).

The issue was that a `TreeLayoutPlugin` event was not enqueued onto the WinUI dispatcher.
  • Loading branch information
dalyIsaac authored Nov 3, 2024
1 parent bd17c2c commit 86eace7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/Whim.TreeLayout.Tests/TreeLayoutPluginTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ ILayoutEngine layoutEngine
public void SetAddWindowDirection_DirectionNotSet(IContext ctx, IMonitor monitor, IWorkspace workspace)
{
// Given
NativeManagerUtils.SetupTryEnqueue(ctx);
ctx.Butler.Pantry.GetWorkspaceForMonitor(monitor).Returns(workspace);

TreeLayoutPlugin plugin = new(ctx);
Expand Down Expand Up @@ -236,6 +237,7 @@ public void SetAddWindowDirection_DirectionNotSet(IContext ctx, IMonitor monitor
public void SetAddWindowDirection_DirectionAlreadySet(IContext ctx, IMonitor monitor, IWorkspace workspace)
{
// Given
NativeManagerUtils.SetupTryEnqueue(ctx);
ctx.Butler.Pantry.GetWorkspaceForMonitor(monitor).Returns(workspace);

TreeLayoutPlugin plugin = new(ctx);
Expand Down
20 changes: 12 additions & 8 deletions src/Whim.TreeLayout/TreeLayoutPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ public void SetAddWindowDirection(TreeLayoutEngine engine, Direction direction)
: DefaultAddNodeDirection;

_addNodeDirections[engine.Identity] = direction;
AddWindowDirectionChanged?.Invoke(
this,
new AddWindowDirectionChangedEventArgs()
{
CurrentDirection = direction,
PreviousDirection = previousDirection,
TreeLayoutEngine = engine,
}

context.NativeManager.TryEnqueue(
() =>
AddWindowDirectionChanged?.Invoke(
this,
new AddWindowDirectionChangedEventArgs()
{
CurrentDirection = direction,
PreviousDirection = previousDirection,
TreeLayoutEngine = engine,
}
)
);
}

Expand Down

0 comments on commit 86eace7

Please sign in to comment.