Skip to content

Commit

Permalink
perf: Add DispatcherCallback export
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 11, 2023
1 parent 6e81972 commit b42f301
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Uno.UI.Dispatching/Core/CoreDispatcher.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
using Uno.Foundation.Interop;
using Uno.Foundation.Logging;

#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
#endif

namespace Uno.UI.Dispatching
{
internal sealed partial class CoreDispatcher
Expand All @@ -22,6 +26,9 @@ internal sealed partial class CoreDispatcher
/// Method invoked from
/// </summary>
#pragma warning disable IDE0051 // Remove unused private members - called by MonoSupport.ts
#if NET7_0_OR_GREATER
[JSExport]
#endif
private static int DispatcherCallback()
#pragma warning restore IDE0051 // Remove unused private members
{
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI.Dispatching/Uno.UI.Dispatching.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<Import Project="../targetframework-override.props" />

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>Uno.UI.Dispatching</AssemblyName>
<RootNamespace>Uno.UI.Dispatching</RootNamespace>
<DefineConstants>$(DefineConstants);XAMARIN;IS_UNO;IS_UNO_UI_DISPATCHING_PROJECT</DefineConstants>
Expand Down
6 changes: 5 additions & 1 deletion src/Uno.UI/ts/CoreDispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@

private static initMethods() {
if (!CoreDispatcher._coreDispatcherCallback) {
CoreDispatcher._coreDispatcherCallback = (<any>Module).mono_bind_static_method("[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback");
if ((<any>globalThis).DotnetExports !== undefined) {
CoreDispatcher._coreDispatcherCallback = (<any>globalThis).DotnetExports.UnoUIDispatching.Uno.UI.Dispatching.CoreDispatcher.DispatcherCallback;
} else {
CoreDispatcher._coreDispatcherCallback = (<any>Module).mono_bind_static_method("[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback");
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/ts/ExportManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ namespace Uno.UI {
if ((<any>Module).getAssemblyExports !== undefined) {
const unoExports = await (<any>Module).getAssemblyExports("Uno");
const unoUIExports = await (<any>Module).getAssemblyExports("Uno.UI");
const unoUIDispatchingExports = await (<any>Module).getAssemblyExports("Uno.UI.Dispatching");

const runtimeWasmExports = await (<any>Module).getAssemblyExports("Uno.Foundation.Runtime.WebAssembly");

(<any>globalThis).DotnetExports = {
Uno: unoExports,
UnoUI: unoUIExports,
UnoUIDispatching: unoUIDispatchingExports,
UnoFoundationRuntimeWebAssembly: runtimeWasmExports
};
}
Expand Down
8 changes: 6 additions & 2 deletions src/Uno.UI/ts/MonoSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ namespace MonoSupport {
public static invokeOnMainThread() {

if (!jsCallDispatcher.dispatcherCallback) {
jsCallDispatcher.dispatcherCallback = (<any>Module).mono_bind_static_method(
"[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback");
if ((<any>globalThis).DotnetExports !== undefined) {
jsCallDispatcher.dispatcherCallback = (<any>globalThis).DotnetExports.UnoUIDispatching.Uno.UI.Dispatching.CoreDispatcher.DispatcherCallback;
} else {
jsCallDispatcher.dispatcherCallback = (<any>Module).mono_bind_static_method(
"[Uno.UI.Dispatching] Uno.UI.Dispatching.CoreDispatcher:DispatcherCallback");
}
}

// Use setImmediate to return avoid blocking the background thread
Expand Down

0 comments on commit b42f301

Please sign in to comment.