Skip to content

Commit

Permalink
Add back Mac invoke workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Mar 16, 2024
1 parent 0a7349c commit f903747
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions NAPS2.Lib.Mac/EtoForms/Mac/MacEtoPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> CreateListView<T>(ListViewBehavior<T> behavior) =>
new MacListView<T>(behavior);

Expand Down
6 changes: 3 additions & 3 deletions NAPS2.Lib/EtoForms/EtoInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(Func<T> func)
{
T value = default!;
_application.Invoke(() => value = func());
EtoPlatform.Current.Invoke(_application, () => value = func());
return value;
}
}
10 changes: 10 additions & 0 deletions NAPS2.Lib/EtoForms/EtoPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down

0 comments on commit f903747

Please sign in to comment.