Skip to content

Commit 0a955aa

Browse files
committed
perf: avalonia toast test
1 parent e4c2391 commit 0a955aa

26 files changed

+61
-68
lines changed

Hollow.Abstractions/Hollow.Abstractions.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<Platforms>AnyCPU</Platforms>
1010
</PropertyGroup>
1111
<ItemGroup>
12+
<PackageReference Include="Avalonia.Desktop" Version="11.1.2" />
1213
<PackageReference Include="System.Text.Json" Version="8.0.4" />
1314
</ItemGroup>
1415

Hollow.Windows/Hollow.Windows.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22+
<PackageReference Include="Avalonia.Desktop" Version="11.1.2" />
2223
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
2324
<PrivateAssets>all</PrivateAssets>
2425
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

Hollow/App.axaml.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using AsyncImageLoader.Loaders;
66
using Avalonia;
77
using Avalonia.Controls.ApplicationLifetimes;
8+
using Avalonia.Controls.Notifications;
89
using Avalonia.Markup.Xaml;
910
using Hollow.Abstractions.Models;
1011
using Hollow.Services.ConfigurationService;
@@ -16,6 +17,7 @@
1617
using Hollow.ViewModels;
1718
using Hollow.ViewModels.Pages;
1819
using Hollow.Views;
20+
using Hollow.Views.Controls;
1921
using Hollow.Views.Pages;
2022
using Microsoft.Extensions.DependencyInjection;
2123
using Serilog;
@@ -94,6 +96,8 @@ public override void OnFrameworkInitializationCompleted()
9496
{
9597
desktop.MainWindow = MainWindowInstance;
9698
}
99+
100+
HollowHost.NotificationManager = new WindowNotificationManager(MainWindowInstance) { MaxItems = 5, Position = NotificationPosition.BottomRight};
97101

98102
base.OnFrameworkInitializationCompleted();
99103
}

Hollow/Enums/NotificationType.cs

-9
This file was deleted.

Hollow/Helpers/BitmapOperations.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ namespace Hollow.Helpers;
66
public static class BitmapOperations
77
{
88
public static Bitmap Convert(Stream stream, int height)
9-
{
10-
var image = new Bitmap(stream);
11-
return Decode(image, height);
12-
}
9+
=> Decode(new Bitmap(stream), height);
1310

1411
public static Bitmap Decode(Bitmap bitmap, int height)
1512
{

Hollow/Helpers/Converters/BitmapValueConverter.cs

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace Hollow.Helpers.Converters;
77

88
public class BitmapValueConverter : IValueConverter
99
{
10-
public static BitmapValueConverter Instance = new();
11-
1210
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
1311
{
1412
if (value is string fileName && targetType == typeof(Bitmap))

Hollow/Helpers/Converters/RankTypeToBrushConverter.cs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ namespace Hollow.Helpers.Converters;
88

99
public class RankTypeToBrushConverter : IValueConverter
1010
{
11-
public static readonly RankTypeToBrushConverter Instance = new();
12-
1311
public object Convert(object? value, Type targetType, object? parameter,
1412
CultureInfo culture)
1513
{

Hollow/Helpers/Converters/RankTypeToFormattedConverter.cs

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace Hollow.Helpers.Converters;
77

88
public class RankTypeToFormattedConverter: IValueConverter
99
{
10-
public static readonly RankTypeToFormattedConverter Instance = new();
11-
1210
public object Convert(object? value, Type targetType, object? parameter,
1311
CultureInfo culture)
1412
{

Hollow/Helpers/DialogViewLocator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public class DialogViewLocator
1111

1212
internal static Control TryBuild(object? data)
1313
{
14-
if (data is string s) return new TextBlock() { Text = s };
14+
if (data is string s) return new TextBlock { Text = s };
1515
_locator ??= Application.Current?.DataTemplates.FirstOrDefault();
16-
return _locator?.Build(data) ?? new TextBlock() { Text = $"Unable to find suitable view for {data?.GetType().Name}" };
16+
return _locator?.Build(data) ?? new TextBlock { Text = $"Unable to find suitable view for {data?.GetType().Name}" };
1717
}
1818
}

Hollow/Helpers/PlatformHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static async Task<string> OpenFolderPickerForPath()
2121
private static long GetDirectorySize(string folderPath)
2222
{
2323
var directory = new DirectoryInfo(folderPath);
24-
return directory.EnumerateFiles("*", SearchOption.AllDirectories).Sum(fi => fi.Length);
24+
return directory.EnumerateFiles("*", SearchOption.AllDirectories).Sum(fileInfo => fileInfo.Length);
2525
}
2626

2727
private static double ConvertBytesToMegabytes(long bytes)

Hollow/Helpers/TimeZoneAdjuster.cs

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ public string ConvertToLocalTimeZone(string knownDateTime)
2222
public static class DateTimeDisplayExtensions
2323
{
2424
public static string ToUtcPrefixTimeZone(this int offsetHours)
25-
{
26-
return offsetHours >= 0 ? $"UTC+{offsetHours}" : $"UTC{offsetHours}";
27-
}
25+
=> offsetHours >= 0 ? $"UTC+{offsetHours}" : $"UTC{offsetHours}";
2826

2927
public static int ToTimeZoneFromUtcPrefix(this string utcPrefixTimeZone)
30-
{
31-
return int.Parse(utcPrefixTimeZone.Replace("UTC", "").Replace("+", ""));
32-
}
28+
=> int.Parse(utcPrefixTimeZone.Replace("UTC", "").Replace("+", ""));
3329
}

Hollow/Helpers/UigfSchemaValidator.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ namespace Hollow.Helpers;
55

66
public static class UigfSchemaValidator
77
{
8+
private static JsonSchema Schema { get; } = JsonSchema.FromText(SchemaJson);
9+
810
public static bool Validate(string json)
9-
{
10-
var jsonNode = JsonNode.Parse(json);
11-
var schema = JsonSchema.FromText(Schema);
12-
return schema.Evaluate(jsonNode).IsValid;
13-
}
11+
=> Schema.Evaluate(JsonNode.Parse(json)).IsValid;
1412

15-
private const string Schema =
13+
private const string SchemaJson =
1614
"""
1715
{
1816
"$schema": "https://json-schema.org/draft/2020-12/schema",

Hollow/Hollow.csproj

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
<ItemGroup>
2323
<PackageReference Include="Antelcat.I18N.Avalonia" Version="1.0.3" />
2424
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.2.1" />
25-
<PackageReference Include="Avalonia" Version="11.1.1" />
26-
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.1" />
27-
<PackageReference Include="Avalonia.Desktop" Version="11.1.1" />
28-
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.1" />
29-
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.1" />
25+
<PackageReference Include="Avalonia" Version="11.1.2" />
26+
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.2" />
27+
<PackageReference Include="Avalonia.Desktop" Version="11.1.2" />
28+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.2" />
29+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.2" />
3030
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0" />
3131
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
32-
<PackageReference Include="FluentIcons.Avalonia" Version="1.1.249" />
32+
<PackageReference Include="FluentIcons.Avalonia" Version="1.1.250" />
3333
<PackageReference Include="JsonSchema.Net" Version="7.1.2" />
3434
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
3535
<PackageReference Include="Serilog" Version="4.0.1" />

Hollow/ViewModels/MainWindowViewModel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
3+
using Avalonia.Controls.Notifications;
34
using Avalonia.Media.Imaging;
45
using Avalonia.Platform;
56
using CommunityToolkit.Mvvm.ComponentModel;

Hollow/ViewModels/Pages/GameSettingsViewModel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.InteropServices;
22
using System.Runtime.Versioning;
3+
using Avalonia.Controls.Notifications;
34
using CommunityToolkit.Mvvm.ComponentModel;
45
using CommunityToolkit.Mvvm.Input;
56
using Hollow.Abstractions.Models;

Hollow/ViewModels/Pages/HomeViewModel.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System.Collections.ObjectModel;
1+
using System;
2+
using System.Collections.ObjectModel;
23
using System.Net.Http;
34
using System.Threading.Tasks;
5+
using Avalonia.Controls.Notifications;
46
using CommunityToolkit.Mvvm.ComponentModel;
57
using CommunityToolkit.Mvvm.Input;
68
using Hollow.Abstractions.Models.HttpContrasts.MiHoYoLauncher;
@@ -10,6 +12,7 @@
1012
using Hollow.Services.GameService;
1113
using Hollow.Services.MiHoYoLauncherService;
1214
using Hollow.Services.NavigationService;
15+
using Hollow.Views.Controls;
1316
using Hollow.Views.Pages;
1417
using Serilog;
1518

@@ -45,7 +48,7 @@ public HomeViewModel(IMiHoYoLauncherService miHoYoLauncherService, HttpClient ht
4548

4649
_ = LoadContents();
4750
CheckStartGameReady();
48-
51+
4952
MainWindowViewModel.NavigatedToHome += Navigated;
5053
}
5154

Hollow/ViewModels/Pages/SettingsViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Threading.Tasks;
7+
using Avalonia.Controls.Notifications;
78
using Avalonia.Markup.Xaml.MarkupExtensions;
89
using Avalonia.Platform.Storage;
910
using CommunityToolkit.Mvvm.ComponentModel;
@@ -19,7 +20,6 @@
1920
using Hollow.Views.Controls;
2021
using Hollow.Views.Pages;
2122
using Serilog;
22-
using NotificationType = Hollow.Enums.NotificationType;
2323

2424
namespace Hollow.ViewModels.Pages;
2525

Hollow/ViewModels/Pages/SignalSearchViewModel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Text.Json;
77
using System.Threading.Tasks;
8+
using Avalonia.Controls.Notifications;
89
using Avalonia.Platform.Storage;
910
using CommunityToolkit.Mvvm.ComponentModel;
1011
using CommunityToolkit.Mvvm.Input;

Hollow/ViewModels/Pages/WikiViewModel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Net.Http;
55
using System.Text.Json;
66
using System.Threading.Tasks;
7+
using Avalonia.Controls.Notifications;
78
using CommunityToolkit.Mvvm.ComponentModel;
89
using Hollow.Abstractions.Enums.Hakush;
910
using Hollow.Abstractions.JsonConverters.Serializers;

Hollow/Views/Controls/HollowHost.axaml

-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@
1010
<ContentPresenter Content="{TemplateBinding Content}" />
1111
</Panel>
1212

13-
<ItemsControl
14-
HorizontalAlignment="Right"
15-
ItemsSource="{TemplateBinding ToastsCollection}"
16-
Margin="0,0,25,10"
17-
Name="PART_ToastPresenter"
18-
VerticalAlignment="Bottom">
19-
<ItemsControl.ItemsPanel>
20-
<ItemsPanelTemplate>
21-
<DockPanel LastChildFill="True" VerticalAlignment="Bottom" />
22-
</ItemsPanelTemplate>
23-
</ItemsControl.ItemsPanel>
24-
</ItemsControl>
25-
2613
<Border
2714
Background="#131313"
2815
HorizontalAlignment="Stretch"

Hollow/Views/Controls/HollowHost.axaml.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
using Avalonia;
66
using Avalonia.Collections;
77
using Avalonia.Controls;
8+
using Avalonia.Controls.Notifications;
89
using Avalonia.Controls.Primitives;
910
using Avalonia.Controls.Templates;
1011
using Avalonia.LogicalTree;
1112
using Avalonia.Rendering.Composition;
1213
using Avalonia.Threading;
1314
using Hollow.Helpers;
1415
using Hollow.Views.Controls.Toast;
15-
using NotificationType = Hollow.Enums.NotificationType;
1616

1717
namespace Hollow.Views.Controls;
1818

@@ -156,20 +156,20 @@ public static async Task ShowToast(Window window, ToastModel model)
156156
public static Task ShowToast(ToastModel model) =>
157157
ShowToast(_mainWindow!, model);
158158

159-
public static Task ShowToast(string title, string content = "", NotificationType? type = NotificationType.Info, TimeSpan? duration = null, Action? onClicked = null) =>
159+
public static Task ShowToast(string title, string? content, NotificationType? type, TimeSpan? duration = null, Action? onClicked = null) =>
160160
ShowToast(new ToastModel(
161161
title,
162-
content,
163-
type ?? NotificationType.Info,
162+
content ?? "",
163+
type ?? NotificationType.Information,
164164
duration ?? TimeSpan.FromSeconds(4),
165165
onClicked));
166166

167-
public static Task ShowToast(Window window, string title, string content = "", NotificationType? type = NotificationType.Info, TimeSpan? duration = null,
167+
public static Task ShowToast(Window window, string title, string? content, NotificationType? type, TimeSpan? duration = null,
168168
Action? onClicked = null) =>
169169
ShowToast(window, new ToastModel(
170170
title,
171-
content,
172-
type ?? NotificationType.Info,
171+
content ?? "",
172+
type ?? NotificationType.Information,
173173
duration ?? TimeSpan.FromSeconds(4),
174174
onClicked));
175175

@@ -201,6 +201,16 @@ public static void ClearAllToasts(Window window)
201201

202202
public static void ClearAllToasts() => ClearAllToasts(_mainWindow!);
203203

204+
#region New Toasts
205+
206+
public static WindowNotificationManager NotificationManager { get; set; } = null!;
207+
public static void ShowAvaloniaToast(string title, string message, NotificationType notificationType, TimeSpan? timeSpan = null, Action? onClick = null, Action? onClose = null)
208+
{
209+
NotificationManager.Show(new Notification(title, message, notificationType, timeSpan, onClick, onClose));
210+
}
211+
212+
#endregion
213+
204214
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
205215
{
206216
base.OnDetachedFromLogicalTree(e);

Hollow/Views/Controls/Toast/Toast.axaml.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Timers;
33
using Avalonia;
44
using Avalonia.Controls;
5+
using Avalonia.Controls.Notifications;
56
using Avalonia.Controls.Primitives;
67
using Avalonia.Input;
78
using Avalonia.Interactivity;
@@ -121,15 +122,15 @@ public void Initialize(ToastModel model, HollowHost host)
121122
}
122123
Icon = model.Type switch
123124
{
124-
NotificationType.Info => Symbol.Info,
125+
NotificationType.Information => Symbol.Info,
125126
NotificationType.Success => Symbol.CheckmarkCircle,
126127
NotificationType.Warning => Symbol.Warning,
127128
NotificationType.Error => Symbol.ErrorCircle,
128129
_ => Symbol.Info
129130
};
130131
Foreground = model.Type switch
131132
{
132-
NotificationType.Info => NotificationColor.InfoIconForeground,
133+
NotificationType.Information => NotificationColor.InfoIconForeground,
133134
NotificationType.Success => NotificationColor.SuccessIconForeground,
134135
NotificationType.Warning => NotificationColor.WarningIconForeground,
135136
NotificationType.Error => NotificationColor.ErrorIconForeground,

Hollow/Views/Controls/Toast/ToastModel.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System;
2+
using Avalonia.Controls.Notifications;
23
using Hollow.Enums;
34

45
namespace Hollow.Views.Controls.Toast;
56

6-
public readonly record struct ToastModel(string Title, string Content, NotificationType Type = NotificationType.Info, TimeSpan? Lifetime = null, Action? OnClicked = null, string? ActionButtonContent = null,Action? ActionButton= null)
7+
public readonly record struct ToastModel(string Title, string Content, NotificationType Type = NotificationType.Information, TimeSpan? Lifetime = null, Action? OnClicked = null, string? ActionButtonContent = null,Action? ActionButton= null)
78
{
89
public string Title { get; } = Title;
910
public string Content { get; } = Content;

Hollow/Views/MainWindow.axaml.cs

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
2+
using Avalonia;
23
using Avalonia.Controls;
4+
using Avalonia.Controls.Notifications;
35
using Avalonia.Input;
46
using Avalonia.Interactivity;
57
using Hollow.Services.NavigationService;
8+
using Hollow.Views.Controls;
69
using Serilog;
710

811
namespace Hollow.Views;

Hollow/Views/Pages/Home.axaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<Panel>
8181
<Carousel ItemsSource="{Binding Banners}" Name="Banners">
8282
<Carousel.PageTransition>
83-
<PageSlide Duration="0:0:0.3" Orientation="Horizontal" />
83+
<CrossFade Duration="0:0:0.3" />
8484
</Carousel.PageTransition>
8585
<Carousel.ItemTemplate>
8686
<DataTemplate>

Hollow/Views/Pages/Home.axaml.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Avalonia.Controls;
1+
using Avalonia;
2+
using Avalonia.Controls;
3+
using Avalonia.Controls.Notifications;
24
using Avalonia.Interactivity;
35
using Hollow.ViewModels.Pages;
46

0 commit comments

Comments
 (0)