From 85a0823ce2414c1e71d292c610ccc5f016fcd97e Mon Sep 17 00:00:00 2001 From: Samrat Banerjee <106741933+SamratB8@users.noreply.github.com> Date: Wed, 15 Jul 2026 21:58:47 +0530 Subject: [PATCH] fix(studio): avoid startup crash when Sentry DSN is missing --- src/WinDroid.Studio/App.xaml.cs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/WinDroid.Studio/App.xaml.cs b/src/WinDroid.Studio/App.xaml.cs index a48f469..7a1bdde 100644 --- a/src/WinDroid.Studio/App.xaml.cs +++ b/src/WinDroid.Studio/App.xaml.cs @@ -8,25 +8,30 @@ namespace WinDroid.Studio; /// public partial class App : Application { - private readonly IDisposable _sentry; + private IDisposable? _sentry; private Window? _window; public App() { - _sentry = SentrySdk.Init(options => + InitializeComponent(); + + var sentryDsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); + + if (!string.IsNullOrWhiteSpace(sentryDsn)) { - options.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN"); + _sentry = SentrySdk.Init(options => + { + options.Dsn = sentryDsn; #if DEBUG - options.Debug = true; + options.Debug = true; #else - options.Debug = false; + options.Debug = false; #endif - options.AutoSessionTracking = true; - }); - - InitializeComponent(); + options.AutoSessionTracking = true; + }); + } } protected override void OnLaunched(LaunchActivatedEventArgs args) @@ -38,6 +43,11 @@ protected override void OnLaunched(LaunchActivatedEventArgs args) private async void OnMainWindowClosed(object sender, WindowEventArgs args) { + if (_sentry is null) + { + return; + } + await SentrySdk.FlushAsync(TimeSpan.FromSeconds(2)); _sentry.Dispose(); }