Skip to content

Commit 3dae7d4

Browse files
committed
uncommitted local changes
1 parent b03e5e6 commit 3dae7d4

18 files changed

+174
-160
lines changed

.vscode/Volte4.code-workspace

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"folders": [
3+
{
4+
"path": ".."
5+
}
6+
],
7+
"settings": {}
8+
}

src/Bot/Core/Entities/EventArgs/NotificationEventArgs.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public static event Action<NotificationEventArgs> NotificationSent
3333

3434
public sealed class CustomNotificationEventArgs : NotificationEventArgs
3535
{
36-
private CustomNotificationEventArgs(byte rawType)
37-
{
38-
RawType = rawType;
39-
}
36+
private CustomNotificationEventArgs(byte rawType)
37+
=> RawType = rawType;
4038

4139
public required string Title { get; init; }
4240
public required string Message { get; init; }

src/Bot/Version.cs

+2-13
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,13 @@ static Version()
2424

2525
InformationVersion = $"{DotNetVersion} {infoVer.Trim()}";
2626
}
27-
28-
public static readonly bool IsDevelopment = ReleaseType is DevelopmentStage.Development;
29-
30-
public static readonly DevelopmentStage ReleaseType = InformationVersion.ContainsIgnoreCase("dev")
31-
? DevelopmentStage.Development
32-
: DevelopmentStage.Release;
33-
3427

28+
public static readonly bool IsDevelopment = InformationVersion.ContainsIgnoreCase("dev");
29+
3530
public static string DiscordNetVersion => DiscordConfig.Version;
3631

3732
public static int Major => DotNetVersion.Major;
3833
public static int Minor => DotNetVersion.Minor;
3934
public static int Patch => DotNetVersion.Build;
4035
public static int Hotfix => DotNetVersion.Revision;
41-
}
42-
43-
public enum DevelopmentStage
44-
{
45-
Development,
46-
Release
4736
}

src/UI/Assets/Fonts/Mojangles.ttf

70.2 KB
Binary file not shown.

src/UI/Avalonia/Pages/Logs/LogsViewModel.LogData.cs src/UI/Avalonia/Models/VolteLog.cs

+20-26
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66

77
// ReSharper disable MemberCanBePrivate.Global
88

9-
namespace Volte.UI.Avalonia.Pages;
9+
namespace Volte.UI.Avalonia.Models;
1010

1111
public record struct VolteLog
1212
{
13-
private static readonly int LongestSeverity = Enum.GetValues<LogSeverity>()
14-
.Max(sev => Enum.GetName(sev)!.Length);
13+
private static readonly int LongestSeverity = Enum
14+
.GetNames<LogSeverity>()
15+
.Max(sev => sev.Length);
1516

16-
private static readonly int LongestSource = Enum.GetValues<LogSource>()
17-
.Max(src => Enum.GetName(src)!.Length);
17+
private static readonly int LongestSource = Enum
18+
.GetNames<LogSource>()
19+
.Max(src => src.Length);
1820

1921
private static readonly int SeverityPadding = (int)(LongestSeverity * 1.33);
2022
private static readonly int SourcePadding = (int)(LongestSource * 1.85);
@@ -34,14 +36,14 @@ public VolteLog(VolteLogEventArgs eventData)
3436
public string? Message { get; }
3537
public Exception? Error { get; }
3638

37-
private StringBuilder? _formatted = null;
38-
3939
public string? StrippedMessage => Message?.Replace(CommandEventArgs.Whitespace, string.Empty);
4040
public string SeverityName => Enum.GetName(Severity)!.ToUpper();
4141
public string SourceName => Enum.GetName(Source)!.ToUpper();
4242

4343
public string FormattedSeverityName => $"{SeverityName}:".P(SeverityPadding);
44-
public string FormattedSourceName => $"[{SourceName}] ->".P(SourcePadding + 3); //+3 accounts for the space and arrow
44+
45+
public string FormattedSourceName =>
46+
$"[{SourceName}] ->".P(SourcePadding + 3); //+3 accounts for the space and arrow
4547

4648
public string FormattedMessage
4749
{
@@ -57,28 +59,20 @@ public string FormattedMessage
5759
}
5860
}
5961

60-
public string FormattedString
61-
{
62-
get
63-
{
64-
if (_formatted is not null) return _formatted.ToString();
65-
66-
_formatted = new StringBuilder();
67-
_formatted.Append(FormattedSeverityName);
68-
_formatted.Append($"[{SourceName}]".P(SourcePadding));
69-
70-
_formatted.Append(FormattedMessage);
62+
private StringBuilder? _formatted = null;
7163

72-
return _formatted.ToString();
73-
}
74-
}
64+
public string FormattedString => (
65+
_formatted ??= new StringBuilder(FormattedSeverityName)
66+
.Append($"[{SourceName}]".P(SourcePadding))
67+
.Append(FormattedMessage)
68+
).ToString();
7569

7670

7771
public string Markdown =>
7872
$"""
79-
`[{Date.FormatDate()} @ {Date.FormatFullTime()}]`
80-
`[{SourceName}]` `[{SeverityName}]`
73+
`[{Date.FormatDate()} @ {Date.FormatFullTime()}]`
74+
`[{SourceName}]` `[{SeverityName}]`
8175
82-
{Format.Code(StrippedMessage, string.Empty)}
83-
""";
76+
{Format.Code(StrippedMessage, string.Empty)}
77+
""";
8478
}

src/UI/Avalonia/Pages/Logs/LogsView.axaml

+21-9
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5-
xmlns:faw="using:FluentAvalonia.UI.Windowing"
65
xmlns:local="using:Volte.UI.Avalonia.Pages"
6+
xmlns:models="using:Volte.UI.Avalonia.Models"
77
xmlns:pi="using:Projektanker.Icons.Avalonia"
88
xmlns:converters="using:Volte.UI.Converters"
99
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
@@ -29,26 +29,38 @@
2929
</ListBox.Styles>
3030
<ListBox.ContextFlyout>
3131
<Flyout ShowMode="TransientWithDismissOnPointerMoveAway">
32-
<StackPanel Orientation="Horizontal" Spacing="5">
32+
<StackPanel Orientation="Vertical" Spacing="5">
3333
<Button Name="CopySimple"
34-
Height="25"
35-
Width="25"
34+
MinHeight="25"
35+
MinWidth="25"
3636
Padding="0"
3737
ToolTip.Tip="Copy">
38-
<pi:Icon Name="CopySimpleIcon" />
38+
<Grid ColumnDefinitions="Auto,Auto">
39+
<pi:Icon Margin="5" Name="CopySimpleIcon" />
40+
<TextBlock Grid.Column="1"
41+
Text="Copy Line"
42+
Margin="0, 0, 5, 0"
43+
TextWrapping="NoWrap" />
44+
</Grid>
3945
</Button>
4046
<Button Name="CopyMarkdown"
41-
Height="25"
42-
Width="25"
47+
MinHeight="25"
48+
MinWidth="25"
4349
Padding="0"
4450
ToolTip.Tip="Copy Markdown">
45-
<pi:Icon Name="CopyMarkdownIcon" />
51+
<Grid ColumnDefinitions="Auto,Auto">
52+
<pi:Icon Margin="5" Name="CopyMarkdownIcon" />
53+
<TextBlock Grid.Column="1"
54+
Text="Copy Markdown"
55+
Margin="0, 0, 5, 0"
56+
TextWrapping="NoWrap" />
57+
</Grid>
4658
</Button>
4759
</StackPanel>
4860
</Flyout>
4961
</ListBox.ContextFlyout>
5062
<ListBox.ItemTemplate>
51-
<DataTemplate DataType="{x:Type local:VolteLog}">
63+
<DataTemplate DataType="{x:Type models:VolteLog}">
5264
<Grid ColumnDefinitions="Auto,Auto,*,Auto" Margin="5">
5365
<TextBlock Grid.Column="0"
5466
FontFamily="{StaticResource JetBrainsMono}"

src/UI/Avalonia/Pages/Logs/LogsView.axaml.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public LogsView()
1313
{
1414
InitializeComponent();
1515
DataContext = new LogsViewModel { View = this, LogsClearAmount = 10 };
16-
16+
1717
CopySimpleIcon.Value = FontAwesome.Copy;
1818
CopySimple.Command = new AsyncRelayCommand(async () =>
1919
{

src/UI/Avalonia/Pages/Logs/LogsViewModel.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Collections.ObjectModel;
2-
using Avalonia;
32
using Avalonia.Threading;
43
using CommunityToolkit.Mvvm.ComponentModel;
5-
using CommunityToolkit.Mvvm.Input;
64
using Discord;
75
using Gommon;
86
using Volte.Entities;
97
using Volte.Helpers;
8+
using Volte.UI.Avalonia.Models;
109
using Volte.UI.Helpers;
1110

1211
namespace Volte.UI.Avalonia.Pages;
@@ -29,10 +28,8 @@ public partial class LogsViewModel : ObservableObject
2928

3029
~LogsViewModel() => Logger.Event -= Receive;
3130

32-
public static void UnregisterHandler()
33-
{
34-
Logger.Event -= PageManager.Shared.GetViewModel<LogsViewModel>().Receive;
35-
}
31+
public static void UnregisterHandler()
32+
=> Logger.Event -= PageManager.Shared.GetViewModel<LogsViewModel>().Receive;
3633

3734
private void Receive(VolteLogEventArgs eventArgs)
3835
{

src/UI/Avalonia/Pages/UIShellView.axaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
HorizontalAlignment="Center"
3131
VerticalAlignment="Center">
3232
<Border Padding="25">
33-
<Image Name="VolteLogo"></Image>
33+
<Image Name="VolteLogo" />
3434
</Border>
3535
</Viewbox>
3636
</Grid>

src/UI/Avalonia/Pages/UIShellView.axaml.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public UIShellView()
1515
TitleBar.ExtendsContentIntoTitleBar = true;
1616
TitleBar.TitleBarHitTestType = TitleBarHitTestType.Complex;
1717

18-
using var bitmap = new Bitmap(AssetLoader.Open(AvaloniaHelper.GetResourceUri("icon.ico")));
19-
VolteLogo.Source = Icon = bitmap.CreateScaledBitmap(new PixelSize(48, 48));
18+
using var bitmap = new Bitmap(AvaloniaHelper.OpenResource("icon.ico"));
19+
VolteLogo.Source = Icon = bitmap.CreateScaledBitmap(new PixelSize(48, 48), BitmapInterpolationMode.None);
2020

2121
DataContext = new UIShellViewModel { View = this };
2222

src/UI/Avalonia/VolteApp.axaml.cs

+39-38
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ public override void Initialize()
3232
switch (notif)
3333
{
3434
case CustomNotificationEventArgs custom:
35-
Notify(custom.Message, custom.Title,
36-
custom.RawType.HardCast<NotificationType>(),
35+
var notificationType = custom.RawType.HardCast<NotificationType>();
36+
Notify(
37+
custom.Message,
38+
custom.Title,
39+
Enum.IsDefined(notificationType) ? notificationType : NotificationType.Information,
3740
custom.Expiration,
38-
notif.Clicked, notif.Closed
39-
);
41+
notif.Clicked,
42+
notif.Closed
43+
);
4044
break;
4145
case ErrorNotificationEventArgs custom:
4246
NotifyError(custom.Error, custom.Expiration, notif.Clicked, notif.Closed);
@@ -47,43 +51,40 @@ public override void Initialize()
4751

4852
public override void OnFrameworkInitializationCompleted()
4953
{
50-
if (AvaloniaHelper.TryGetDesktop(out var desktop))
54+
if (!AvaloniaHelper.TryGetDesktop(out var desktop)) return;
55+
56+
XamlRoot = desktop.MainWindow = new UIShellView();
57+
58+
desktop.MainWindow.Loaded += (_, _) => _notificationManager = new(XamlRoot)
5159
{
52-
XamlRoot = desktop.MainWindow = new UIShellView();
53-
54-
desktop.MainWindow.Loaded += (_, _) => _notificationManager = new(XamlRoot)
55-
{
56-
Position = NotificationPosition.BottomRight,
57-
MaxItems = 4,
58-
Margin = new(0, 0, 4, 30)
59-
};
60-
61-
desktop.MainWindow.Closing += (_, _) =>
62-
{
63-
LogsViewModel.UnregisterHandler();
64-
VolteManager.Stop();
65-
};
66-
67-
TaskScheduler.UnobservedTaskException += (_, eventArgs) =>
68-
{
69-
NotifyError(eventArgs.Exception);
70-
eventArgs.SetObserved();
71-
};
60+
Position = NotificationPosition.BottomRight,
61+
MaxItems = 4,
62+
Margin = new(0, 0, 4, 30)
63+
};
64+
65+
desktop.MainWindow.Closing += (_, _) =>
66+
{
67+
LogsViewModel.UnregisterHandler();
68+
VolteManager.Stop();
69+
};
70+
71+
TaskScheduler.UnobservedTaskException += (_, eventArgs) =>
72+
{
73+
NotifyError(eventArgs.Exception);
74+
eventArgs.SetObserved();
75+
};
76+
77+
PageManager.Init();
7278

73-
PageManager.Init();
74-
7579
#if DEBUG
76-
XamlRoot.AttachDevTools(new DevToolsOptions
77-
{
78-
Gesture = OpenDevTools,
79-
Size = new Size(800, 800),
80-
LaunchView = DevToolsViewKind.LogicalTree,
81-
FocusHighlighterBrush = Brushes.Crimson
82-
});
80+
this.AttachDevTools(new DevToolsOptions
81+
{
82+
Gesture = OpenDevTools,
83+
Size = new Size(800, 800),
84+
LaunchView = DevToolsViewKind.LogicalTree,
85+
FocusHighlighterBrush = Brush.Parse("#7000FB")
86+
});
8387
#endif
84-
}
85-
86-
VolteManager.Start();
8788
}
8889

8990
public static void Notify(Notification notification)
@@ -114,7 +115,7 @@ public static void NotifyError<TException>(
114115
Action? onClick = null,
115116
Action? onClose = null
116117
) where TException : Exception
117-
=> Notify(new Notification
118+
=> Notify(new Notification
118119
{
119120
Title = typeof(TException).AsPrettyString(),
120121
Message = ex.Message,
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Collections.Immutable;
2+
using System.Globalization;
3+
using Avalonia.Data.Converters;
4+
using Gommon;
5+
6+
// ReSharper disable InconsistentNaming
7+
8+
namespace Volte.UI.Converters;
9+
10+
public abstract class BasicValueConverter<TFrom, TTo, TConverter> : IValueConverter where TConverter : IValueConverter, new()
11+
{
12+
private static readonly Lazy<TConverter> _shared = new(() => new());
13+
public static TConverter Shared => _shared.Value;
14+
15+
protected Optional<ImmutableArray<(TFrom From, TTo To)>> Definitions;
16+
17+
public object Convert(object? value, Type _, object? __, CultureInfo ___) =>
18+
Definitions.OrDefault()
19+
.FindFirst(x => x.From!.Equals(value))
20+
.Convert(x => x.To);
21+
22+
public object ConvertBack(object? value, Type _, object? __, CultureInfo ___) =>
23+
Definitions.OrDefault()
24+
.FindFirst(x => x.To!.Equals(value))
25+
.Convert(x => x.From);
26+
}

0 commit comments

Comments
 (0)