Browse Source

add js emscripten injection.

pull/9028/head
Dan Walmsley 4 years ago
parent
commit
08336ae4b3
  1. 5
      src/Web/Avalonia.Web.Sample/Avalonia.Web.Sample.csproj
  2. 13
      src/Web/Avalonia.Web.Sample/Program.cs
  3. 13
      src/Web/Avalonia.Web.Sample/interop.js

5
src/Web/Avalonia.Web.Sample/Avalonia.Web.Sample.csproj

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
@ -6,6 +6,9 @@
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<MSBuildEnableWorkloadResolver>true</MSBuildEnableWorkloadResolver>
<WasmBuildNative>true</WasmBuildNative>
<EmccFlags>-sVERBOSE</EmccFlags>
<EmccExtraLDFlags>--js-library="C:\Users\User\repos\Avalonia\src\Web\Avalonia.Web.Sample\interop.js"</EmccExtraLDFlags>
</PropertyGroup>
<ItemGroup>

13
src/Web/Avalonia.Web.Sample/Program.cs

@ -1,4 +1,5 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.JavaScript;
using System.Threading.Tasks;
using Avalonia.Web;
@ -6,10 +7,22 @@ using Avalonia.Web;
internal class Program
{
[DllImport("libSkiaSharp", CallingConvention = CallingConvention.Cdecl)]
static extern JSObject example_initialize();
private static void Main(string[] args)
{
Console.WriteLine("Hello, Browser!");
example_initialize();
Console.WriteLine();
foreach(var arg in args)
{
Console.WriteLine(arg);
}
AvaloniaRuntime.Init();
}
}

13
src/Web/Avalonia.Web.Sample/interop.js

@ -0,0 +1,13 @@
var LibraryExample = {
// Internal functions
$EXAMPLE: {
internal_func: function () {
}
},
example_initialize: function () {
window["avalonia-helper-GL"] = GL
}
}
autoAddDeps(LibraryExample, '$EXAMPLE')
mergeInto(LibraryManager.library, LibraryExample)
Loading…
Cancel
Save