Skip to content

Commit

Permalink
Upgrade to .NET 8 and Avalonia 11.0.7
Browse files Browse the repository at this point in the history
This is not yet a complete upgrade, as some features have been momentarily removed, such as the map theming and the inertial scrolling. Also, analysis corrections have been applied where applicable. Bugs have not been fixed as well as many other idiosyncrasies. The Mac and Web workloads have not been looked at.
  • Loading branch information
Vrabbers committed Jan 30, 2024
1 parent 22d3247 commit 36e9a31
Show file tree
Hide file tree
Showing 46 changed files with 186 additions and 203 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion BnbnavNetClient.I18Next/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Avalonia;
using BnbnavNetClient.I18Next.Services;
using Splat;

namespace BnbnavNetClient.I18Next;
public static class AppBuilderExtensions
{
public static AppBuilder UseI18NextLocalization(this AppBuilder appBuilder)
{

This comment has been minimized.

Copy link
@Vrabbers

Vrabbers Jan 30, 2024

Author Owner

Don't have this as an extension method. This applies to usesettingsmanagers

appBuilder.With<IAvaloniaI18Next>(new AvaloniaI18Next());
Locator.CurrentMutable.RegisterConstant<IAvaloniaI18Next>(new AvaloniaI18Next());
return appBuilder;
}
}
3 changes: 2 additions & 1 deletion BnbnavNetClient.I18Next/BnbnavNetClient.I18Next.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="I18Next.Net" Version="1.0.0" />
<PackageReference Include="Sepia.Globalization" Version="0.8.0" />
<PackageReference Include="Splat" Version="14.8.12" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions BnbnavNetClient.I18Next/Services/IAvaloniaI18Next.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Reflection;

namespace BnbnavNetClient.I18Next.Services;


//consider using singleton class since this is only ever used as the instance
public interface IAvaloniaI18Next
{
string this[string key, Dictionary<string, object?>? arguments] { get; }
Expand Down
3 changes: 2 additions & 1 deletion BnbnavNetClient.I18Next/TrString.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia;
using BnbnavNetClient.I18Next.Services;
using Splat;

namespace BnbnavNetClient.I18Next;
public sealed class TrString : AvaloniaObject
Expand Down Expand Up @@ -36,7 +37,7 @@ public IEnumerable<TrArgument> Arguments

public TrString()
{
_tr = AvaloniaLocator.Current.GetRequiredService<IAvaloniaI18Next>();
_tr = Locator.Current.GetService<IAvaloniaI18Next>() ?? throw new InvalidOperationException("AvaloniaI18Next must be registered for TrString to be constructed");
}

public override string ToString()
Expand Down
3 changes: 2 additions & 1 deletion BnbnavNetClient.I18Next/TranslateExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia;
using Avalonia.Markup.Xaml;
using BnbnavNetClient.I18Next.Services;
using Splat;

namespace BnbnavNetClient.I18Next;

Expand All @@ -11,6 +12,6 @@ public sealed class Tr : MarkupExtension

public override object ProvideValue(IServiceProvider serviceProvider)

This comment has been minimized.

Copy link
@Vrabbers

Vrabbers Jan 30, 2024

Author Owner

There's probably something nicer that can be done here, considering that serviceProvider argument

{
return AvaloniaLocator.Current.GetRequiredService<IAvaloniaI18Next>()[Key];
return Locator.Current.GetService<IAvaloniaI18Next>()![Key];
}
}
2 changes: 1 addition & 1 deletion BnbnavNetClient.Linux/BnbnavNetClient.Linux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

Expand Down
3 changes: 2 additions & 1 deletion BnbnavNetClient.Linux/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BnbnavNetClient.Linux.TextToSpeech;
using BnbnavNetClient.Services.TextToSpeech;
using BnbnavNetClient.Settings;
using Splat;

namespace BnbnavNetClient.Linux;

Expand All @@ -15,6 +16,7 @@ internal class Program
public static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
Locator.CurrentMutable.RegisterConstant<ITextToSpeechProvider>(new SpdTextToSpeechProvider());
}

static AppBuilder BuildAvaloniaApp()
Expand All @@ -27,7 +29,6 @@ static AppBuilder BuildAvaloniaApp()
.LogToTrace()
.UseReactiveUI()
.UseI18NextLocalization()
.With<ITextToSpeechProvider>(new SpdTextToSpeechProvider())
.UseSettings(new SettingsManagerJsonFile());
}
}
2 changes: 1 addition & 1 deletion BnbnavNetClient.Mac/BnbnavNetClient.Mac.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0-macos10.14</TargetFramework>
<TargetFramework>net8.0-macos10.14</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion BnbnavNetClient.Web/BnbnavNetClient.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<InvariantGlobalization>false</InvariantGlobalization>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<WasmMainJSPath>AppBundle\main.js</WasmMainJSPath>
Expand Down
2 changes: 1 addition & 1 deletion BnbnavNetClient.Windows/BnbnavNetClient.Windows.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>net7.0-windows</TargetFramework>
<TargetFramework>net8.0-windows</TargetFramework>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup>

Expand Down
9 changes: 6 additions & 3 deletions BnbnavNetClient.Windows/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using BnbnavNetClient.I18Next;
using BnbnavNetClient.Services.TextToSpeech;
using BnbnavNetClient.Settings;
using Splat;

namespace BnbnavNetClient.Windows;

Expand All @@ -14,8 +15,11 @@ class Program
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
public static void Main(string[] args)
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
Locator.CurrentMutable.RegisterConstant<ITextToSpeechProvider>(new WindowsTextToSpeechProvider());
}

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
Expand All @@ -24,6 +28,5 @@ public static AppBuilder BuildAvaloniaApp()
.LogToTrace()
.UseReactiveUI()
.UseI18NextLocalization()
.With<ITextToSpeechProvider>(new WindowsTextToSpeechProvider())
.UseSettings(new SettingsManagerJsonFile());
}
6 changes: 4 additions & 2 deletions BnbnavNetClient/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<local:MapThemeResources Theme="Day"/>

<ResourceInclude Source="/Resources/DayTheme.axaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand All @@ -31,6 +30,9 @@
<Setter Property="MinWidth" Value="0"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
</Style>
<Style Selector=":is(Button).accent">
<Setter Property="FontWeight" Value="Bold"/>
</Style>
<Style Selector="ComboBox">
<Setter Property="Margin" Value="2"/>
</Style>
Expand Down
11 changes: 7 additions & 4 deletions BnbnavNetClient/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using BnbnavNetClient.Views;
using System;
using System.Globalization;
using BnbnavNetClient.Extensions;
using BnbnavNetClient.Services.TextToSpeech;
using Splat;

namespace BnbnavNetClient;

Expand All @@ -16,16 +18,17 @@ public class App : Application
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
var settings = AvaloniaLocator.Current.GetRequiredService<ISettingsManager>();
var settings = Locator.Current.GetSettingsManager();
settings.LoadAsync().Wait();

var pseudo = Environment.GetEnvironmentVariable("PSEUDOLOCALIZATION") == "true";
var i18N = AvaloniaLocator.Current.GetRequiredService<IAvaloniaI18Next>();
var i18N = Locator.Current.GetI18Next();
i18N.Initialize("BnbnavNetClient.locales", pseudo);
i18N.CurrentLanguage = new CultureInfo(settings.Settings.Language);

var tts = AvaloniaLocator.Current.GetRequiredService<ITextToSpeechProvider>();
tts.CurrentCulture = CultureInfo.CurrentUICulture;
var tts = Locator.Current.GetService<ITextToSpeechProvider>();
if (tts is not null)
tts.CurrentCulture = CultureInfo.CurrentUICulture;
}

public override void OnFrameworkInitializationCompleted()
Expand Down
8 changes: 5 additions & 3 deletions BnbnavNetClient/BnbnavNetClient.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ImplicitUsings>true</ImplicitUsings>
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand All @@ -18,14 +20,14 @@

<ItemGroup>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Svg.Skia" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.0.0.13" />
<PackageReference Include="Avalonia.Themes.Simple" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)" />

<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="ReactiveUI.Fody" Version="18.4.1" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
<PackageReference Include="System.Speech" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion BnbnavNetClient/Controls/InstructionImageControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public override void Render(DrawingContext context)
CalculatedRoute.Instruction.InstructionTypes.Merge => "merge",
CalculatedRoute.Instruction.InstructionTypes.EnterRoundabout => "enter-roundabout",
CalculatedRoute.Instruction.InstructionTypes.LeaveRoundabout => "leave-roundabout",
_ => throw new ArgumentOutOfRangeException()
_ => throw new InvalidOperationException(nameof(_instruction) + " was out of range")
};

context.DrawSvgUrl($"avares://BnbnavNetClient/Assets/Instructions/{instructionFile}.svg", bounds);
Expand Down
14 changes: 14 additions & 0 deletions BnbnavNetClient/Extensions/SplatExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using BnbnavNetClient.I18Next.Services;
using BnbnavNetClient.Settings;
using Splat;

namespace BnbnavNetClient.Extensions;

public static class SplatExtensions
{
public static IAvaloniaI18Next GetI18Next(this IReadonlyDependencyResolver me) =>
me.GetService<IAvaloniaI18Next>() ?? throw new InvalidOperationException("Avalonia I18Next must be registered");

public static ISettingsManager GetSettingsManager(this IReadonlyDependencyResolver me) =>
me.GetService<ISettingsManager>() ?? throw new InvalidOperationException("Settings manager must be registered");
}
5 changes: 2 additions & 3 deletions BnbnavNetClient/Helpers/DrawingContextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ public static void DrawSvgUrl(this DrawingContext context, string? url, Rect rec
}
else
{
var assetLoader = AvaloniaLocator.Current.GetService<IAssetLoader>()!;
var uri = new Uri(url);
if (assetLoader.Exists(uri))
if (AssetLoader.Exists(uri))
{
var asset = assetLoader.Open(uri);
var asset = AssetLoader.Open(uri);

svg = new SKSvg();
svg.Load(asset);
Expand Down
69 changes: 0 additions & 69 deletions BnbnavNetClient/MapThemeResources.cs

This file was deleted.

Loading

0 comments on commit 36e9a31

Please sign in to comment.