Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DeviceRunners.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EE37724C-5
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.WebApp", "sample\src\DeviceTestingKitApp.WebApp\DeviceTestingKitApp.WebApp.csproj", "{2A387F0F-3DBE-4A6C-BEB5-60CA6CE6F4B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeviceTestingKitApp.BlazorLibrary", "sample\src\DeviceTestingKitApp.BlazorLibrary\DeviceTestingKitApp.BlazorLibrary.csproj", "{8C3A7E82-0F4D-4B9C-A5E6-1A2B3C4D5E6F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceRunners.Cli", "src\DeviceRunners.Cli\DeviceRunners.Cli.csproj", "{E0CEF24B-9991-4BE0-8FD6-4BC464A8D59B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeviceRunners.Cli.Tests", "test\DeviceRunners.Cli.Tests\DeviceRunners.Cli.Tests.csproj", "{CADA0B60-3175-4471-814F-635D701BBD44}"
Expand Down Expand Up @@ -147,6 +149,10 @@ Global
{2A387F0F-3DBE-4A6C-BEB5-60CA6CE6F4B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A387F0F-3DBE-4A6C-BEB5-60CA6CE6F4B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A387F0F-3DBE-4A6C-BEB5-60CA6CE6F4B4}.Release|Any CPU.Build.0 = Release|Any CPU
{8C3A7E82-0F4D-4B9C-A5E6-1A2B3C4D5E6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C3A7E82-0F4D-4B9C-A5E6-1A2B3C4D5E6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C3A7E82-0F4D-4B9C-A5E6-1A2B3C4D5E6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C3A7E82-0F4D-4B9C-A5E6-1A2B3C4D5E6F}.Release|Any CPU.Build.0 = Release|Any CPU
{E0CEF24B-9991-4BE0-8FD6-4BC464A8D59B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0CEF24B-9991-4BE0-8FD6-4BC464A8D59B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0CEF24B-9991-4BE0-8FD6-4BC464A8D59B}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -182,6 +188,7 @@ Global
{7FD9E644-B760-47D7-A4FC-61199AFE9D62} = {46348E44-C1A8-4923-B3E9-7B9217BA5792}
{EE37724C-5FEF-46BB-AD80-CD002CC7FF54} = {46348E44-C1A8-4923-B3E9-7B9217BA5792}
{2A387F0F-3DBE-4A6C-BEB5-60CA6CE6F4B4} = {7FD9E644-B760-47D7-A4FC-61199AFE9D62}
{8C3A7E82-0F4D-4B9C-A5E6-1A2B3C4D5E6F} = {7FD9E644-B760-47D7-A4FC-61199AFE9D62}
{E0CEF24B-9991-4BE0-8FD6-4BC464A8D59B} = {DBF1C119-C96C-4DD3-810B-52451603475C}
{CADA0B60-3175-4471-814F-635D701BBD44} = {5073EAFD-FF7B-4C4E-84D2-3AA38A91DE73}
EndGlobalSection
Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PackageVersion Include="AndroidSdk" Version="0.25.0" />
<PackageVersion Include="AppleDev" Version="0.6.6" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="9.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.0" />
<PackageVersion Include="Microsoft.DotNet.XHarness.DefaultAndroidEntryPoint.Xunit" Version="9.0.0-prerelease.24066.3" />
<PackageVersion Include="Microsoft.DotNet.XHarness.TestRunners.Common" Version="9.0.0-prerelease.24066.3" />
<PackageVersion Include="Microsoft.DotNet.XHarness.TestRunners.Xunit" Version="9.0.0-prerelease.24066.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@using DeviceTestingKitApp.ViewModels
@using DeviceTestingKitApp.Converters
@implements IDisposable

<button id="CounterButton"
class="btn btn-primary"
@onclick="HandleIncrement"
title="Counts the number of times you click">
@CounterTextConverter.ConvertCountToText(ViewModel?.Count ?? 0)
</button>

@code {
[Parameter] public CounterViewModel? ViewModel { get; set; }

protected override void OnParametersSet()
{
if (ViewModel != null)
{
ViewModel.PropertyChanged += OnViewModelPropertyChanged;
}
}

private void OnViewModelPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(CounterViewModel.Count))
{
InvokeAsync(StateHasChanged);
}
}

private void HandleIncrement()
{
ViewModel?.IncrementCommand.Execute(null);
}

public void Dispose()
{
if (ViewModel != null)
{
ViewModel.PropertyChanged -= OnViewModelPropertyChanged;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace DeviceTestingKitApp.Converters;

public static class CounterTextConverter
{
public static string ConvertCountToText(int count)
{
return count switch
{
0 => "Click me!",
1 => $"Clicked {count} time",
_ => $"Clicked {count} times"
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>DeviceTestingKitApp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DeviceTestingKitApp.Library\DeviceTestingKitApp.Library.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using DeviceTestingKitApp.Features;
using Microsoft.JSInterop;

namespace DeviceTestingKitApp.Features;

public class BlazorSemanticAnnouncer : ISemanticAnnouncer, IAsyncDisposable
{
private readonly IJSRuntime _jsRuntime;
private IJSObjectReference? _module;

public BlazorSemanticAnnouncer(IJSRuntime jsRuntime)
{
_jsRuntime = jsRuntime;
}

public void Announce(string message)
{
// Use ARIA live regions for proper accessibility announcements
_ = Task.Run(async () =>
{
try
{
await EnsureModuleLoadedAsync();
if (_module != null)
{
await _module.InvokeVoidAsync("announceToScreenReader", message);
}
}
catch
{
// Ignore JS interop errors in case JS is not available
}
});
}

private async Task EnsureModuleLoadedAsync()
{
if (_module == null)
{
_module = await _jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/DeviceTestingKitApp.BlazorLibrary/js/accessibility.js");
}
}

public async ValueTask DisposeAsync()
{
if (_module != null)
{
await _module.DisposeAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@using Microsoft.AspNetCore.Components.Web
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Accessibility support functions module

export function announceToScreenReader(message) {
// Create or get the live region element
let liveRegion = document.getElementById('sr-live-region');
if (!liveRegion) {
liveRegion = document.createElement('div');
liveRegion.id = 'sr-live-region';
liveRegion.setAttribute('aria-live', 'polite');
liveRegion.setAttribute('aria-atomic', 'true');
liveRegion.style.position = 'absolute';
liveRegion.style.left = '-10000px';
liveRegion.style.width = '1px';
liveRegion.style.height = '1px';
liveRegion.style.overflow = 'hidden';
document.body.appendChild(liveRegion);
}

// Clear and set the message
liveRegion.textContent = '';
setTimeout(() => {
liveRegion.textContent = message;
}, 100);
}
41 changes: 15 additions & 26 deletions sample/src/DeviceTestingKitApp.WebApp/Components/Pages/Home.razor
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
ο»Ώ@page "/"
@rendermode InteractiveServer
@inject MainViewModel MainViewModel

<PageTitle>Home</PageTitle>
<PageTitle>DeviceTestingKitApp</PageTitle>

<h1>Home</h1>
<div class="container" style="padding: 30px 0; text-align: center;">
<div style="display: flex; flex-direction: column; align-items: center; gap: 25px;">

<img src="https://raw.githubusercontent.com/mattleibow/DeviceRunners/main/sample/src/DeviceTestingKitApp/Resources/Images/dotnet_bot.png"
alt="dot net bot in a race car number eight"
style="height: 185px; object-fit: contain;" />

<img src="https://raw.githubusercontent.com/mattleibow/DeviceRunners/main/sample/src/DeviceTestingKitApp/Resources/Images/dotnet_bot.png"
alt="dot net bot in a race car number eight"
style="width: 300px"/>
<h1 style="margin: 0; font-size: 2rem; font-weight: 600;">Hello, World!</h1>

<p>Hello, World</p>
<h2 style="margin: 0; font-size: 1.5rem; font-weight: 400; text-align: center;">
Welcome to<br />.NET Multi-platform App UI
</h2>

<p>Welcome to <br />.NET Blazor</p>
<CounterView ViewModel="@MainViewModel.Counter" />

<button id="CounterButton"
class="btn btn-primary" @onclick="IncrementCount"
title="Counts the number of times you click">@message</button>

@code {
private int currentCount = 0;
private string message = "Click me!";

private void IncrementCount()
{
currentCount++;
message = currentCount switch
{
0 => "Click me!",
1 => $"Clicked {currentCount} time",
_ => $"Clicked {currentCount} times"
};
}
}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
@using Microsoft.JSInterop
@using DeviceTestingKitApp.WebApp
@using DeviceTestingKitApp.WebApp.Components
@using DeviceTestingKitApp.Controls
@using DeviceTestingKitApp.ViewModels
@using DeviceTestingKitApp.Features
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\DeviceTestingKitApp.Library\DeviceTestingKitApp.Library.csproj" />
<ProjectReference Include="..\DeviceTestingKitApp.BlazorLibrary\DeviceTestingKitApp.BlazorLibrary.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions sample/src/DeviceTestingKitApp.WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
using DeviceTestingKitApp.WebApp.Components;
using DeviceTestingKitApp.Features;
using DeviceTestingKitApp.ViewModels;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();

// Register view models from the library project (same as MAUI app)
builder.Services.AddTransient<MainViewModel>();
builder.Services.AddTransient<CounterViewModel>();

// Register Blazor-specific semantic announcer
builder.Services.AddTransient<ISemanticAnnouncer, BlazorSemanticAnnouncer>();

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand Down