diff --git a/src/Sentry.Unity.Native/SentryNative.cs b/src/Sentry.Unity.Native/SentryNative.cs index b21071b0f..120d46d9c 100644 --- a/src/Sentry.Unity.Native/SentryNative.cs +++ b/src/Sentry.Unity.Native/SentryNative.cs @@ -1,5 +1,5 @@ -using System; using Sentry.Extensibility; +using Sentry.Unity.Integrations; namespace Sentry.Unity.Native { @@ -17,11 +17,11 @@ public static void Configure(SentryUnityOptions options) if (options.WindowsNativeSupportEnabled) { SentryNativeBridge.Init(options); - SentryMonoBehaviour.AttachOnApplicationQuittingOverride(() => + ApplicationAdapter.Instance.Quitting += () => { options?.DiagnosticLogger?.LogDebug("Closing the sentry-native SDK"); SentryNativeBridge.Close(); - }); + }; options.ScopeObserver = new NativeScopeObserver(options); options.EnableScopeSync = true; // options.CrashedLastRun = () => @@ -48,9 +48,4 @@ public static void Configure(SentryUnityOptions options) } } } - - internal class SentryMonoBehaviour : SentryMonoBehaviourInternal - { - public static void AttachOnApplicationQuittingOverride(Action action) => AttachOnApplicationQuitting(action); - } } diff --git a/src/Sentry.Unity/Integrations/IApplication.cs b/src/Sentry.Unity/Integrations/IApplication.cs index 7df8a90d8..b078d507e 100644 --- a/src/Sentry.Unity/Integrations/IApplication.cs +++ b/src/Sentry.Unity/Integrations/IApplication.cs @@ -16,7 +16,8 @@ internal interface IApplication RuntimePlatform Platform { get; } } - internal sealed class ApplicationAdapter : IApplication + /// Semi-internal class to be used by other Sentry.Unity assemblies + public sealed class ApplicationAdapter : IApplication { public static readonly ApplicationAdapter Instance = new(); diff --git a/src/Sentry.Unity/SentryMonoBehaviour.cs b/src/Sentry.Unity/SentryMonoBehaviour.cs index 34333bc87..594c20579 100644 --- a/src/Sentry.Unity/SentryMonoBehaviour.cs +++ b/src/Sentry.Unity/SentryMonoBehaviour.cs @@ -50,15 +50,6 @@ internal partial class SentryMonoBehaviour /// public event Action? ApplicationPausing; - /// - /// Hook to receive an event when the application is quitting. - /// - /// This is not guaranteed to be called on all platforms. See Unity docs for more details: - /// https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnApplicationQuit.html - /// - /// - public event Action? ApplicationQuitting; - // Keeping internal track of running state because OnApplicationPause and OnApplicationFocus get called during startup and would fire false resume events private bool _isRunning = true; @@ -125,31 +116,8 @@ internal void OnApplicationFocus(bool hasFocus) } } - private void OnApplicationQuit() - { - try - { - ApplicationQuitting?.Invoke(); - } - catch (Exception e) - { - Debug.LogWarningFormat("ApplicationQuitting.Invoke() threw an exception %s", e.ToString()); - } - - // The GameObject has to destroy itself since it was created with HideFlags.HideAndDontSave - Destroy(gameObject); - } - } - - /// - /// Sentry-Unity SDK internal class for other Sentry.Unity.* assemblies. - /// You should not use this directly in your application. - /// - public class SentryMonoBehaviourInternal - { - /// This is `protected internal` to be semi-hidden from users. - protected internal static void AttachOnApplicationQuitting(Action action) => - SentryMonoBehaviour.Instance.ApplicationQuitting += action; + // The GameObject has to destroy itself since it was created with HideFlags.HideAndDontSave + private void OnApplicationQuit() => Destroy(gameObject); } /// diff --git a/src/Sentry.Unity/SentryUnity.cs b/src/Sentry.Unity/SentryUnity.cs index f5059aa1e..f83eae333 100644 --- a/src/Sentry.Unity/SentryUnity.cs +++ b/src/Sentry.Unity/SentryUnity.cs @@ -1,6 +1,7 @@ using System; using System.ComponentModel; using Sentry.Extensibility; +using Sentry.Unity.Integrations; namespace Sentry.Unity { @@ -32,7 +33,7 @@ public static void Init(SentryUnityOptions sentryUnityOptions) { sentryUnityOptions.DiagnosticLogger?.LogDebug(sentryUnityOptions.ToString()); var sentryDotNet = SentrySdk.Init(sentryUnityOptions); - SentryMonoBehaviour.Instance.ApplicationQuitting += () => + ApplicationAdapter.Instance.Quitting += () => { sentryUnityOptions.DiagnosticLogger?.LogDebug("Closing the sentry-dotnet SDK"); sentryDotNet.Dispose();