Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to Avalonia v11 and .NET6 #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions samples/AvaloniaVncClient/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AvaloniaVncClient"
x:Class="AvaloniaVncClient.App">

<Application.DataTemplates>
<local:ViewLocator />
</Application.DataTemplates>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml" />
<SimpleTheme />
</Application.Styles>
</Application>
10 changes: 5 additions & 5 deletions samples/AvaloniaVncClient/AvaloniaVncClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
Expand All @@ -16,10 +16,10 @@
<Folder Include="Views\Dialogs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.0" />
<PackageReference Include="Avalonia.Desktop" Version="0.10.0" />
<PackageReference Include="Avalonia.Diagnostics" Version="0.10.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.10.0" />
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.10" />
<PackageReference Include="Avalonia.Diagnostics" Version="11.0.10" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MarcusW.VncClient.Avalonia\MarcusW.VncClient.Avalonia.csproj" />
Expand Down
2 changes: 1 addition & 1 deletion samples/AvaloniaVncClient/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;

public IControl Build(object data)
public Control Build(object data)
{
var viewName = data.GetType().FullName?.Replace("ViewModel", "View");
if (viewName == null)
Expand Down
4 changes: 2 additions & 2 deletions samples/AvaloniaVncClient/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
IsVisible="{Binding RfbConnection, Converter={x:Static ObjectConverters.IsNotNull}}">
<Grid RowDefinitions="Auto,*,Auto,*,Auto" Margin="10">
<TextBlock Grid.Row="0" Margin="0,0,0,10" FontWeight="Bold" Text="Used Message Types:" />
<ListBox Grid.Row="1" Margin="0,0,0,10" Items="{Binding RfbConnection.UsedMessageTypes}" BorderThickness="0">
<ListBox Grid.Row="1" Margin="0,0,0,10" ItemsSource="{Binding RfbConnection.UsedMessageTypes}" BorderThickness="0">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Grid.Row="2" Margin="0,0,0,10" FontWeight="Bold" Text="Used Encoding Types:" />
<ListBox Grid.Row="3" Items="{Binding RfbConnection.UsedEncodingTypes}" BorderThickness="0">
<ListBox Grid.Row="3" ItemsSource="{Binding RfbConnection.UsedEncodingTypes}" BorderThickness="0">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Avalonia.Logging;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

namespace MarcusW.VncClient.Avalonia.Adapters.Logging
Expand Down
30 changes: 30 additions & 0 deletions src/MarcusW.VncClient.Avalonia/Clipboard.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input.Platform;
using Avalonia.VisualTree;

namespace MarcusW.VncClient.Avalonia;

public static class Clipboard
{
public static IClipboard Get()
{
//Desktop
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: { } window })
{
return window.Clipboard!;
}
//Android (and iOS?)
else if (Application.Current?.ApplicationLifetime is ISingleViewApplicationLifetime { MainView: { } mainView })
{
var visualRoot = mainView.GetVisualRoot();
if (visualRoot is TopLevel topLevel)
{
return topLevel.Clipboard!;
}
}

return null!;
}
}
26 changes: 12 additions & 14 deletions src/MarcusW.VncClient.Avalonia/Conversions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.ComponentModel;
using Avalonia;

Expand Down Expand Up @@ -28,20 +29,17 @@ public static class Conversions
/// <param name="avaloniaPixelFormat">Value to convert.</param>
/// <returns>The conversion result.</returns>
public static PixelFormat GetPixelFormat(global::Avalonia.Platform.PixelFormat avaloniaPixelFormat)
=> avaloniaPixelFormat switch {
// TODO: Actually, the Avalonia PixelFormat is generic and doesn't always refer to Skia. But as long as the pixel representation is identical with Direct2D and others, they can just be renamed.

// Packed format, component order refers to order in native type (BE): 0xRGB
global::Avalonia.Platform.PixelFormat.Rgb565 => new PixelFormat("Skia kRGB_565_SkColorType", 16, 16, false, true, false, 31, 63, 31, 0, 11, 5, 0, 0),

// Array format, component order refers to order in memory (LE): ...RGBA... => 0xABGR
global::Avalonia.Platform.PixelFormat.Rgba8888 => new PixelFormat("Skia kRGBA_8888_SkColorType", 32, 32, false, true, true, 0xFF, 0xFF, 0xFF, 0xFF, 0, 8, 16, 24),

// Array format, component order refers to order in memory (LE): ...BGRA... => 0xARGB
global::Avalonia.Platform.PixelFormat.Bgra8888 => new PixelFormat("Skia kBGRA_8888_SkColorType", 32, 32, false, true, true, 0xFF, 0xFF, 0xFF, 0xFF, 16, 8, 0, 24),

_ => throw new InvalidEnumArgumentException(nameof(avaloniaPixelFormat), (int)avaloniaPixelFormat, typeof(global::Avalonia.Platform.PixelFormat))
};
{
// TODO: Actually, the Avalonia PixelFormat is generic and doesn't always refer to Skia. But as long as the pixel representation is identical with Direct2D and others, they can just be renamed.
if(avaloniaPixelFormat.Equals(global::Avalonia.Platform.PixelFormat.Rgb565))
return new PixelFormat("Skia kRGB_565_SkColorType", 16, 16, false, true, false, 31, 63, 31, 0, 11, 5, 0, 0);
else if(avaloniaPixelFormat.Equals(global::Avalonia.Platform.PixelFormat.Rgba8888))
return new PixelFormat("Skia kRGBA_8888_SkColorType", 32, 32, false, true, true, 0xFF, 0xFF, 0xFF, 0xFF, 0, 8, 16, 24);
else if(avaloniaPixelFormat.Equals(global::Avalonia.Platform.PixelFormat.Bgra8888))
return new PixelFormat("Skia kBGRA_8888_SkColorType", 32, 32, false, true, true, 0xFF, 0xFF, 0xFF, 0xFF, 16, 8, 0, 24);
else
throw new ArgumentException(avaloniaPixelFormat.ToString(), nameof(avaloniaPixelFormat));
}

/// <summary>
/// Converts a Avalonia <see cref="Point"/> to a <see cref="Position"/>.
Expand Down
14 changes: 11 additions & 3 deletions src/MarcusW.VncClient.Avalonia/MarcusW.VncClient.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" />
<PackageReference Include="Avalonia" Version="11.0.10" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/MarcusW.VncClient.Avalonia/RfbRenderTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override void Render(DrawingContext context)

// Has any bitmap been rendered yet?
if (!bitmapSize.HasValue)
return global::Avalonia.Size.Empty;
return default;

// Request the size of the current bitmap
return bitmapSize.Value;
Expand Down
2 changes: 1 addition & 1 deletion src/MarcusW.VncClient.Avalonia/VncView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public virtual void HandleServerClipboardUpdate(string text)
{
Dispatcher.UIThread.Post(async () => {
// Copy the text to the local clipboard
await Application.Current.Clipboard.SetTextAsync(text).ConfigureAwait(true);
await Clipboard.Get().SetTextAsync(text).ConfigureAwait(true);
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/MarcusW.VncClient/MarcusW.VncClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down