global event for projects running changed

This commit is contained in:
Matt Parker
2025-08-08 00:14:26 +10:00
parent 85d8a129a2
commit f220e31b36
3 changed files with 24 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
namespace SharpIDE.Application.Features.Events;
public static class GlobalEvents
{
public static event Func<Task> ProjectsRunningChanged = () => Task.CompletedTask;
public static void InvokeProjectsRunningChanged() => ProjectsRunningChanged?.Invoke();
}

View File

@@ -2,6 +2,7 @@
using Ardalis.GuardClauses;
using AsyncReadProcess.Common;
using AsyncReadProcess;
using SharpIDE.Application.Features.Events;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
namespace SharpIDE.Application.Features.Run;
@@ -39,8 +40,11 @@ public class RunService
}
});
project.Running = true;
GlobalEvents.InvokeProjectsRunningChanged();
await process.WaitForExitAsync();
project.Running = false;
GlobalEvents.InvokeProjectsRunningChanged();
Console.WriteLine("Project ran successfully.");
}

View File

@@ -1,4 +1,7 @@
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
@using SharpIDE.Application.Features.Events
@using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence
@implements IDisposable
<div @onmouseover="@(() => _open = true)">
<MudPopover Duration="100" OverflowBehavior="OverflowBehavior.FlipNever" Open="@true" AnchorOrigin="Origin.TopRight" TransformOrigin="Origin.TopRight">
@@ -16,7 +19,7 @@
<MudText>@project.Name</MudText>
<MudSpacer/>
<MudButton Style="min-width: 20px;">
<MudIcon Icon="@Icons.Material.Filled.PlayArrow" Size="Size.Medium" Color="Color.Success"/>
<MudIcon Icon="@(project.Running ? Icons.Material.Filled.Stop : Icons.Material.Filled.PlayArrow)" Size="Size.Medium" Color="@(project.Running ? Color.Error : Color.Success)"/>
</MudButton>
</MudStack>
</MudListItem>
@@ -45,6 +48,13 @@
var tasks = SolutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask).ToList();
await Task.WhenAll(tasks);
_ready = true;
GlobalEvents.ProjectsRunningChanged += OnProjectsRunningChanged;
}
private async Task OnProjectsRunningChanged()
{
await InvokeAsync(StateHasChanged);
}
public void Dispose() => GlobalEvents.ProjectsRunningChanged -= OnProjectsRunningChanged;
}