Skip to content

Commit

Permalink
Merge pull request #73 from jmacato/upgrade-to-avalonia-v11
Browse files Browse the repository at this point in the history
Upgrade to avalonia v11
  • Loading branch information
NicolasDorier authored Dec 7, 2023
2 parents ee87008 + 90c3615 commit ac67bb4
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 71 deletions.
8 changes: 4 additions & 4 deletions BTCPayServer.Hwi/BTCPayServer.Hwi.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="Version.csproj" Condition="Exists('Version.csproj')" />
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<Company>BTCPay Server</Company>
<Copyright>Copyright © BTCPay Server</Copyright>
<Description>A wrapper library around the hwi bitcoin-core project</Description>
Expand All @@ -10,19 +10,19 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/btcpayserver/BTCPayServer.Vault</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<LangVersion>8.0</LangVersion>
<LangVersion>12</LangVersion>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="NBitcoin" Version="6.0.8" />
<PackageReference Include="NBitcoin" Version="7.0.31" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions BTCPayServer.Vault.Tests/BTCPayServer.Vault.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0-preview-20200116-01" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
13 changes: 0 additions & 13 deletions BTCPayServer.Vault.Tests/HwiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ public async Task CanGetXPub()
await tester.Device.GetXPubAsync(new KeyPath("44'/0'/0'/0/0"));
}


[Fact]
[Trait("Device", "Device")]
public async Task CanSignMessage()
{
var tester = await CreateTester();
var accountPath = tester.GetKeyPath(ScriptPubKeyType.Legacy);
var addrPath = accountPath.Derive(new KeyPath("0/0"));
var signature = await tester.Device.SignMessageAsync("I am satoshi", addrPath);
var xpub = await tester.Device.GetXPubAsync(addrPath);
Assert.True(xpub.GetPublicKey().VerifyMessage("I am satoshi", signature));
}

[Fact]
[Trait("Device", "Device")]
public async Task CanDisplayAddress()
Expand Down
3 changes: 1 addition & 2 deletions BTCPayServer.Vault/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="BTCPayServer.Vault.App">
<Application.Styles>
<StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>
<SimpleTheme />
<StyleInclude Source="avares://BTCPayServer.Vault/Styles.xaml" />
</Application.Styles>
</Application>
9 changes: 4 additions & 5 deletions BTCPayServer.Vault/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public App()
{

}
public IServiceProvider ServiceProvider { get; private set; }

public IHostApplicationLifetime HostApplicationLifetime { get; private set; }
public IHost Host { get; private set; }
public IClassicDesktopStyleApplicationLifetime Desktop { get; private set; }
Expand All @@ -30,15 +30,14 @@ public override void Initialize()
}
public override void OnFrameworkInitializationCompleted()
{
ServiceProvider = AvaloniaLocator.CurrentMutable.GetService<IServiceProvider>();
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Desktop = desktop;
Desktop.MainWindow = ServiceProvider.GetRequiredService<MainWindow>();
Desktop.MainWindow = Program.CurrentServiceProvider.GetRequiredService<MainWindow>();
Desktop.Exit += Desktop_Exit;
Desktop.Startup += Desktop_Startup;
HostApplicationLifetime = ServiceProvider.GetRequiredService<IHostApplicationLifetime>();
Host = ServiceProvider.GetRequiredService<IHost>();
HostApplicationLifetime = Program.CurrentServiceProvider.GetRequiredService<IHostApplicationLifetime>();
Host = Program.CurrentServiceProvider.GetRequiredService<IHost>();
}
base.OnFrameworkInitializationCompleted();
}
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Vault/AvaloniaHackExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void ActivateHack(this Window window)
if (ReferenceEquals(platformImpl, null))
return;

var platformHandle = platformImpl.Handle;
var platformHandle = window.TryGetPlatformHandle();
if (ReferenceEquals(platformHandle, null))
return;

Expand All @@ -65,7 +65,7 @@ public static void Blink(this Window window)
if (ReferenceEquals(platformImpl, null))
return;

var platformHandle = platformImpl.Handle;
var platformHandle = window.TryGetPlatformHandle();
if (ReferenceEquals(platformHandle, null))
return;
var handle = platformHandle.Handle;
Expand Down
14 changes: 8 additions & 6 deletions BTCPayServer.Vault/BTCPayServer.Vault.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType Condition=" '$(Configuration)' == 'Release' ">WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12</LangVersion>
<Company>The BTCPayServer Team</Company>
<Title>BTCPayServer Vault</Title>
<AssemblyTitle>$(Title)</AssemblyTitle>
Expand All @@ -16,14 +17,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="0.10.16" />
<PackageReference Include="BTCPayServer.NTag424.PCSC" Version="1.0.11" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Avalonia.Desktop" Version="11.0.6" />
<PackageReference Include="Avalonia.Themes.Simple" Version="11.0.6" />
<PackageReference Include="BTCPayServer.NTag424.PCSC" Version="1.0.15" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.16" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Avalonia" Version="11.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="NicolasDorier.RateLimits" Version="1.1.0" />
</ItemGroup>

Expand Down
16 changes: 3 additions & 13 deletions BTCPayServer.Vault/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,12 @@ public static class Extensions
result.UsePlatformDetect();
}

// TODO remove this overriding of RenderTimer when Avalonia 0.9 is released.
// fixes "Thread Leak" issue in 0.8.1 Avalonia.
var old = result.WindowingSubsystemInitializer;

result.UseWindowingSubsystem(() =>
{
old();

AvaloniaLocator.CurrentMutable.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60));
});
var title = GetTitle();

result = result
.With(new Win32PlatformOptions { AllowEglInitialization = true, UseDeferredRendering = true })
.With(new X11PlatformOptions { UseGpu = useGpuLinux, WmClass = title })
.With(new AvaloniaNativePlatformOptions { UseDeferredRendering = true, UseGpu = true })
.With(new Win32PlatformOptions())
.With(new X11PlatformOptions { WmClass = title })
.With(new AvaloniaNativePlatformOptions())
.With(new MacOSPlatformOptions { ShowInDock = true });
services.AddSingleton(result);
services.AddSingleton<MainWindow>();
Expand Down
4 changes: 2 additions & 2 deletions BTCPayServer.Vault/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
<DockPanel>
<TextBlock DockPanel.Dock="Left" FontSize="18">The vault is now ready to be used by web applications</TextBlock>
<StackPanel DockPanel.Dock="Right" IsVisible="{Binding IsLoading}" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
<DrawingPresenter Drawing="{DynamicResource spinner}"></DrawingPresenter>
<Image Source="{DynamicResource spinner}"/>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding CurrentOperation}"></TextBlock>
</StackPanel>
</DockPanel>
<StackPanel IsVisible="{Binding IsVisible}" Margin="0,15,0,0">
<Separator HorizontalAlignment="Left" Height="3" Background="{DynamicResource btcpay-color-primary}" Width="128" Margin="0,0,0,15"></Separator>
<DockPanel>
<DrawingPresenter DockPanel.Dock="Left" Height="128" Width="128" VerticalAlignment="Center" HorizontalAlignment="Center" Drawing="{DynamicResource warning}" />
<Image DockPanel.Dock="Left" Height="128" Width="128" VerticalAlignment="Center" HorizontalAlignment="Center" Source="{DynamicResource warning}" />
<StackPanel IsVisible="{Binding HWIVisible}" Margin="10,0,0,0" VerticalAlignment="Center">
<TextBlock>A website is requesting access to your hardware wallets.</TextBlock>
<TextBlock>If you accept, the website will be able to:</TextBlock>
Expand Down
5 changes: 2 additions & 3 deletions BTCPayServer.Vault/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public MainWindow()
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
Context = AvaloniaSynchronizationContext.Current as AvaloniaSynchronizationContext;
if (AvaloniaLocator.CurrentMutable?.GetService<IServiceProvider>() is IServiceProvider serviceProvider)
if (Program.CurrentServiceProvider is { } serviceProvider)
{
ServiceProvider = serviceProvider;
Indicator = ServiceProvider.GetRequiredService<IRunningIndicator>();
Expand All @@ -55,7 +54,7 @@ private void MainViewModel_PropertyChanged(object sender, PropertyChangedEventAr
}
}

protected override void OnClosing(CancelEventArgs e)
protected override void OnClosing(WindowClosingEventArgs e)
{
base.OnClosing(e);
if (Indicator != null)
Expand Down
5 changes: 5 additions & 0 deletions BTCPayServer.Vault/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,17 @@ public static void Main(string[] args)
#endif
})
.Build();

CurrentServiceProvider = host.Services;

host.Services.GetRequiredService<AppBuilder>()
.With(host.Services)
.With(host)
.StartWithClassicDesktopLifetime(args);
}

public static IServiceProvider CurrentServiceProvider { get; private set; }

private static bool TestPortFree()
{
TcpListener listener = new TcpListener(IPAddress.Loopback, HttpTransport.LocalHwiDefaultPort);
Expand Down
16 changes: 8 additions & 8 deletions BTCPayServer.Vault/Styles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<Style>
<Style.Resources>
<SolidColorBrush x:Key="btcpay-color-primary">#329f80</SolidColorBrush>
<DrawingGroup x:Key="warning">
<DrawingGroup.Children>
<DrawingImage x:Key="warning">
<DrawingGroup>
<GeometryDrawing Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M7.7246,15.9219C1.6086,14.1719,0.6986,7.3389,1.0726,3.9709L1.1316,3.4369 7.9996,-9.99999999997669E-05 14.8686,3.4369 14.9276,3.9709C15.3016,7.3389,14.3916,14.1719,8.2756,15.9219L7.9996,15.9999z" />
<GeometryDrawing Brush="#FFFFCC00" Geometry="F1M9,9L7,9 7,4 9,4z M9,12L7,12 7,10 9,10z M13.951,4L8,1 2.049,4C2.049,4 1.058,13 8,15 14.942,13 13.951,4 13.951,4" />
<GeometryDrawing Brush="#FF000000" Geometry="F1M7,12L9,12 9,10 7,10z M7,4L9,4 9,9 7,9z" />
</DrawingGroup.Children>
</DrawingGroup>
<DrawingGroup x:Key="spinner">
<DrawingGroup.Children>
</DrawingGroup>
</DrawingImage>
<DrawingImage x:Key="spinner">
<DrawingGroup>
<GeometryDrawing Brush="#329f80">
<GeometryDrawing.Geometry>
<EllipseGeometry Rect="0 0 20 20"></EllipseGeometry>
Expand All @@ -23,8 +23,8 @@
<EllipseGeometry Rect="2.5 2.5 15 15"></EllipseGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingGroup>
</DrawingImage>
</Style.Resources>
</Style>
<Style Selector="TextBlock">
Expand Down
8 changes: 0 additions & 8 deletions Build/win-x64/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ RUN $EXPORT_VARIABLES && \
done && \
convert /tmp/BTCPayServerVault.ico.tmp/*.png /tmp/BTCPayServerVault.ico && \
executable="$PUBLISH_FOLDER/$EXECUTABLE.exe" && \
# Workaround https://github.com/dotnet/sdk/issues/3990
e_lfanew_loc=$(xxd -p -l1 -s $((16#3C)) "$executable") && \
e_lfanew_loc="$((16#$e_lfanew_loc))" && \
echo "e_lfanew=$(printf "%08x" 0x$e_lfanew_loc)" && \
subsystem_loc=$(($e_lfanew_loc + 92)) && \
echo "subsystem_loc location is 0x$(printf "%08x" $subsystem_loc)" && \
printf "%06x: 0200" $subsystem_loc | xxd -r - "$executable" && \
# End of workaround
wine /tmp/rcedit.exe "$executable" \
--set-icon "/tmp/BTCPayServerVault.ico" \
--set-version-string "LegalCopyright" "$LICENSE" \
Expand Down

0 comments on commit ac67bb4

Please sign in to comment.