global event for projects running changed
This commit is contained in:
7
src/SharpIDE.Application/Features/Events/GlobalEvents.cs
Normal file
7
src/SharpIDE.Application/Features/Events/GlobalEvents.cs
Normal 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();
|
||||
}
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user