Skip to content

Commit

Permalink
Upgrade to Avalonia 11 (#110)
Browse files Browse the repository at this point in the history
Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
  • Loading branch information
Visne and PJB3005 committed Dec 13, 2023
1 parent b3bf735 commit e9cc769
Show file tree
Hide file tree
Showing 34 changed files with 87 additions and 103 deletions.
11 changes: 6 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<PackageVersion Include="Microsoft.Data.Sqlite" Version="7.0.4"/>
<PackageVersion Include="NSec.Cryptography" Version="22.4.0"/>
<PackageVersion Include="SharpZstd.Interop" Version="1.5.2-beta2"/>
<PackageVersion Include="JetBrains.Annotations" Version="2023.2.0-eap3" />
<!-- Loader -->
<PackageVersion Include="Robust.Natives" Version="0.1.1"/>
<!-- Launcher -->
<PackageVersion Include="Avalonia" Version="0.10.19"/>
<PackageVersion Include="Avalonia.Desktop" Version="0.10.19"/>
<PackageVersion Include="Avalonia.ReactiveUI" Version="0.10.19"/>
<PackageVersion Include="Avalonia.Diagnostics" Version="0.10.19"/>
<PackageVersion Include="Avalonia" Version="11.0.5"/>
<PackageVersion Include="Avalonia.Desktop" Version="11.0.5"/>
<PackageVersion Include="Avalonia.ReactiveUI" Version="11.0.5"/>
<PackageVersion Include="Avalonia.Diagnostics" Version="11.0.5"/>
<PackageVersion Include="Avalonia.Themes.Simple" Version="11.0.5"/>
<PackageVersion Include="CodeHollow.FeedReader" Version="1.2.6"/>
<PackageVersion Include="Dapper" Version="2.0.123"/>
<PackageVersion Include="DynamicData" Version="7.13.1"/>
Expand All @@ -24,7 +26,6 @@
<PackageVersion Include="Serilog" Version="2.12.0"/>
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0"/>
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0"/>
<PackageVersion Include="XamlNameReferenceGenerator" Version="1.6.1"/>
<PackageVersion Include="YamlDotNet" Version="13.0.2"/>
<PackageVersion Include="TerraFX.Interop.Windows" Version="10.0.22621.1"/>
<PackageVersion Include="Mono.Posix.NETStandard" Version="1.0.0"/>
Expand Down
3 changes: 1 addition & 2 deletions SS14.Launcher/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
</Application.DataTemplates>

<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseDark.xaml" />
<StyleInclude Source="avares://Avalonia.Themes.Simple/SimpleTheme.xaml" />
<StyleInclude Source="/Theme/Theme.xaml" />
<StyleInclude Source="/Theme/ThemeResources.xaml" />
<StyleInclude Source="/Theme/ThemeAngleBox.xaml" />
Expand Down
4 changes: 1 addition & 3 deletions SS14.Launcher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ public override void Initialize()

private void LoadBaseAssets()
{
var loader = AvaloniaLocator.Current.GetService<IAssetLoader>()!;

foreach (var (name, (path, type)) in AssetDefs)
{
using var dataStream = loader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}"));
using var dataStream = AssetLoader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}"));

var asset = LoadAsset(type, dataStream);

Expand Down
4 changes: 1 addition & 3 deletions SS14.Launcher/IconsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ private static readonly (string path, string resource)[] Icons =

public static void Load(App app)
{
var loader = AvaloniaLocator.Current.GetService<IAssetLoader>()!;

foreach (var (path, resource) in Icons)
{
using var file = loader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}"));
using var file = AssetLoader.Open(new Uri($"avares://SS14.Launcher/Assets/{path}"));
var bitmap = new Bitmap(file);
app.Resources.Add(resource, bitmap);
}
Expand Down
5 changes: 3 additions & 2 deletions SS14.Launcher/SS14.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<SubType>Designer</SubType>
</AvaloniaResource>

<AdditionalFiles Include="**\*.xaml" />
<AdditionalFiles Include="**\*.xaml" SourceItemGroup="AvaloniaXaml" />

<Compile Update="Views\MainWindowTabs\ServerFilterView.xaml.cs">
<DependentUpon>ServerFilterView.xaml</DependentUpon>
Expand All @@ -34,6 +34,7 @@
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.ReactiveUI" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" />
<PackageReference Include="Avalonia.Themes.Simple" />
<PackageReference Include="CodeHollow.FeedReader" />
<PackageReference Include="Dapper" />
<PackageReference Include="DynamicData" />
Expand All @@ -45,13 +46,13 @@
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.File" />
<PackageReference Include="XamlNameReferenceGenerator" />
<PackageReference Include="YamlDotNet" />
<PackageReference Include="TerraFX.Interop.Windows" />
<PackageReference Include="NSec.Cryptography" />
<PackageReference Include="Mono.Posix.NETStandard" />
<PackageReference Include="SharpZstd.Interop" />
<PackageReference Include="SpaceWizards.Sodium" />
<PackageReference Include="JetBrains.Annotations" />
</ItemGroup>
<ItemGroup>
<None Remove="Utility\runtime.json" />
Expand Down
10 changes: 5 additions & 5 deletions SS14.Launcher/Theme/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@
</Style>

<!-- TabItem -->
<Style Selector="TabItem:pointerover">
<Style Selector="TabItem:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeTabItemHoveredBrush}" />
</Style>
<Style Selector="TabItem:selected">
<Style Selector="TabItem:selected /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeTabItemSelectedBrush}" />
</Style>
<Style Selector="TabItem:selected:focus">
<Style Selector="TabItem:selected:focus /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeTabItemSelectedBrush}" />
</Style>
<Style Selector="TabItem:selected:pointerover">
<Style Selector="TabItem:selected:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeTabItemSelectedBrush}" />
</Style>
<Style Selector="TabItem:selected:focus:pointerover">
<Style Selector="TabItem:selected:focus:pointerover /template/ ContentPresenter">
<Setter Property="Background" Value="{DynamicResource ThemeTabItemSelectedBrush}" />
</Style>

Expand Down
3 changes: 1 addition & 2 deletions SS14.Launcher/Theme/ThemeDropDown.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
Name="PART_Popup"
PlacementTarget="{TemplateBinding}"
IsOpen="{TemplateBinding IsDropDownOpen,Mode=TwoWay}"
StaysOpen="False">
IsOpen="{TemplateBinding IsDropDownOpen,Mode=TwoWay}">
<ContentPresenter Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</Popup>
Expand Down
4 changes: 1 addition & 3 deletions SS14.Launcher/Theme/ThemeTabControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ Taken & modified from Avalonia's git repo.
Background="{DynamicResource ThemeStripeBackBrush}">
<ItemsPresenter
Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}" />
ItemsPanel="{TemplateBinding ItemsPanel}"/>
</Panel>
<Panel Name="PART_Edge" Background="{DynamicResource ThemeStripebackEdgeBrush}" />
<ContentPresenter
Expand Down
2 changes: 1 addition & 1 deletion SS14.Launcher/Theme/ThemeTabItem.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<Style Selector="TabItem">
<Style Selector="TabItem /template/ ContentPresenter">
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
</Style>
</Styles>
7 changes: 5 additions & 2 deletions SS14.Launcher/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ public class ViewLocator : IDataTemplate
{
public bool SupportsRecycling => false;

public IControl Build(object data)
public Control? Build(object? data)
{
if (data == null)
return null;

var name = data.GetType().FullName!.Replace("ViewModel", "View");
var type = Type.GetType(name);

Expand All @@ -27,7 +30,7 @@ public IControl Build(object data)
}
}

public bool Match(object data)
public bool Match(object? data)
{
return data is IViewModelBase;
}
Expand Down
12 changes: 9 additions & 3 deletions SS14.Launcher/ViewModels/AccountDropDownViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using JetBrains.Annotations;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Serilog;
using Splat;
using SS14.Launcher.Api;
using SS14.Launcher.Models.Data;
Expand Down Expand Up @@ -87,11 +88,16 @@ public async void LogoutPressed()
}

[UsedImplicitly]
public void AccountButtonPressed(LoggedInAccount account)
public void AccountButtonPressed(object account)
{
IsDropDownOpen = false;
if (account is not LoggedInAccount loggedInAccount)
{
Log.Warning($"Tried to switch account but parameter was not of type {nameof(LoggedInAccount)}");
return;
}

_mainVm.TrySwitchToAccount(account);
IsDropDownOpen = false;
_mainVm.TrySwitchToAccount(loggedInAccount);
}

public void AddAccountPressed()
Expand Down
4 changes: 4 additions & 0 deletions SS14.Launcher/ViewModels/ConnectingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class ConnectingViewModel : ViewModelBase
_connectorStatus == Connector.ConnectionStatus.ClientExited &&
_connector.ClientExitedBadly;

public static event Action? StartedConnecting;

public ConnectingViewModel(Connector connector, MainWindowViewModel windowVm, string? givenReason)
{
_updater = Locator.Current.GetRequiredService<Updater>();
Expand Down Expand Up @@ -186,6 +188,7 @@ public static void StartConnect(MainWindowViewModel windowVm, string address, st
var vm = new ConnectingViewModel(connector, windowVm, givenReason);
windowVm.ConnectingVM = vm;
vm.Start(address);
StartedConnecting?.Invoke();
}

public static void StartContentBundle(MainWindowViewModel windowVm, string fileName)
Expand All @@ -194,6 +197,7 @@ public static void StartContentBundle(MainWindowViewModel windowVm, string fileN
var vm = new ConnectingViewModel(connector, windowVm, null);
windowVm.ConnectingVM = vm;
vm.StartContentBundle(fileName);
StartedConnecting?.Invoke();
}

private void Start(string address)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using Avalonia.Input;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Messaging;
using SS14.Launcher.Models.Data;
Expand Down Expand Up @@ -50,7 +49,6 @@ public ServerEntryViewModel(

public void ConnectPressed()
{
FocusManager.Instance?.Focus(null);
ConnectingViewModel.StartConnect(_windowVm, Address);
}

Expand Down
2 changes: 1 addition & 1 deletion SS14.Launcher/Views/AccountDropDown.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<StackPanel Orientation="Vertical" IsVisible="{Binding AccountSwitchVisible}">
<TextBlock Text="{Binding AccountSwitchText}" Margin="4" />

<ItemsControl Name="Items" Items="{Binding Accounts}">
<ItemsControl Name="Items" ItemsSource="{Binding Accounts}">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="vm:AvailableAccountViewModel">
<Button Content="{Binding StatusText}" Margin="4"
Expand Down
9 changes: 1 addition & 8 deletions SS14.Launcher/Views/AddFavoriteDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Avalonia;
using Avalonia.Controls;
using ReactiveUI;

Expand All @@ -24,12 +23,6 @@ public AddFavoriteDialog()

this.WhenAnyValue(x => x._addressBox.Text)
.Subscribe(_ => UpdateSubmitValid());

#if DEBUG

this.AttachDevTools();

#endif
}

protected override void OnOpened(EventArgs e)
Expand All @@ -52,4 +45,4 @@ private void UpdateSubmitValid()
SubmitButton.IsEnabled = valid;
TxtInvalid.IsVisible = !validAddr;
}
}
}
6 changes: 5 additions & 1 deletion SS14.Launcher/Views/ConnectingOverlay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
Command="{Binding ErrorDismissed}" MinWidth="75" />

<DockPanel LastChildFill="False">
<Button DockPanel.Dock="Left" Content="Cancel" Command="{Binding Cancel}" IsVisible="{Binding !IsErrored}" />
<Button DockPanel.Dock="Left"
Name="CancelButton"
Content="Cancel"
Command="{Binding Cancel}"
IsVisible="{Binding !IsErrored}" />

<TextBlock DockPanel.Dock="Right" Margin="8 4 0 4" Text="{Binding ProgressText}"
TextWrapping="Wrap"
Expand Down
4 changes: 3 additions & 1 deletion SS14.Launcher/Views/ConnectingOverlay.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using SS14.Launcher.ViewModels;

namespace SS14.Launcher.Views;

Expand All @@ -8,5 +9,6 @@ public partial class ConnectingOverlay : UserControl
public ConnectingOverlay()
{
InitializeComponent();
ConnectingViewModel.StartedConnecting += () => Dispatcher.UIThread.Post(() => CancelButton.Focus());
}
}
12 changes: 6 additions & 6 deletions SS14.Launcher/Views/DropDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public sealed class DropDown : TemplatedControl
AvaloniaProperty.RegisterDirect<DropDown, bool>(nameof(IsDropDownOpen), down => down.IsDropDownOpen,
(down, b) => down.IsDropDownOpen = b);

public static readonly StyledProperty<object> ContentProperty =
public static readonly StyledProperty<object?> ContentProperty =
ContentControl.ContentProperty.AddOwner<DropDown>();

public static readonly StyledProperty<IDataTemplate> ContentTemplateProperty =
public static readonly StyledProperty<IDataTemplate?> ContentTemplateProperty =
ContentControl.ContentTemplateProperty.AddOwner<DropDown>();

public static readonly StyledProperty<object> HeaderContentProperty =
Expand All @@ -30,13 +30,13 @@ public sealed class DropDown : TemplatedControl
private Popup? _popup;

[Content]
public object Content
public object? Content
{
get => GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

public IDataTemplate ContentTemplate
public IDataTemplate? ContentTemplate
{
get => GetValue(ContentTemplateProperty);
set => SetValue(ContentTemplateProperty, value);
Expand Down Expand Up @@ -74,7 +74,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
{
if (!e.Handled)
{
if (e.Source != null && _popup?.IsInsidePopup((IVisual) e.Source) == false)
if (e.Source != null && _popup?.IsInsidePopup((Visual) e.Source) == false)
{
IsDropDownOpen ^= true;
e.Handled = true;
Expand All @@ -90,4 +90,4 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)

base.OnApplyTemplate(e);
}
}
}
4 changes: 2 additions & 2 deletions SS14.Launcher/Views/HubSettingsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ take precedence.
<ScrollViewer DockPanel.Dock="Top">
<StackPanel Spacing="2">
<TextBlock DockPanel.Dock="Left" Text="Default" Classes="NanoHeadingSmall" />
<ItemsControl Items="{Binding DefaultHubs}" Classes="Spaced">
<ItemsControl ItemsSource="{Binding DefaultHubs}" Classes="Spaced">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding}" IsEnabled="False" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBlock DockPanel.Dock="Left" Text="Custom" Classes="NanoHeadingSmall" />
<ItemsControl Items="{Binding HubList}" Name="Hubs" Classes="Spaced">
<ItemsControl ItemsSource="{Binding HubList}" Name="Hubs" Classes="Spaced">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DockPanel>
Expand Down
4 changes: 0 additions & 4 deletions SS14.Launcher/Views/HubSettingsDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public HubSettingsDialog()
{
InitializeComponent();

#if DEBUG
this.AttachDevTools();
#endif

_viewModel = (DataContext as HubSettingsViewModel)!; // Should have been set in XAML
_viewModel.HubList.CollectionChanged += (_, _) => Verify();
}
Expand Down
4 changes: 2 additions & 2 deletions SS14.Launcher/Views/Login/AuthErrorsOverlayView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<DockPanel>
<TextBlock HorizontalAlignment="Center" DockPanel.Dock="Top" Classes="NanoHeadingMedium" Text="{Binding Title}" />

<Button DockPanel.Dock="Bottom" Content="Ok" MinWidth="60" HorizontalAlignment="Center"
<Button Name="OkButton" DockPanel.Dock="Bottom" Content="Ok" MinWidth="60" HorizontalAlignment="Center"
Command="{Binding Ok}" />
<ItemsControl Items="{Binding Errors}" Margin="0, 20" HorizontalAlignment="Center" MaxWidth="400">
<ItemsControl ItemsSource="{Binding Errors}" Margin="0, 20" HorizontalAlignment="Center" MaxWidth="400">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="system:String">
<TextBlock Text="{Binding}" TextWrapping="Wrap" />
Expand Down
Loading

0 comments on commit e9cc769

Please sign in to comment.