4
4
using Microsoft . Extensions . Configuration ;
5
5
using Microsoft . Extensions . DependencyInjection ;
6
6
using Microsoft . Extensions . Hosting ;
7
+ using Sentry ;
7
8
using Serilog ;
8
9
using SharpDeck . Connectivity ;
9
10
using SharpDeck . Extensions . Hosting ;
10
11
using System ;
11
12
using System . IO ;
13
+ using System . Reflection ;
12
14
using System . Threading . Tasks ;
13
15
using System . Windows ;
16
+ using System . Windows . Threading ;
14
17
15
18
namespace FlightStreamDeck . AddOn ;
16
19
@@ -23,6 +26,11 @@ public partial class App : Application
23
26
24
27
private MainWindow ? mainWindow = null ;
25
28
29
+ public App ( )
30
+ {
31
+ InitializeSentry ( ) ;
32
+ }
33
+
26
34
protected override void OnStartup ( StartupEventArgs e )
27
35
{
28
36
var builder = new ConfigurationBuilder ( )
@@ -48,6 +56,44 @@ protected override void OnStartup(StartupEventArgs e)
48
56
}
49
57
}
50
58
59
+ private void InitializeSentry ( )
60
+ {
61
+ if ( Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( "FlightStreamDeck.AddOn.Sentry.txt" ) is Stream stream )
62
+ {
63
+ using ( stream )
64
+ {
65
+ using var reader = new StreamReader ( stream ) ;
66
+ var dsn = reader . ReadLine ( ) ;
67
+ if ( ! string . IsNullOrWhiteSpace ( dsn ) )
68
+ {
69
+ DispatcherUnhandledException += App_DispatcherUnhandledException ;
70
+ SentrySdk . Init ( o =>
71
+ {
72
+ // Tells which project in Sentry to send events to:
73
+ o . Dsn = dsn ;
74
+ // When configuring for the first time, to see what the SDK is doing:
75
+ //o.Debug = true;
76
+ // Set TracesSampleRate to 1.0 to capture 100% of transactions for tracing.
77
+ // We recommend adjusting this value in production.
78
+ o . TracesSampleRate = 1.0 ;
79
+ // Enable Global Mode since this is a client app
80
+ o . IsGlobalModeEnabled = true ;
81
+
82
+ o . AutoSessionTracking = true ;
83
+ } ) ;
84
+ }
85
+ }
86
+ }
87
+ }
88
+
89
+ void App_DispatcherUnhandledException ( object sender , DispatcherUnhandledExceptionEventArgs e )
90
+ {
91
+ SentrySdk . CaptureException ( e . Exception ) ;
92
+
93
+ // If you want to avoid the application from crashing:
94
+ //e.Handled = true;
95
+ }
96
+
51
97
private IHost ? InitializeStreamDeckHost ( ServiceCollection serviceCollection )
52
98
{
53
99
if ( Environment . GetCommandLineArgs ( ) . Length <= 1 )
0 commit comments