Skip to content

Commit

Permalink
Wait for guildwars window to be initialized before moving to desired …
Browse files Browse the repository at this point in the history
…window.
  • Loading branch information
Alexandru Macocian committed Apr 26, 2021
1 parent 8405e4d commit 6622e41
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<Version>0.8.2</Version>
<Version>0.8.3</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
17 changes: 14 additions & 3 deletions Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private async Task<bool> LaunchGuildwarsProcess(string email, Models.SecureStrin
var retries = 0;
while (true)
{
await Task.Delay(1000);
await Task.Delay(100);
retries++;
var gwProcess = Process.GetProcessesByName("gw").FirstOrDefault();
if (gwProcess is null && retries < MaxRetries)
Expand All @@ -202,10 +202,21 @@ private async Task<bool> LaunchGuildwarsProcess(string email, Models.SecureStrin
throw new InvalidOperationException("Newly launched gw process not detected");
}

if (gwProcess.MainWindowHandle != IntPtr.Zero)
if (gwProcess.MainWindowHandle == IntPtr.Zero)
{
return true;
continue;
}

int titleLength = NativeMethods.GetWindowTextLength(gwProcess.MainWindowHandle);
var titleBuffer = new StringBuilder(titleLength);
var readCount = NativeMethods.GetWindowText(gwProcess.MainWindowHandle, titleBuffer, titleLength + 1);
var title = titleBuffer.ToString();
if (title != "Guild Wars")
{
continue;
}

return true;
}
}

Expand Down
4 changes: 4 additions & 0 deletions Daybreak/Utils/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,9 @@ public enum FileInformationClass
public static extern bool SetWindowPos(IntPtr hwnd, IntPtr insertAfter, int x, int y, int cx, int cy, uint flags);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int cmd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
}
}
1 change: 1 addition & 0 deletions Daybreak/Views/MainView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ private async void LaunchButton_Clicked(object sender, EventArgs e)
{
throw new InvalidOperationException($"Unable to set guildwars on desired screen. No screen with id {id}");
}
await Task.Delay(1000);
this.screenManager.MoveGuildwarsToScreen(desiredScreen);
}

Expand Down

0 comments on commit 6622e41

Please sign in to comment.