Skip to content

Commit

Permalink
Update Avalonia, reactivate trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Jul 15, 2022
1 parent 0904f02 commit ed9a3c7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 37 deletions.
4 changes: 2 additions & 2 deletions BTCPayServer.Vault.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29411.108
# Visual Studio Version 17
VisualStudioVersion = 17.1.32414.318
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BTCPayServer.Vault", "BTCPayServer.Vault\BTCPayServer.Vault.csproj", "{E54675AA-679D-440B-B82C-52FC2E119C34}"
EndProject
Expand Down
7 changes: 4 additions & 3 deletions BTCPayServer.Vault/BTCPayServer.Vault.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Avalonia" Version="0.9.12" />
<PackageReference Include="AvalonStudio.Shell" Version="0.9.9" />
<PackageReference Include="Avalonia" Version="0.10.16" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="NicolasDorier.RateLimits" Version="1.1.0" />
</ItemGroup>
Expand Down Expand Up @@ -54,7 +54,8 @@
</ItemGroup>

<PropertyGroup Condition="'$(GithubDistrib)' == 'true'">
<PublishTrimmed>false</PublishTrimmed>
<PublishTrimmed>true</PublishTrimmed>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<SelfContained>true</SelfContained>
</PropertyGroup>
</Project>
2 changes: 0 additions & 2 deletions BTCPayServer.Vault/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
using Avalonia.Platform;
using Avalonia.Rendering;
using Avalonia.Threading;
using AvalonStudio.Shell;
using AvalonStudio.Shell.Extensibility.Platforms;
using Microsoft.Extensions.DependencyInjection;
using Avalonia.Controls.Platform;
using System.Reflection;
Expand Down
3 changes: 2 additions & 1 deletion BTCPayServer.Vault/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
SizeToContent="Manual"
SizeToContent="Height"
CanResize="false"
Width="622"
Height="433"
Icon="avares://BTCPayServer.Vault/Assets/BTCPayServerVault-256x256.png"
Expand Down
31 changes: 4 additions & 27 deletions BTCPayServer.Vault/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,14 @@ namespace BTCPayServer.Vault
{
public class MainWindow : Window
{
static Size NormalSize = new Size(622, 220);
static Size ExpandedSize = new Size(622, 433);
/// <summary>
/// Workaround https://github.com/AvaloniaUI/Avalonia/issues/3290 and https://github.com/AvaloniaUI/Avalonia/issues/3291
/// Because our app can only have two size we just resize based on the state of IsVisible of the MainViewModel
/// </summary>
void ResizeHack()
{
Size newSize = MainViewModel.IsVisible ? ExpandedSize : NormalSize;

if (newSize != this.ClientSize)
{
this.ClientSize = newSize;
// On Mac, resizing down will make the windows jump down, so we need to set it back up
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && newSize == NormalSize)
{
this.Position = this.Position.WithY(this.Position.Y - (int)(ExpandedSize.Height - NormalSize.Height));
}
}
}

public MainWindow()
{
InitializeComponent();
Title = Extensions.GetTitle();
}

DispatcherTimer _ResizeHackTimer;
private DispatcherTimer _BlinkTimer;
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
Expand All @@ -56,14 +36,12 @@ private void InitializeComponent()
Indicator.StoppedRunning += OnStoppedRunning;
DataContext = ServiceProvider.GetRequiredService<MainWindowViewModel>();
MainViewModel.PropertyChanged += MainViewModel_PropertyChanged;
_ResizeHackTimer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, (_, __) =>
_BlinkTimer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, (_, __) =>
{
ResizeHack();
if (MainViewModel.IsVisible && this.WindowState == WindowState.Minimized)
this.Blink();
});
_ResizeHackTimer.Start();
this.ResizeHack();
_BlinkTimer.Start();
}
}
private void MainViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
Expand All @@ -72,7 +50,6 @@ private void MainViewModel_PropertyChanged(object sender, PropertyChangedEventAr
{
Context.Post(_ =>
{
this.ResizeHack();
this.ActivateHack();
}, null);
}
Expand All @@ -86,7 +63,7 @@ protected override void OnClosing(CancelEventArgs e)
Indicator.Running -= OnRunning;
Indicator.StoppedRunning -= OnStoppedRunning;
MainViewModel.PropertyChanged -= MainViewModel_PropertyChanged;
_ResizeHackTimer.Stop();
_BlinkTimer.Stop();
}
}

Expand Down
3 changes: 1 addition & 2 deletions BTCPayServer.Vault/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.AspNetCore.Hosting.Server;
using System.IO;
using Avalonia;
using Avalonia.Logging.Serilog;
using Microsoft.AspNetCore.Connections;
using System.Net.Sockets;
using System.Threading;
Expand Down Expand Up @@ -73,6 +72,6 @@ private static bool TestPortFree()
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToDebug();
.LogToTrace();
}
}

0 comments on commit ed9a3c7

Please sign in to comment.