Fix wasm deployment issue (#827)

* fix: update wasm-tools installation

* fix: add TrimmerRootAssembly for WASM optimization

* fix: update project to target .NET 10 and adjust deployment settings

* fix: add TrimmerRootAssembly for Ursa.Demo to improve WASM optimization

* fix: avoid Window based dialog crash on non-supported platforms.
This commit is contained in:
Dong Bin
2025-11-17 11:24:07 +08:00
committed by GitHub
parent 1cf920afa8
commit a4906d5130
5 changed files with 29 additions and 6 deletions

View File

@@ -2,7 +2,7 @@ name: Deploy to GitHub Pages
env: env:
PROJECT_PATH: demo/Ursa.Demo.Browser/Ursa.Demo.Browser.csproj PROJECT_PATH: demo/Ursa.Demo.Browser/Ursa.Demo.Browser.csproj
OUTPUT_PATH: demo/Ursa.Demo.Browser/bin/Release/net8.0-browser/publish/wwwroot OUTPUT_PATH: demo/Ursa.Demo.Browser/bin/Release/net10.0-browser/publish/wwwroot
on: on:
workflow_dispatch: workflow_dispatch:
@@ -13,10 +13,10 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4.1.1 uses: actions/checkout@v4.1.1
- name: Setup .NET 8 - name: Setup .NET 10
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v5
with: with:
dotnet-version: 8.0.x dotnet-version: 10.0.x
- name: Install wasm-tools - name: Install wasm-tools
run: dotnet workload install wasm-tools run: dotnet workload install wasm-tools

View File

@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.WebAssembly"> <Project Sdk="Microsoft.NET.Sdk.WebAssembly">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-browser</TargetFramework> <TargetFramework>net10.0-browser</TargetFramework>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
@@ -9,9 +9,15 @@
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets\**"/> <AvaloniaResource Include="Assets\**"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<TrimmerRootAssembly Include="Ursa.Demo" />
<TrimmerRootAssembly Include="Ursa.Demo.Browser" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia.Browser" Version="$(AvaloniaVersion)"/> <PackageReference Include="Avalonia.Browser" Version="$(AvaloniaVersion)"/>
<PackageReference Include="SkiaSharp.NativeAssets.WebAssembly" Version="3.119.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -30,6 +30,6 @@ public class ButtonItem
private async Task Invoke() private async Task Invoke()
{ {
await MessageBox.ShowAsync("Hello " + Name); await MessageBox.ShowOverlayAsync("Hello " + Name);
} }
} }

View File

@@ -48,6 +48,11 @@ public partial class DefaultWindowDialogDemoViewModel: ObservableObject
private async Task ShowDialog() private async Task ShowDialog()
{ {
if(OperatingSystem.IsBrowser() || OperatingSystem.IsAndroid() || OperatingSystem.IsIOS())
{
await MessageBox.ShowOverlayAsync("Window dialogs are not supported on this platform. Please use overlay dialogs instead.");
return;
}
var options = new DialogOptions() var options = new DialogOptions()
{ {
Title = Title, Title = Title,
@@ -92,6 +97,11 @@ public partial class CustomWindowDialogDemoViewModel: ObservableObject
private async Task ShowDialog() private async Task ShowDialog()
{ {
if(OperatingSystem.IsBrowser() || OperatingSystem.IsAndroid() || OperatingSystem.IsIOS())
{
await MessageBox.ShowOverlayAsync("Window dialogs are not supported on this platform. Please use overlay dialogs instead.");
return;
}
var options = new DialogOptions() var options = new DialogOptions()
{ {
Title = Title, Title = Title,

View File

@@ -2,6 +2,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using Avalonia.Markup.Xaml.MarkupExtensions;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input; using CommunityToolkit.Mvvm.Input;
using Ursa.Controls; using Ursa.Controls;
@@ -126,6 +127,12 @@ public class MessageBoxDemoViewModel: ObservableObject
} }
else else
{ {
if (OperatingSystem.IsBrowser() || OperatingSystem.IsAndroid() || OperatingSystem.IsIOS())
{
await MessageBox.ShowOverlayAsync("Only overlay message box is supported on this platform.",
"Ursa MessageBox", button: MessageBoxButton.OK, icon: MessageBoxIcon.Error);
return;
}
Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:button); Result = await MessageBox.ShowAsync(_message, _title, icon: SelectedIcon, button:button);
} }
} }