Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions src/BuiltInTools/dotnet-watch/HotReload/HotReloadDotNetWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,18 @@ public async Task WatchAsync(CancellationToken shutdownCancellationToken)
{
CancellationTokenSource? forceRestartCancellationSource = null;

if (!_context.Options.NonInteractive)
{
_context.Logger.Log(MessageDescriptor.HotReloadEnabled);
_context.Logger.Log(MessageDescriptor.PressCtrlRToRestart);
_context.Logger.Log(MessageDescriptor.HotReloadEnabled);
_context.Logger.Log(MessageDescriptor.PressCtrlRToRestart);

_console.KeyPressed += (key) =>
{
if (key.Modifiers.HasFlag(ConsoleModifiers.Control) && key.Key == ConsoleKey.R && forceRestartCancellationSource is { } source)
{
// provide immediate feedback to the user:
_context.Logger.Log(source.IsCancellationRequested ? MessageDescriptor.RestartInProgress : MessageDescriptor.RestartRequested);
source.Cancel();
}
};
}
else
_console.KeyPressed += (key) =>
{
_context.Logger.Log(MessageDescriptor.HotReloadEnabled with { Severity = MessageSeverity.Verbose });
}
if (key.Modifiers.HasFlag(ConsoleModifiers.Control) && key.Key == ConsoleKey.R && forceRestartCancellationSource is { } source)
{
// provide immediate feedback to the user:
_context.Logger.Log(source.IsCancellationRequested ? MessageDescriptor.RestartInProgress : MessageDescriptor.RestartRequested);
source.Cancel();
}
};

using var fileWatcher = new FileWatcher(_context.Logger, _context.EnvironmentOptions);

Expand Down
3 changes: 2 additions & 1 deletion test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,13 @@ public async Task BlazorWasm_Restart()
.WithSource();

var port = TestOptions.GetTestPort();
App.Start(testAsset, ["--urls", "http://localhost:" + port], testFlags: TestFlags.ReadKeyFromStdin | TestFlags.MockBrowser);
App.Start(testAsset, ["--urls", "http://localhost:" + port, "--non-interactive"], testFlags: TestFlags.ReadKeyFromStdin | TestFlags.MockBrowser);

await App.WaitForOutputLineContaining(MessageDescriptor.WaitingForChanges);

App.AssertOutputContains(MessageDescriptor.ConfiguredToUseBrowserRefresh);
App.AssertOutputContains(MessageDescriptor.ConfiguredToLaunchBrowser);
App.AssertOutputContains(MessageDescriptor.PressCtrlRToRestart);

// Browser is launched based on blazor-devserver output "Now listening on: ...".
await App.WaitUntilOutputContains($"dotnet watch ⌚ Launching browser: http://localhost:{port}");
Expand Down