Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Port NuGetResolver.UI to AvaloniaUI #2512

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<Window
x:Class="Stride.NuGetResolver.SplashScreenWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Stride.NuGetResolver"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Stride.NuGetResolver.SplashScreenWindow"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
SystemDecorations="None"
Background="#1A1A1D"
Width="480"
Height="380"
ResizeMode="NoResize">
CanResize="False">

<Window.Resources>
<ResourceDictionary>
Expand All @@ -25,19 +24,16 @@
</DrawingImage>
</ResourceDictionary>
</Window.Resources>
<Window.CommandBindings>
<CommandBinding Command="ApplicationCommands.Close" Executed="CloseCommand"/>
</Window.CommandBindings>
<Grid>
<Button HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="#FFFFFF" Background="#1A1A1D" Command="{x:Static ApplicationCommands.Close}" Content="X" Padding="4" x:Name="CloseButton" Visibility="Hidden" />
<Button HorizontalAlignment="Right" VerticalAlignment="Top" Foreground="#FFFFFF" Background="#1A1A1D" Click="CloseCommand" Content="X" Padding="4" x:Name="CloseButton" IsVisible="False" />
<StackPanel Orientation="Vertical" Margin="10">
<Image x:Name="Logo"
HorizontalAlignment="Center" VerticalAlignment="Center"
Width="424" Source="{StaticResource StrideLogo}"
Margin="10"/>
<ProgressBar IsIndeterminate="True" Width="424" Margin="10" />
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FFFFFF" Margin="10" x:Name="Message">Restoring NuGet packages...</TextBlock>
<TextBox x:Name="Log" Width="424" Height="120" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#C0C0C0" Background="#1A1A1D" Margin="10" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
<TextBox x:Name="Log" Width="424" Height="120" IsReadOnly="True" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#C0C0C0" Background="#1A1A1D" Margin="10" AcceptsReturn="True" />
</StackPanel>
</Grid>
</Window>
64 changes: 64 additions & 0 deletions sources/shared/Stride.NuGetResolver.UI/SplashScreenWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Reflection.Emit;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Themes.Fluent;
using Avalonia.Threading;
using NuGet.Common;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace Stride.NuGetResolver
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class SplashScreenWindow : Window
{
private int lineCounter;

public SplashScreenWindow()
{
this.InitializeComponent();
}

public void AppendMessage(LogLevel level, string message)
{
if (level == LogLevel.Error)
{
CloseButton.IsVisible = true;
Message.Text = "Error restoring NuGet packages!";
Message.Foreground = new SolidColorBrush(Colors.Red);
}
Log.Text += ($"[{level}] {message}{Environment.NewLine}");
Log.ScrollToLine(++lineCounter);
}

public void CloseCommand(object sender, RoutedEventArgs e)
{
this.Close();
}

public void SetupLog(LogLevel level, string message)
{
Dispatcher.UIThread.InvokeAsync(() => AppendMessage(level, message));
}

public void CloseApp()
{
Dispatcher.UIThread.InvokeAsync(() => Close());
}
}

public class NugetResolverApp
{
public static void Run(AppBuilder.AppMainDelegate AppMain)
{
AppBuilder.Configure<Application>()
.UsePlatformDetect()
.Start(AppMain, []);
}
}
}
42 changes: 0 additions & 42 deletions sources/shared/Stride.NuGetResolver.UI/SplashScreenWindow.xaml.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<StrideBuildTags>WindowsTools</StrideBuildTags>
<UseWPF>true</UseWPF>
<DefineConstants>STRIDE_NUGET_RESOLVER_UI;$(DefineConstants)</DefineConstants>
</PropertyGroup>

Expand All @@ -19,6 +18,9 @@
<PackageReference Include="NuGet.PackageManagement" />
<PackageReference Include="NuGet.Resolver" />
<PackageReference Include="NuGet.Commands" />
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Themes.Fluent" />
</ItemGroup>

</Project>
35 changes: 17 additions & 18 deletions sources/shared/Stride.NuGetResolver/NuGetAssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
using NuGet.Frameworks;
using NuGet.Versioning;

#if STRIDE_NUGET_RESOLVER_UI
using Avalonia.Controls;
#endif

namespace Stride.Core.Assets
{
public class NuGetAssemblyResolver
Expand Down Expand Up @@ -78,29 +82,24 @@ public static void SetupNuGet(string targetFramework, string packageName, string
Thread.Sleep(500);
if (!dialogNotNeeded.Task.IsCompleted)
{
var splashScreen = new Stride.NuGetResolver.SplashScreenWindow();
splashScreen.Show();

// Register log
logger.SetupLogAction((level, message) =>
Stride.NuGetResolver.NugetResolverApp.Run((app, args) =>
{
splashScreen.Dispatcher.InvokeAsync(() =>
app.Styles.Add(new Avalonia.Themes.Fluent.FluentTheme());
var splashScreen = new Stride.NuGetResolver.SplashScreenWindow();
splashScreen.Show();
// Register log
logger.SetupLogAction((level, message) =>
{
splashScreen.AppendMessage(level, message);
splashScreen.SetupLog(level, message);
});
});

dialogNotNeeded.Task.ContinueWith(t =>
{
splashScreen.Dispatcher.Invoke(() => splashScreen.Close());
});

splashScreen.Closed += (sender2, e2) =>
splashScreen.Dispatcher.InvokeShutdown();

System.Windows.Threading.Dispatcher.Run();
dialogNotNeeded.Task.ContinueWith(t =>
{
splashScreen.CloseApp();
});

splashScreen.Close();
app.Run(splashScreen);
});
}
dialogClosed.SetResult(true);
});
Expand Down