From 79fa0f0f3faf4ba0ca84856f50f43b33da0a3341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Lampron?= Date: Tue, 3 Dec 2024 19:46:52 -0500 Subject: [PATCH] Handle poe 2 in DockingHelper --- .editorconfig | 2 +- src/PoeLurker.Core/ClientLurker.cs | 22 ++++++++++++++++++- src/PoeLurker.Core/Helpers/DockingHelper.cs | 12 +++++++++- src/PoeLurker.UI/ViewModels/ShellViewModel.cs | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0b52fb3a..8d6348d2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -20,7 +20,7 @@ csharp_prefer_braces = true:silent csharp_style_namespace_declarations = file_scoped:silent csharp_style_prefer_method_group_conversion = true:silent csharp_style_prefer_top_level_statements = true:silent -csharp_style_prefer_primary_constructors = true:suggestion +csharp_style_prefer_primary_constructors = false:suggestion csharp_style_expression_bodied_methods = false:silent csharp_style_expression_bodied_constructors = false:silent csharp_style_expression_bodied_operators = false:silent diff --git a/src/PoeLurker.Core/ClientLurker.cs b/src/PoeLurker.Core/ClientLurker.cs index ead9cd1d..2dcf59d8 100644 --- a/src/PoeLurker.Core/ClientLurker.cs +++ b/src/PoeLurker.Core/ClientLurker.cs @@ -33,6 +33,7 @@ public class ClientLurker : IDisposable private readonly CancellationTokenSource _tokenSource; private readonly Process _pathOfExileProcess; private string _currentLeague; + private bool _poe2; #endregion @@ -73,6 +74,11 @@ public ClientLurker(int processId) #region Events + /// + /// Occurs when the player changed the location. + /// + public event EventHandler Poe2; + /// /// Occurs when [request admin]. /// @@ -143,6 +149,7 @@ public ClientLurker(int processId) public void Dispose() { Dispose(true); + GC.SuppressFinalize(this); } /// @@ -360,7 +367,13 @@ private void OnFileChanged(string newline) var generatingLevelEvent = GeneratingLevelEvent.TryParse(newline); if (generatingLevelEvent != null) { - Models.PoeApplicationContext.Poe2 = true; + if (!_poe2) + { + _poe2 = true; + Models.PoeApplicationContext.Poe2 = true; + Poe2?.Invoke(this, Models.PoeApplicationContext.Poe2); + } + GeneratingLevel?.Invoke(this, generatingLevelEvent); return; } @@ -368,6 +381,13 @@ private void OnFileChanged(string newline) var locationEvent = LocationChangedEvent.TryParse(newline); if (locationEvent != null) { + if (_poe2) + { + _poe2 = false; + Models.PoeApplicationContext.Poe2 = false; + Poe2?.Invoke(this, Models.PoeApplicationContext.Poe2); + } + Models.PoeApplicationContext.Location = locationEvent.Location; LocationChanged?.Invoke(this, locationEvent); return; diff --git a/src/PoeLurker.Core/Helpers/DockingHelper.cs b/src/PoeLurker.Core/Helpers/DockingHelper.cs index eabd8c74..4ecdf90e 100644 --- a/src/PoeLurker.Core/Helpers/DockingHelper.cs +++ b/src/PoeLurker.Core/Helpers/DockingHelper.cs @@ -45,6 +45,7 @@ public class DockingHelper : IDisposable private readonly IntPtr _windowHandle; private IntPtr _currentWindowStyle; private readonly Process _process; + private readonly ClientLurker _clientLurker; #endregion @@ -55,11 +56,14 @@ public class DockingHelper : IDisposable /// /// The process identifier. /// The settings service. - public DockingHelper(int processId, SettingsService settingsService) + public DockingHelper(int processId, SettingsService settingsService, ClientLurker clientLurker) { _process = Process.GetProcessById(processId); + _clientLurker = clientLurker; + if (_process != null) { + _clientLurker.Poe2 += ClientLurker_Poe2; _myProcess = Process.GetCurrentProcess(); _tokenSource = new CancellationTokenSource(); _settingsService = settingsService; @@ -153,12 +157,18 @@ protected virtual void Dispose(bool disposing) { if (disposing) { + _clientLurker.Poe2 -= ClientLurker_Poe2; _myProcess.Dispose(); _tokenSource.Cancel(); UnhookWinEvent(_hook); } } + private void ClientLurker_Poe2(object sender, bool e) + { + InvokeWindowMove(); + } + /// /// Removes the window border. /// diff --git a/src/PoeLurker.UI/ViewModels/ShellViewModel.cs b/src/PoeLurker.UI/ViewModels/ShellViewModel.cs index 3ce5e7c8..984445d7 100644 --- a/src/PoeLurker.UI/ViewModels/ShellViewModel.cs +++ b/src/PoeLurker.UI/ViewModels/ShellViewModel.cs @@ -472,7 +472,7 @@ private void ShowOverlays(int processId) { Execute.OnUIThread(() => { - _currentDockingHelper = new DockingHelper(processId, _settingsService); + _currentDockingHelper = new DockingHelper(processId, _settingsService, _currentLurker); // Keyboard var keyboarHelper = new PoeKeyboardHelper(processId);