diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index d6cf6a107..4e491f12a 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -151,9 +151,6 @@ internal sealed class Dalamud : IServiceType // will not receive any windows messages Service.GetNullable()?.Dispose(); - // this must be done before unloading interface manager, since it relies on the window handle members. - Service.GetNullable()?.Dispose(); - // this must be done before unloading plugins, or it can cause a race condition // due to rendering happening on another thread, where a plugin might receive // a render call after it has been disposed, which can crash if it attempts to diff --git a/Dalamud/Interface/DragDrop/DragDropManager.cs b/Dalamud/Interface/DragDrop/DragDropManager.cs index 0bb7eac12..8a4a5ca51 100644 --- a/Dalamud/Interface/DragDrop/DragDropManager.cs +++ b/Dalamud/Interface/DragDrop/DragDropManager.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Threading.Tasks; + using Dalamud.Interface.Internal; +using Dalamud.IoC; +using Dalamud.IoC.Internal; using ImGuiNET; using Serilog; @@ -12,22 +14,19 @@ namespace Dalamud.Interface.DragDrop; /// A manager that keeps state of external windows drag and drop events, /// and can be used to create ImGui drag and drop sources and targets for those external events. /// +[PluginInterface] [ServiceManager.EarlyLoadedService] +[InherentDependency] internal partial class DragDropManager : IDisposable, IDragDropManager, IServiceType { - private InterfaceManager? interfaceManager; + private readonly InterfaceManager interfaceManager = Service.Get(); private int lastDropFrame = -2; private int lastTooltipFrame = -1; + [ServiceManager.ServiceConstructor] private DragDropManager() - { - Service.GetAsync().ContinueWith(task => - { - this.interfaceManager = task.Result.Manager; - this.Enable(); - }); - } + => this.Enable(); /// Gets a value indicating whether external drag and drop is available at all. public bool ServiceAvailable { get; private set; } @@ -51,16 +50,16 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService /// Enable external drag and drop. public void Enable() { - if (this.ServiceAvailable || this.interfaceManager == null) + if (this.ServiceAvailable) { return; } try { - var ret2 = DragDropInterop.RegisterDragDrop(this.interfaceManager.WindowHandlePtr, this); - Log.Information($"[DragDrop] Registered window {this.interfaceManager.WindowHandlePtr} for external drag and drop operations. ({ret2})"); - Marshal.ThrowExceptionForHR(ret2); + var ret = DragDropInterop.RegisterDragDrop(this.interfaceManager.WindowHandlePtr, this); + Log.Information($"[DragDrop] Registered window {this.interfaceManager.WindowHandlePtr} for external drag and drop operations. ({ret})"); + Marshal.ThrowExceptionForHR(ret); this.ServiceAvailable = true; } catch (Exception ex) @@ -79,8 +78,9 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService try { - DragDropInterop.RevokeDragDrop(this.interfaceManager!.WindowHandlePtr); - Log.Information($"[DragDrop] Disabled external drag and drop operations for window {this.interfaceManager.WindowHandlePtr}."); + var ret = DragDropInterop.RevokeDragDrop(this.interfaceManager!.WindowHandlePtr); + Log.Information($"[DragDrop] Disabled external drag and drop operations for window {this.interfaceManager.WindowHandlePtr}. ({ret})"); + Marshal.ThrowExceptionForHR(ret); } catch (Exception ex) { diff --git a/Dalamud/Interface/UiBuilder.cs b/Dalamud/Interface/UiBuilder.cs index 5a757e0e6..53f223ef2 100644 --- a/Dalamud/Interface/UiBuilder.cs +++ b/Dalamud/Interface/UiBuilder.cs @@ -31,7 +31,6 @@ public sealed class UiBuilder : IDisposable private readonly string namespaceName; private readonly InterfaceManager interfaceManager = Service.Get(); private readonly GameFontManager gameFontManager = Service.Get(); - private readonly DragDropManager dragDropManager = Service.Get(); [ServiceManager.ServiceDependency] private readonly DalamudConfiguration configuration = Service.Get(); @@ -102,11 +101,6 @@ public sealed class UiBuilder : IDisposable /// public event Action HideUi; - /// - /// Gets the manager for external, WinAPI-based drag and drop functionality. - /// - public IDragDropManager DragDropManager => this.dragDropManager; - /// /// Gets the default Dalamud font based on Noto Sans CJK Medium in 17pt - supporting all game languages and icons. ///