-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.xaml.cs
99 lines (83 loc) · 3.45 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// ****************************** Module Header ****************************** //
//
//
// Last Modified: 17:07:2017 / 17:07
// Creation: 20:06:2017
// Project: AstroSoundBoard
//
//
// <copyright file="App.xaml.cs" company="Patrick Hollweck" GitHub="https://github.com/FetzenRndy">//</copyright>
// *************************************************************************** //
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using AstroSoundBoard.Core.Components;
using AstroSoundBoard.Core.Objects;
using AstroSoundBoard.Core.Utils;
using AstroSoundBoard.Properties;
using CrashReporterDotNET;
using log4net;
using log4net.Core;
using log4net.Repository.Hierarchy;
using MaterialDesignThemes.Wpf;
using SharpRaven;
using SharpRaven.Data;
namespace AstroSoundBoard
{
public partial class App : Application
{
private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private void Application_Startup(object sender, StartupEventArgs e)
{
#if DEBUG
((Hierarchy)LogManager.GetRepository()).Root.Level = Level.Debug;
((Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty);
#else
((Hierarchy)LogManager.GetRepository()).Root.Level = Level.Warn;
((Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty);
// Setup error handler
AppDomain.CurrentDomain.UnhandledException += ReportError;
#endif
Log.Info("--- APP START! ---");
Log.Info($"Current Version: {Assembly.GetExecutingAssembly().GetName().Version}");
FileSystem.FolderHelper.CreateIfMissing($"{AppSettings.SettingsFilePath}/");
ApplyMaterialTheme();
SoundManager.Init();
SettingsManager.Init();
}
public static void ReportError(object sender, UnhandledExceptionEventArgs args)
{
Log.Fatal($"Fatal unhanded exception. - {args.ExceptionObject} -- {args.IsTerminating} -> {args}");
if (Settings.Default.AllowErrorReporting)
{
var ravenClient = new RavenClient(Credentials.SentryApiKey);
ravenClient.Capture(new SentryEvent((Exception)args.ExceptionObject));
ReportCrash((Exception)args.ExceptionObject);
Log.Info("Reported error to sentry!");
}
}
public static void ReportCrash(Exception exception, string developerMessage = "")
{
var reportCrash = new ReportCrash("[email protected]")
{
IncludeScreenshot = true,
CaptureScreen = true,
DeveloperMessage = developerMessage
};
reportCrash.Send(exception);
}
private void Application_Exit(object sender, ExitEventArgs e)
{
Log.Info("--- APP EXIT! ---");
}
public static void ApplyMaterialTheme()
{
List<string> colorList = new List<string> { "Red", "Pink", "Purple", "Indigo", "Blue", "Cyan", "Teal", "Green", "Lime", "Yellow", "Amber", "Orange", "Brown", "Grey" };
var palette = new PaletteHelper();
palette.SetLightDark(Settings.Default.IsDarkModeEnabled);
palette.ReplaceAccentColor(colorList[Settings.Default.AccentColor]);
palette.ReplacePrimaryColor(colorList[Settings.Default.PrimaryColor]);
}
}
}