private static async void UpdateOverlayAsync() { #if (!SQUIRREL) if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(true); } #endif var hsForegroundChanged = false; var useNoDeckMenuItem = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone"); while (UpdateOverlay) { if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(); } if (User32.GetHearthstoneWindow() != IntPtr.Zero) { if (Game.CurrentRegion == Region.UNKNOWN) { //game started Game.CurrentRegion = Helper.GetCurrentRegion(); if (Game.CurrentRegion != Region.UNKNOWN) { BackupManager.Run(); Game.MetaData.HearthstoneBuild = null; } } Overlay.UpdatePosition(); if (!Game.IsRunning) { Overlay.Update(true); Windows.CapturableOverlay?.UpdateContentVisibility(); } MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false; Game.IsRunning = true; Helper.GameWindowState = User32.GetHearthstoneWindowState(); Windows.CapturableOverlay?.Update(); if (User32.IsHearthstoneInForeground() && Helper.GameWindowState != WindowState.Minimized) { if (hsForegroundChanged) { Overlay.Update(true); if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { //if player topmost is set to true before opponent: //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs. //other way around it works for both windows... what? Windows.OpponentWindow.Topmost = true; Windows.PlayerWindow.Topmost = true; Windows.TimerWindow.Topmost = true; } hsForegroundChanged = false; } } else if (!hsForegroundChanged) { if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { Windows.PlayerWindow.Topmost = false; Windows.OpponentWindow.Topmost = false; Windows.TimerWindow.Topmost = false; } hsForegroundChanged = true; } } else if (Game.IsRunning) { Game.IsRunning = false; Overlay.ShowOverlay(false); if (Windows.CapturableOverlay != null) { Windows.CapturableOverlay.UpdateContentVisibility(); await Task.Delay(100); Windows.CapturableOverlay.ForcedWindowState = WindowState.Minimized; Windows.CapturableOverlay.WindowState = WindowState.Minimized; } Log.Info("Exited game"); Game.CurrentRegion = Region.UNKNOWN; Log.Info("Reset region"); await Reset(); Game.IsInMenu = true; Game.InvalidateMatchInfoCache(); Overlay.HideRestartRequiredWarning(); Helper.ClearCachedHearthstoneBuild(); TurnTimer.Instance.Stop(); MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true; if (Config.Instance.CloseWithHearthstone) { MainWindow.Close(); } } if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value && Initialized && !User32.IsHearthstoneInForeground()) { NetDeck.CheckForClipboardImport(); } await Task.Delay(UpdateDelay); } CanShutdown = true; }
private static async void UpdateOverlayAsync() { if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(true); } var hsForegroundChanged = false; var useNoDeckMenuItem = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone"); UpdateOverlay = Helper.HearthstoneDirExists; while (UpdateOverlay) { if (User32.GetHearthstoneWindow() != IntPtr.Zero) { if (Game.CurrentRegion == Region.UNKNOWN) { //game started Game.CurrentRegion = Helper.GetCurrentRegion(); BackupManager.Run(); } Overlay.UpdatePosition(); if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(); } if (!Game.IsRunning) { Overlay.Update(true); } MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false; Game.IsRunning = true; if (User32.IsHearthstoneInForeground()) { if (hsForegroundChanged) { Overlay.Update(true); if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { //if player topmost is set to true before opponent: //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs. //other way around it works for both windows... what? Windows.OpponentWindow.Topmost = true; Windows.PlayerWindow.Topmost = true; Windows.TimerWindow.Topmost = true; } hsForegroundChanged = false; } } else if (!hsForegroundChanged) { if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { Windows.PlayerWindow.Topmost = false; Windows.OpponentWindow.Topmost = false; Windows.TimerWindow.Topmost = false; } hsForegroundChanged = true; } } else { Overlay.ShowOverlay(false); if (Game.IsRunning) { //game was closed Logger.WriteLine("Exited game", "UpdateOverlayLoop"); Game.CurrentRegion = Region.UNKNOWN; Logger.WriteLine("Reset region", "UpdateOverlayLoop"); await Reset(); MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true; if (Config.Instance.CloseWithHearthstone) { MainWindow.Close(); } } Game.IsRunning = false; } if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value && Initialized && !User32.IsHearthstoneInForeground()) { NetDeck.CheckForClipboardImport(); } await Task.Delay(Config.Instance.UpdateDelay); } CanShutdown = true; }