From f90374717a6c151d796431bf2fcffeef9612b425 Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Fri, 15 Mar 2024 18:55:50 -0700 Subject: [PATCH] Add back Mac invoke workaround --- NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs | 12 ++++++++++++ NAPS2.Lib/EtoForms/EtoInvoker.cs | 6 +++--- NAPS2.Lib/EtoForms/EtoPlatform.cs | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs index c00432518f..b4dc043cd5 100644 --- a/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs +++ b/NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs @@ -26,6 +26,18 @@ public override Application CreateApplication() return new Application(Platforms.macOS); } + public override void Invoke(Application application, Action action) + { + // TODO: Eto PR to always use InvokeOnMainThread, don't execute the action directly + // even if we're already on the main thread. + NSApplication.SharedApplication.InvokeOnMainThread(action); + } + + public override void AsyncInvoke(Application application, Action action) + { + NSApplication.SharedApplication.BeginInvokeOnMainThread(action); + } + public override IListView CreateListView(ListViewBehavior behavior) => new MacListView(behavior); diff --git a/NAPS2.Lib/EtoForms/EtoInvoker.cs b/NAPS2.Lib/EtoForms/EtoInvoker.cs index af21f77456..2d3fd9eaa7 100644 --- a/NAPS2.Lib/EtoForms/EtoInvoker.cs +++ b/NAPS2.Lib/EtoForms/EtoInvoker.cs @@ -13,18 +13,18 @@ public EtoInvoker(Application application) public void Invoke(Action action) { - _application.Invoke(action); + EtoPlatform.Current.Invoke(_application, action); } public void InvokeDispatch(Action action) { - _application.AsyncInvoke(action); + EtoPlatform.Current.AsyncInvoke(_application, action); } public T InvokeGet(Func func) { T value = default!; - _application.Invoke(() => value = func()); + EtoPlatform.Current.Invoke(_application, () => value = func()); return value; } } \ No newline at end of file diff --git a/NAPS2.Lib/EtoForms/EtoPlatform.cs b/NAPS2.Lib/EtoForms/EtoPlatform.cs index 91b724feb7..b232536a3b 100644 --- a/NAPS2.Lib/EtoForms/EtoPlatform.cs +++ b/NAPS2.Lib/EtoForms/EtoPlatform.cs @@ -37,6 +37,16 @@ public virtual void InitializePlatform() { } + public virtual void Invoke(Application application, Action action) + { + application.Invoke(action); + } + + public virtual void AsyncInvoke(Application application, Action action) + { + application.AsyncInvoke(action); + } + public virtual void SetContainerSize(Window window, Control container, Size size, int padding) { }