From be9ca7618aadc4ae101c5704198e900f381dab24 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 17 Jul 2023 00:47:16 +0200 Subject: [PATCH] Maybe fix dependency issues with early loading plugins that request IDragDropManager? --- Dalamud/Interface/DragDrop/DragDropManager.cs | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Dalamud/Interface/DragDrop/DragDropManager.cs b/Dalamud/Interface/DragDrop/DragDropManager.cs index 34f1296e1..8336edc11 100644 --- a/Dalamud/Interface/DragDrop/DragDropManager.cs +++ b/Dalamud/Interface/DragDrop/DragDropManager.cs @@ -19,15 +19,21 @@ namespace Dalamud.Interface.DragDrop; [ResolveVia] internal partial class DragDropManager : IDisposable, IDragDropManager, IServiceType { - [ServiceManager.ServiceDependency] - private readonly InterfaceManager.InterfaceManagerWithScene interfaceManager = Service.Get(); + private nint windowHandlePtr = nint.Zero; private int lastDropFrame = -2; private int lastTooltipFrame = -1; [ServiceManager.ServiceConstructor] private DragDropManager() - => this.Enable(); + { + Service.GetAsync() + .ContinueWith(t => + { + this.windowHandlePtr = t.Result.Manager.WindowHandlePtr; + this.Enable(); + }); + } /// Gets a value indicating whether external drag and drop is available at all. public bool ServiceAvailable { get; private set; } @@ -51,21 +57,21 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService /// Enable external drag and drop. public void Enable() { - if (this.ServiceAvailable) + if (this.ServiceAvailable || this.windowHandlePtr == nint.Zero) { return; } try { - var ret = DragDropInterop.RegisterDragDrop(this.interfaceManager.Manager.WindowHandlePtr, this); - Log.Information($"[DragDrop] Registered window 0x{this.interfaceManager.Manager.WindowHandlePtr:X} for external drag and drop operations. ({ret})"); + var ret = DragDropInterop.RegisterDragDrop(this.windowHandlePtr, this); + Log.Information($"[DragDrop] Registered window 0x{this.windowHandlePtr:X} for external drag and drop operations. ({ret})"); Marshal.ThrowExceptionForHR(ret); this.ServiceAvailable = true; } catch (Exception ex) { - Log.Error($"Could not create windows drag and drop utility for window 0x{this.interfaceManager.Manager.WindowHandlePtr:X}:\n{ex}"); + Log.Error($"Could not create windows drag and drop utility for window 0x{this.windowHandlePtr:X}:\n{ex}"); } } @@ -79,13 +85,13 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService try { - var ret = DragDropInterop.RevokeDragDrop(this.interfaceManager.Manager.WindowHandlePtr); - Log.Information($"[DragDrop] Disabled external drag and drop operations for window 0x{this.interfaceManager.Manager.WindowHandlePtr:X}. ({ret})"); + var ret = DragDropInterop.RevokeDragDrop(this.windowHandlePtr); + Log.Information($"[DragDrop] Disabled external drag and drop operations for window 0x{this.windowHandlePtr:X}. ({ret})"); Marshal.ThrowExceptionForHR(ret); } catch (Exception ex) { - Log.Error($"Could not disable windows drag and drop utility for window 0x{this.interfaceManager.Manager.WindowHandlePtr:X}:\n{ex}"); + Log.Error($"Could not disable windows drag and drop utility for window 0x{this.windowHandlePtr:X}:\n{ex}"); } this.ServiceAvailable = false;