Skip to content

Commit

Permalink
Avalonia Update (#250)
Browse files Browse the repository at this point in the history
* update Avalonia to version 11.0.2 and resolve errors from breaking changes

* remove unnecessary initialization code

* update Avalonia dependencies
  • Loading branch information
floribe2000 authored Sep 3, 2023
1 parent c872a5d commit 9153b00
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 184 deletions.
2 changes: 0 additions & 2 deletions Tools/SquirrelBuildAndRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ dotnet build dirs.proj -c $buildConfig
Write-Output "Publishing build"
dotnet publish WoWsShipBuilder.Desktop -c $buildConfig -p:PublishProfile=PublishWindows
$publishDir = "WoWsShipBuilder.Desktop\bin\$buildConfig\publish"
Copy-Item -Path WoWsShipBuilder.Desktop\bin\$buildConfig\$frameworkVersion\runtimes\win7-x64\native\av_libGLESv2.dll -Destination $publishDir
Copy-Item -Path WoWsShipBuilder.Desktop\bin\$buildConfig\$frameworkVersion\Third-Party-Licenses.txt -Destination $publishDir

Write-Output "Creating Squirrel.Windows release"
$version = Get-Content -Path WoWsShipBuilder.Desktop\buildInfo.txt
Expand Down
1 change: 0 additions & 1 deletion WoWsShipBuilder.Common/WoWsShipBuilder.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Splat.Microsoft.Extensions.DependencyInjection" Version="14.6.8" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 3 additions & 3 deletions WoWsShipBuilder.Desktop/App.axaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:infrastructure="clr-namespace:WoWsShipBuilder.Desktop.Infrastructure"
x:Class="WoWsShipBuilder.Desktop.App">
x:Class="WoWsShipBuilder.Desktop.App"
RequestedThemeVariant="Dark">
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseDark.xaml"/>
<SimpleTheme />
<StyleInclude Source="/Common/Styles/ThemeOverride.axaml"/>
<StyleInclude Source="/Common/Styles/DefaultStyle.axaml"/>
</Application.Styles>
Expand Down
2 changes: 1 addition & 1 deletion WoWsShipBuilder.Desktop/Common/AppHeader.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="WoWsShipBuilder.Desktop.Infrastructure.AppHeader"
x:Class="WoWsShipBuilder.Desktop.Common.AppHeader"
Name="Header">
<DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Left" IsHitTestVisible="False" Spacing="5">
Expand Down
23 changes: 6 additions & 17 deletions WoWsShipBuilder.Desktop/Common/AppHeader.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Markup.Xaml;

namespace WoWsShipBuilder.Desktop.Infrastructure
namespace WoWsShipBuilder.Desktop.Common
{
public partial class AppHeader : UserControl
{
private Button minimizeButton;
private Button maximizeButton;
private Path maximizeIcon;
private Button closeButton;

public static readonly StyledProperty<bool> ShowTitleProperty =
AvaloniaProperty.Register<AppHeader, bool>(nameof(ShowTitle), true);

Expand All @@ -33,14 +27,9 @@ public AppHeader()
{
InitializeComponent();

minimizeButton = this.FindControl<Button>("MinimizeButton");
maximizeButton = this.FindControl<Button>("MaximizeButton");
maximizeIcon = this.FindControl<Path>("MaximizeIcon");
closeButton = this.FindControl<Button>("CloseButton");

minimizeButton.Click += MinimizeWindow;
maximizeButton.Click += MaximizeWindow;
closeButton.Click += CloseWindow;
MinimizeButton.Click += MinimizeWindow;
MaximizeButton.Click += MaximizeWindow;
CloseButton.Click += CloseWindow;

SubscribeToWindowState();
}
Expand Down Expand Up @@ -135,13 +124,13 @@ private async void SubscribeToWindowState()
{
if (s != WindowState.Maximized)
{
maximizeIcon.Data = Avalonia.Media.Geometry.Parse("M2048 2048v-2048h-2048v2048h2048zM1843 1843h-1638v-1638h1638v1638z");
MaximizeIcon.Data = Avalonia.Media.Geometry.Parse("M2048 2048v-2048h-2048v2048h2048zM1843 1843h-1638v-1638h1638v1638z");
hostWindow.Padding = new Thickness(0, 0, 0, 0);
}
if (s == WindowState.Maximized)
{
maximizeIcon.Data = Avalonia.Media.Geometry.Parse("M2048 1638h-410v410h-1638v-1638h410v-410h1638v1638zm-614-1024h-1229v1229h1229v-1229zm409-409h-1229v205h1024v1024h205v-1229z");
MaximizeIcon.Data = Avalonia.Media.Geometry.Parse("M2048 1638h-410v410h-1638v-1638h410v-410h1638v1638zm-614-1024h-1229v1229h1229v-1229zm409-409h-1229v205h1024v1024h205v-1229z");
// This should be a more universal approach in both cases, but I found it to be less reliable, when for example double-clicking the title bar.
hostWindow.Padding = new Thickness(
Expand Down
10 changes: 5 additions & 5 deletions WoWsShipBuilder.Desktop/Common/Styles/DefaultStyle.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
<Style Selector="Window">
<Setter Property="Icon" Value="/Assets/ShipBuilder_WindowIcon.ico" />
</Style>
<Style Selector="Button">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="15" />
</Style>
<!-- <Style Selector="Button"> -->
<!-- <Setter Property="HorizontalAlignment" Value="Center" /> -->
<!-- <Setter Property="VerticalAlignment" Value="Center" /> -->
<!-- <Setter Property="FontSize" Value="15" /> -->
<!-- </Style> -->
<Style Selector="ListBox">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,5 @@ public BlazorWindow()
Resources.Add("downloadPath", settings.CustomImagePath ?? dataService.CombinePaths(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), AppConstants.ShipBuilderName));

InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}

private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
5 changes: 3 additions & 2 deletions WoWsShipBuilder.Desktop/Features/MessageBox/MessageBox.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:infrastructure="clr-namespace:WoWsShipBuilder.Desktop.Infrastructure"
xmlns:common="clr-namespace:WoWsShipBuilder.Desktop.Common"
mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="150"
x:Class="WoWsShipBuilder.Desktop.Features.MessageBox.MessageBox"
WindowStartupLocation="CenterOwner"
ExtendClientAreaChromeHints="NoChrome">

<Grid RowDefinitions="30,*">
<infrastructure:AppHeader Name="Header" ShowMinimizeButton="False"/>
<common:AppHeader Name="Header" ShowMinimizeButton="False"/>
<Grid HorizontalAlignment="Center" RowDefinitions="Auto,*" ColumnDefinitions="Auto,*" Grid.Row="1" Margin="10">
<Image Name="Icon" Height="35" Width="35" Grid.Row="0" Grid.Column="0" Margin="0,0,20,0" />
<Image Name="IconImage" Height="35" Width="35" Grid.Row="0" Grid.Column="0" Margin="0,0,20,0" />
<TextBlock HorizontalAlignment="Center" Name="Text" Grid.Row="0" Grid.Column="1" TextWrapping="Wrap"/>
<StackPanel HorizontalAlignment="Right" Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" Name="Buttons">
<StackPanel.Styles>
Expand Down
17 changes: 8 additions & 9 deletions WoWsShipBuilder.Desktop/Features/MessageBox/MessageBox.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,36 @@ public static Task<MessageBoxResult> Show(Window? parent, string text, string ti
CanResize = false,
};

msgbox.FindControl<AppHeader>("Header").Title = title;
msgbox.Header.Title = title;

msgbox.Width = width;
msgbox.Height = height;

if (icon != MessageBoxIcon.None)
{
var iconControl = msgbox.FindControl<Image>("Icon");
var assets = AvaloniaLocator.Current.GetService<IAssetLoader>()!;
var iconControl = msgbox.IconImage;
Bitmap? bitmap = null;
switch (icon)
{
case MessageBoxIcon.Error:
bitmap = new Bitmap(assets.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Error.png")));
bitmap = new Bitmap(AssetLoader.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Error.png")));
break;
case MessageBoxIcon.Info:
bitmap = new Bitmap(assets.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Info.png")));
bitmap = new Bitmap(AssetLoader.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Info.png")));
break;
case MessageBoxIcon.Question:
bitmap = new Bitmap(assets.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Question.png")));
bitmap = new Bitmap(AssetLoader.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Question.png")));
break;
case MessageBoxIcon.Warning:
bitmap = new Bitmap(assets.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Warning.png")));
bitmap = new Bitmap(AssetLoader.Open(new Uri("avares://WoWsShipBuilder/Assets/Icons/Warning.png")));
break;
}

iconControl.Source = bitmap;
}

msgbox.FindControl<TextBlock>("Text").Text = text;
var buttonPanel = msgbox.FindControl<StackPanel>("Buttons");
msgbox.Text.Text = text;
var buttonPanel = msgbox.Buttons;

var res = MessageBoxResult.Ok;

Expand Down
19 changes: 9 additions & 10 deletions WoWsShipBuilder.Desktop/Features/Settings/SettingsComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@using System.IO.Abstractions
@using System.Net
@using System.IO
@using Avalonia.Platform.Storage

@implements IDisposable
@inject ILocalizer Localizer
Expand Down Expand Up @@ -325,23 +326,21 @@

private async Task OnImageFolderSelectClicked(MouseEventArgs obj)
{
var dialog = new OpenFolderDialog
{
Directory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures),
};

var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;
var path = await Dispatcher.UIThread.InvokeAsync(async () => await dialog.ShowAsync(mainWindow!));
var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow!;
var startLocation = await mainWindow.StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Pictures);
var selectionResult = await Dispatcher.UIThread.InvokeAsync(async () => await mainWindow.StorageProvider.OpenFolderPickerAsync(new() { SuggestedStartLocation = startLocation, AllowMultiple = false }));
var path = selectionResult.Single().TryGetLocalPath();
if (path is not null)
{
customBuildImagePath = path;
}
}

private async Task ExportSavedBuilds()
{
var dialog = new OpenFolderDialog();
var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow;
var path = await Dispatcher.UIThread.InvokeAsync(async () => await dialog.ShowAsync(mainWindow!));
var mainWindow = (Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime)?.MainWindow!;
var selectionResult = await Dispatcher.UIThread.InvokeAsync(async () => await mainWindow.StorageProvider.OpenFolderPickerAsync(new() { AllowMultiple = false }));
var path = selectionResult.Single().TryGetLocalPath();
if (path is not null)
{
var buildStrings = savedBuilds.Select(x => x.CreateShortStringFromBuild()).ToList();
Expand Down
89 changes: 42 additions & 47 deletions WoWsShipBuilder.Desktop/Features/SplashScreen/SplashScreen.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -13,62 +12,58 @@
using WoWsShipBuilder.Infrastructure.Localization.Resources;
using WoWsShipBuilder.Infrastructure.Utility;

namespace WoWsShipBuilder.Desktop.Features.SplashScreen
namespace WoWsShipBuilder.Desktop.Features.SplashScreen;

public partial class SplashScreen : ReactiveWindow<SplashScreenViewModel>
{
public class SplashScreen : ReactiveWindow<SplashScreenViewModel>
public SplashScreen(IServiceProvider services)
{
public SplashScreen(IServiceProvider services)
InitializeComponent(services.GetRequiredService<SplashScreenViewModel>());
this.WhenActivated(_ =>
{
InitializeComponent(services.GetRequiredService<SplashScreenViewModel>());
#if DEBUG
this.AttachDevTools();
#endif
this.WhenActivated(_ =>
{
var vm = ViewModel ?? services.GetRequiredService<SplashScreenViewModel>();
var vm = ViewModel ?? services.GetRequiredService<SplashScreenViewModel>();
Task.Run(async () =>
Task.Run(async () =>
{
var minimumRuntime = Task.Delay(1500);
try
{
var minimumRuntime = Task.Delay(1500);
try
{
await vm.VersionCheck(throwOnException: true);
}
catch (Exception e)
{
Logging.Logger.LogError(e, "Encountered unexpected error during data download");
await Dispatcher.UIThread.InvokeAsync(async () =>
await MessageBox.MessageBox.Show(
this,
Translation.DataUpdate_ErrorDescription,
Translation.DataUpdate_ErrorTitle,
MessageBox.MessageBox.MessageBoxButtons.Ok,
MessageBox.MessageBox.MessageBoxIcon.Error,
width: 500,
sizeToContent: SizeToContent.Height));
}
await vm.VersionCheck(throwOnException: true);
}
catch (Exception e)
{
Logging.Logger.LogError(e, "Encountered unexpected error during data download");
await Dispatcher.UIThread.InvokeAsync(async () =>
await MessageBox.MessageBox.Show(
this,
Translation.DataUpdate_ErrorDescription,
Translation.DataUpdate_ErrorTitle,
MessageBox.MessageBox.MessageBoxButtons.Ok,
MessageBox.MessageBox.MessageBoxIcon.Error,
width: 500,
sizeToContent: SizeToContent.Height));
}
await minimumRuntime;
await minimumRuntime;
await Dispatcher.UIThread.InvokeAsync(() =>
{
var blazorWindow = new BlazorWindow();
blazorWindow.Show();
await Dispatcher.UIThread.InvokeAsync(() =>
{
var blazorWindow = new BlazorWindow();
blazorWindow.Show();
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow.Close();
desktop.MainWindow = blazorWindow;
}
});
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow?.Close();
desktop.MainWindow = blazorWindow;
}
});
});
}
});
}

private void InitializeComponent(SplashScreenViewModel viewModel)
{
AvaloniaXamlLoader.Load(this);
ViewModel = viewModel;
}
private void InitializeComponent(SplashScreenViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
}
}
38 changes: 0 additions & 38 deletions WoWsShipBuilder.Desktop/Infrastructure/AppBuilderExtension.cs

This file was deleted.

Loading

0 comments on commit 9153b00

Please sign in to comment.