Skip to content

Commit 40efe9d

Browse files
committed
fix: check before shutdown if there are really no lessons near
1 parent 80ce9ca commit 40efe9d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/WinService/Services/ShutdownService.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private async Task StartShutdownLoop(CancellationToken stoppingToken)
5555
await Task.Delay(TimeSpan.FromMinutes(5), stoppingToken);
5656
while (await WaitUntilShutdownAsync(stoppingToken))
5757
{
58-
await SendShutdownAsync();
58+
await SendShutdownAsync(true);
5959
}
6060
}
6161

@@ -217,9 +217,23 @@ private Instant GetNearestFutureInstant(List<Instant> instants, Instant? target
217217
/// If no user is logged in it shuts down the pc immediately
218218
/// </summary>
219219
/// <returns></returns>
220-
private async Task SendShutdownAsync()
220+
private async Task SendShutdownAsync(bool lessonCheck = false)
221221
{
222-
logger.LogInformation("Send shutdown to client!");
222+
if (lessonCheck)
223+
{
224+
logger.LogInformation("Check again if there are really no lessons near.");
225+
var duration = await GetDurationUntilBreakAsync();
226+
227+
if (duration != Duration.Zero)
228+
{
229+
logger.LogWarning("There are lessons near!");
230+
return;
231+
}
232+
233+
logger.LogInformation("No lessons near, send shutdown to user!");
234+
}
235+
else
236+
logger.LogInformation("Send shutdown to user!");
223237

224238
if (!pipeService.Clients.IsEmpty)
225239
{

0 commit comments

Comments
 (0)