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

Release 0.9.9.55 #863

Merged
merged 4 commits into from
Nov 17, 2024
Merged
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
14 changes: 14 additions & 0 deletions Daybreak/Controls/Glyphs/BugGlyph.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl x:Class="Daybreak.Controls.Glyphs.BugGlyph"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Daybreak.Controls.Glyphs"
x:Name="_this"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Viewbox>
<Path Fill="{Binding ElementName=_this, Path=Foreground, Mode=OneWay}"
Data="m1.188,47.173a2,2 0 0 0 -1.188,1.827l0,8l4,0l0,-6.7l6.992,-3.108a17.968,17.968 0 0 0 32.016,0l6.992,3.108l0,6.7l4,0l0,-8a2,2 0 0 0 -1.188,-1.827l-8.39,-3.729a17.858,17.858 0 0 0 0.511,-3.115l7.879,-3.5a2,2 0 0 0 1.188,-1.829l0,-8l-4,0l0,6.7l-5,2.223l0,-10.623l7.812,-3.472a2,2 0 0 0 1.188,-1.828l0,-8l-4,0l0,6.7l-5.325,2.367a6.006,6.006 0 0 0 -5.675,-4.067l-2,0l0,-4a7.941,7.941 0 0 0 -0.99,-3.847l3.239,-2.591a2,2 0 0 0 0.751,-1.562l0,-5l-4,0l0,4.039l-2.747,2.2a7.939,7.939 0 0 0 -4.253,-1.239l-4,0a7.939,7.939 0 0 0 -4.253,1.237l-2.747,-2.198l0,-4.039l-4,0l0,5a2,2 0 0 0 0.751,1.562l3.239,2.591a7.941,7.941 0 0 0 -0.99,3.847l0,4l-2,0a6.006,6.006 0 0 0 -5.675,4.067l-5.325,-2.367l0,-6.7l-4,0l0,8a2,2 0 0 0 1.188,1.827l7.812,3.473l0,10.623l-5,-2.223l0,-6.7l-4,0l0,8a2,2 0 0 0 1.188,1.827l7.879,3.5a17.858,17.858 0 0 0 0.511,3.115l-8.39,3.731zm11.812,-8.173l0,-10l12,0l0,23.84a14.009,14.009 0 0 1 -12,-13.84zm16,13.84l0,-23.84l12,0l0,10a14.009,14.009 0 0 1 -12,13.84zm-8,-39.84a4,4 0 0 1 4,-4l4,0a4,4 0 0 1 4,4l0,4l-12,0l0,-4zm-6,8l24,0a2,2 0 0 1 2,2l0,2l-28,0l0,-2a2,2 0 0 1 2,-2z"/>
</Viewbox>
</UserControl>
26 changes: 26 additions & 0 deletions Daybreak/Controls/Glyphs/BugGlyph.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Daybreak.Controls.Glyphs;
/// <summary>
/// Interaction logic for BugGlyph.xaml
/// </summary>
public partial class BugGlyph : UserControl
{
public BugGlyph()
{
InitializeComponent();
}
}
2 changes: 1 addition & 1 deletion Daybreak/Daybreak.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<LangVersion>preview</LangVersion>
<ApplicationIcon>Daybreak.ico</ApplicationIcon>
<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>
<Version>0.9.9.54</Version>
<Version>0.9.9.55</Version>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<UserSecretsId>cfb2a489-db80-448d-a969-80270f314c46</UserSecretsId>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand Down
55 changes: 55 additions & 0 deletions Daybreak/Launch/ExceptionDialog.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Window x:Class="Daybreak.Launch.ExceptionDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:Daybreak.Controls"
xmlns:buttons="clr-namespace:Daybreak.Controls.Buttons"
xmlns:local="clr-namespace:Daybreak.Launch"
x:Name="_this"
Title="Unhandled exception encountered!"
mc:Ignorable="d"
Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBox Text="{Binding ElementName=_this, Path=ExceptionMessage, Mode=OneWay}"
IsReadOnly="True"/>
<StackPanel Grid.Row="1"
Orientation="Horizontal"
HorizontalAlignment="Center">
<buttons:HighlightButton
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
Background="{StaticResource MahApps.Brushes.ThemeBackground}"
BorderBrush="{StaticResource MahApps.Brushes.ThemeForeground}"
HighlightColor="{StaticResource MahApps.Brushes.Accent}"
BorderThickness="1"
Title="Ok"
Width="80"
Height="30"
FontSize="16"
Margin="0, 0, 50, 0"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Clicked="OkButton_Clicked">
</buttons:HighlightButton>
<buttons:HighlightButton
Foreground="{StaticResource MahApps.Brushes.ThemeForeground}"
Background="{StaticResource MahApps.Brushes.ThemeBackground}"
BorderBrush="{StaticResource MahApps.Brushes.ThemeForeground}"
HighlightColor="{StaticResource MahApps.Brushes.Accent}"
BorderThickness="1"
Title="Report"
Width="80"
Height="30"
FontSize="16"
Margin="50, 0, 0, 0"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Clicked="ReportButton_Clicked">
</buttons:HighlightButton>
</StackPanel>
</Grid>
</Window>
72 changes: 72 additions & 0 deletions Daybreak/Launch/ExceptionDialog.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Diagnostics;
using System.Web;
using System.Windows;
using System.Windows.Extensions;

namespace Daybreak.Launch;
/// <summary>
/// Interaction logic for ExceptionDialog.xaml
/// </summary>
public partial class ExceptionDialog : Window
{
private const string TitlePlaceholder = "[TITLE]";
private const string BodyPlaceholder = "[BODY]";
private const string IssueUrl = $"https://github.com/gwdevhub/Daybreak/issues/new?title={TitlePlaceholder}&body={BodyPlaceholder}&labels=bug";

private string exceptionName;

[GenerateDependencyProperty]
private string exceptionMessage = string.Empty;

public ExceptionDialog(Exception exception)
{
this.InitializeComponent();
this.exceptionName = exception.GetType().Name;
this.ExceptionMessage = exception.ToString();
}

public ExceptionDialog(string exceptionName, string exceptionMessage)
{
this.InitializeComponent();
this.exceptionName = exceptionName;
this.ExceptionMessage = exceptionMessage;
}

private void OkButton_Clicked(object sender, EventArgs e)
{
this.Close();
}

private void ReportButton_Clicked(object sender, EventArgs e)
{
var title = $"[User Report] {this.exceptionName}";
var body = this.ExceptionMessage;

var url = IssueUrl
.Replace(TitlePlaceholder, HttpUtility.UrlEncode(title))
.Replace(BodyPlaceholder, HttpUtility.UrlEncode(body));

Process.Start(new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
});

this.Close();
}

public static void ShowException(Exception exception)
{
var exceptionDialog = new ExceptionDialog(exception);
exceptionDialog.ShowDialog();
return;
}

public static void ShowException(string exceptionName, string exceptionMessage)
{
var exceptionDialog = new ExceptionDialog(exceptionName, exceptionMessage);
exceptionDialog.ShowDialog();
return;
}
}
19 changes: 19 additions & 0 deletions Daybreak/Launch/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@
</Grid>
</buttons:HighlightButton.ButtonContent>
</buttons:HighlightButton>
<buttons:HighlightButton Height="30"
Width="47"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Grid.Column="1"
Margin="0, 0, 190, 0"
Cursor="Hand"
Opacity="0.8"
HighlightColor="White"
ToolTip="Report an issue"
Clicked="BugButton_Click">
<buttons:HighlightButton.ButtonContent>
<Grid Height="30"
Width="30">
<glyphs:BugGlyph Height="20"
Width="20" />
</Grid>
</buttons:HighlightButton.ButtonContent>
</buttons:HighlightButton>
<notifications:NotificationStackpanel
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Expand Down
24 changes: 23 additions & 1 deletion Daybreak/Launch/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Daybreak.Views;
using MahApps.Metro.Controls;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System;
using System.Configuration;
Expand All @@ -34,6 +35,8 @@ namespace Daybreak.Launch;
[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0052:Remove unread private members", Justification = "Used by source generators")]
public partial class MainWindow : MetroWindow
{
private const string IssueUrl = "https://github.com/gwdevhub/Daybreak/issues/new";

private readonly IOptionsSynchronizationService optionsSynchronizationService;
private readonly ISplashScreenService splashScreenService;
private readonly IMenuServiceInitializer menuServiceInitializer;
Expand All @@ -43,6 +46,7 @@ public partial class MainWindow : MetroWindow
private readonly IPrivilegeManager privilegeManager;
private readonly ILiveOptions<LauncherOptions> launcherOptions;
private readonly ILiveOptions<ThemeOptions> themeOptions;
private readonly ILogger<MainWindow> logger;
private readonly CancellationTokenSource cancellationToken = new();

[GenerateDependencyProperty]
Expand Down Expand Up @@ -74,7 +78,8 @@ public MainWindow(
IPrivilegeManager privilegeManager,
IOptionsUpdateHook optionsUpdateHook,
ILiveOptions<LauncherOptions> launcherOptions,
ILiveOptions<ThemeOptions> themeOptions)
ILiveOptions<ThemeOptions> themeOptions,
ILogger<MainWindow> logger)
{
this.optionsSynchronizationService = optionsSynchronizationService.ThrowIfNull();
this.splashScreenService = splashScreenService.ThrowIfNull();
Expand All @@ -85,6 +90,7 @@ public MainWindow(
this.privilegeManager = privilegeManager.ThrowIfNull();
this.launcherOptions = launcherOptions.ThrowIfNull();
this.themeOptions = themeOptions.ThrowIfNull();
this.logger = logger.ThrowIfNull();
optionsUpdateHook.ThrowIfNull().RegisterHook<ThemeOptions>(this.ThemeOptionsChanged);
this.InitializeComponent();
this.CurrentVersionText = this.applicationUpdater.CurrentVersion.ToString();
Expand Down Expand Up @@ -121,6 +127,22 @@ private void SynchronizeButton_Click(object sender, EventArgs e)
this.viewManager.ShowView<SettingsSynchronizationView>();
}

private void BugButton_Click(object sender, EventArgs e)
{
try
{
Process.Start(new ProcessStartInfo
{
FileName = IssueUrl,
UseShellExecute = true
});
}
catch (Exception ex)
{
this.logger.LogError(ex, "Encountered exception while opening issues page");
}
}

private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton is not MouseButton.Left &&
Expand Down
5 changes: 3 additions & 2 deletions Daybreak/Models/Notifications/Handling/MessageBoxHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Windows;
using Daybreak.Launch;
using System.Windows;

namespace Daybreak.Models.Notifications.Handling;

public sealed class MessageBoxHandler : INotificationHandler
{
public void OpenNotification(Notification notification)
{
MessageBox.Show(notification.Description, notification.Title);
ExceptionDialog.ShowException(notification.Title, notification.Description);
}
}
8 changes: 4 additions & 4 deletions Daybreak/Services/ExceptionHandling/ExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Daybreak.Exceptions;
using Daybreak.Launch;
using Daybreak.Models.Notifications.Handling;
using Daybreak.Services.Notifications;
using Daybreak.Utils;
Expand All @@ -11,7 +12,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;

namespace Daybreak.Services.ExceptionHandling;

Expand Down Expand Up @@ -45,7 +45,7 @@ public bool HandleException(Exception e)
if (e is FatalException fatalException)
{
this.logger.LogCritical(e, $"{nameof(FatalException)} encountered. Closing application");
MessageBox.Show(fatalException.ToString());
ExceptionDialog.ShowException(fatalException);
File.WriteAllText("crash.log", e.ToString());
WriteCrashDump();
return false;
Expand All @@ -58,7 +58,7 @@ public bool HandleException(Exception e)
else if (e is TargetInvocationException targetInvocationException && e.InnerException is FatalException innerFatalException)
{
this.logger.LogCritical(e, $"{nameof(FatalException)} encountered. Closing application");
MessageBox.Show(innerFatalException.ToString());
ExceptionDialog.ShowException(e);
File.WriteAllText("crash.log", e.ToString());
WriteCrashDump();
return false;
Expand Down Expand Up @@ -92,7 +92,7 @@ public bool HandleException(Exception e)
}

this.logger.LogError(e, $"Unhandled exception caught {e.GetType()}");
this.notificationService.NotifyError<MessageBoxHandler>("Encountered exception", e.ToString());
this.notificationService.NotifyError<MessageBoxHandler>(e.GetType().Name, e.ToString());
return true;
}

Expand Down
3 changes: 2 additions & 1 deletion Daybreak/Services/Logging/JsonLogsManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Daybreak.Configuration.Options;
using Daybreak.Services.Database;
using Daybreak.Services.Logging.Models;
using Daybreak.Utils;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -65,7 +66,7 @@ public async void WriteLog(Log log)
Message = log.Exception is null ? log.Message : $"{log.Message}{Environment.NewLine}{log.Exception}",
Category = log.Category,
LogLevel = log.LogLevel,
LogTime = log.LogTime,
LogTime = log.LogTime.ToSafeDateTimeOffset(),
CorrelationVector = log.CorrelationVector
};

Expand Down
Loading
Loading