Skip to content

Commit

Permalink
Fix automatic screen placer (Closes #708) (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMacocian committed May 5, 2024
1 parent dbfd555 commit fe0a77d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void RestartDaybreakAsNormalUser()
var sw = Stopwatch.StartNew();
while (sw.Elapsed.TotalSeconds < LaunchTimeout.TotalSeconds)
{
await Task.Delay(16);
await Task.Delay(500);
var gwProcess = Process.GetProcessesByName("gw").FirstOrDefault();
if (gwProcess is null)
{
Expand Down
16 changes: 3 additions & 13 deletions Daybreak/Services/Screens/GuildwarsScreenPlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Daybreak.Models;
using Daybreak.Services.Scanner;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Core.Extensions;
Expand All @@ -13,7 +14,7 @@ namespace Daybreak.Services.Screens;

internal sealed class GuildwarsScreenPlacer : IGuildwarsScreenPlacer
{
private const int MaxTries = 10;
private static readonly TimeSpan Delay = TimeSpan.FromSeconds(5);

private readonly IGuildwarsMemoryCache guildwarsMemoryCache;
private readonly ILiveUpdateableOptions<LauncherOptions> liveOptions;
Expand Down Expand Up @@ -53,18 +54,7 @@ public async Task OnGuildWarsStarted(ApplicationLauncherContext applicationLaunc
return;
}

var tries = 0;
while (await this.guildwarsMemoryCache.ReadLoginData(CancellationToken.None) is null)
{
await Task.Delay(1000, cancellationToken);
tries++;
if (tries > MaxTries)
{
this.logger.LogInformation("Failed to detect startup of Guildwars. Cancelling screen placement operation");
return;
}
}

await Task.Delay(Delay, cancellationToken);
this.screenManager.MoveGuildwarsToScreen(screen);
return;
}
Expand Down

0 comments on commit fe0a77d

Please sign in to comment.