diff --git a/Daybreak/Daybreak.csproj b/Daybreak/Daybreak.csproj index 0e058ed4..575e7240 100644 --- a/Daybreak/Daybreak.csproj +++ b/Daybreak/Daybreak.csproj @@ -9,7 +9,7 @@ false preview Daybreak.ico - 0.8.2 + 0.8.3 diff --git a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs index 850a52c3..19d30230 100644 --- a/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs +++ b/Daybreak/Services/ApplicationLauncher/ApplicationLauncher.cs @@ -190,7 +190,7 @@ private async Task 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) @@ -202,10 +202,21 @@ private async Task 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; } } diff --git a/Daybreak/Utils/NativeMethods.cs b/Daybreak/Utils/NativeMethods.cs index 5a7e83e2..e1639fcf 100644 --- a/Daybreak/Utils/NativeMethods.cs +++ b/Daybreak/Utils/NativeMethods.cs @@ -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); } } \ No newline at end of file diff --git a/Daybreak/Views/MainView.xaml.cs b/Daybreak/Views/MainView.xaml.cs index 0a729029..9779092c 100644 --- a/Daybreak/Views/MainView.xaml.cs +++ b/Daybreak/Views/MainView.xaml.cs @@ -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); }