Skip to content

Commit

Permalink
feat: global exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Jul 10, 2024
1 parent f8bba45 commit 620f291
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
1 change: 0 additions & 1 deletion Hollow/Models/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class AppInfo

public static readonly string BasePath = Directory.GetCurrentDirectory();
public static readonly string ConfigPath = Path.Combine(BasePath, "config.json");
public static readonly string CrushesDir = Path.Combine(BasePath, "crashes");
public static readonly string LogDir = Path.Combine(BasePath, "logs");
public static readonly string CachesDir = Path.Combine(BasePath, "caches");
public static readonly string GachaRecordsDir = Path.Combine(BasePath, "gacha_records");
Expand Down
19 changes: 16 additions & 3 deletions Hollow/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@ public static void Main(string[] args)
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Version", AppInfo.AppVersion)
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "[{Level}] {Timestamp:HH:mm:ss} {Message}{NewLine}{Exception}")
.WriteTo.File(Path.Combine(AppInfo.LogDir, "log_.txt"), outputTemplate: "[{Level}] {Timestamp:HH:mm:ss} {Message}{NewLine}{Exception}", rollingInterval: RollingInterval.Day, retainedFileCountLimit: null)
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}")
.WriteTo.File(Path.Combine(AppInfo.LogDir, "log_.txt"), outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}", rollingInterval: RollingInterval.Day, retainedFileCountLimit: null)
.CreateLogger();

Log.Information("Hollow is starting...");

//TODO: Platform specific
Environment.SetEnvironmentVariable("WEBVIEW2_USER_DATA_FOLDER", AppInfo.CachesDir);

BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
try
{
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
catch (Exception e)
{
Log.Fatal(e, "Oops, Hollow crashed!");
}
finally
{
Log.CloseAndFlush();
}
}

// Avalonia configuration, don't remove; also used by visual designer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public ConfigurationService()
public static AppConfig LoadConfiguration()
{
Directory.CreateDirectory(AppInfo.BasePath);
Directory.CreateDirectory(AppInfo.CrushesDir);
Directory.CreateDirectory(AppInfo.LogDir);
Directory.CreateDirectory(AppInfo.CachesDir);
Directory.CreateDirectory(AppInfo.GachaRecordsDir);
Expand Down
2 changes: 1 addition & 1 deletion Hollow/ViewModels/Pages/AnnouncementsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void GameAnnouncementWebView_OnWebViewCreated(object? sender, WebViewCrea
AnnouncementLoadingCoverageOpacity = 1;
AnnouncementLoaded = false;
//TODO: Platform specific
if (Announcements.AnnouncementWebView.PlatformWebView is WebView2Core webView2Core)
if (Announcements.AnnouncementWebView.PlatformWebView is WebView2Core { CoreWebView2: not null } webView2Core)
{
webView2Core.CoreWebView2!.DOMContentLoaded += async (_, _) =>
{
Expand Down
2 changes: 0 additions & 2 deletions Hollow/ViewModels/Pages/HomeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public HomeViewModel(IMiHoYoLauncherService miHoYoLauncherService, HttpClient ht
_httpClient = httpClient;
_configurationService = configurationService;
_gameService = gameService;

Log.Information("test");

_ = LoadContents();
CheckStartGameReady();
Expand Down
2 changes: 2 additions & 0 deletions Hollow/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Serilog;

namespace Hollow.Views;

Expand All @@ -19,6 +20,7 @@ private void MinimizeButton_OnClick(object? _1, RoutedEventArgs _2)

private void CloseButton_OnClick(object? _1, RoutedEventArgs _2)
{
Log.CloseAndFlush();
Environment.Exit(0);
}

Expand Down

0 comments on commit 620f291

Please sign in to comment.