diff --git a/CHANGELOG.md b/CHANGELOG.md index d02fc7054..bb23a7a72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features - Launch a setup wizard after installation ([#780](https://github.com/getsentry/sentry-unity/pull/780)) +- Reduced automated screenshot attachment controls to a simple toggle ([#784](https://github.com/getsentry/sentry-unity/pull/784)) - Disable AutoSessionTracking on unknown platforms ([#840](https://github.com/getsentry/sentry-unity/pull/840)) - Support Android apps minified with Proguard ([#844](https://github.com/getsentry/sentry-unity/pull/844)) - Bump Cocoa SDK to v7.17.0 ([#802](https://github.com/getsentry/sentry-unity/pull/802) & [#821](https://github.com/getsentry/sentry-unity/pull/821)) diff --git a/src/Sentry.Unity.Editor/ConfigurationWindow/EnrichmentTab.cs b/src/Sentry.Unity.Editor/ConfigurationWindow/EnrichmentTab.cs index 47e5a00b0..3b6f42b8f 100644 --- a/src/Sentry.Unity.Editor/ConfigurationWindow/EnrichmentTab.cs +++ b/src/Sentry.Unity.Editor/ConfigurationWindow/EnrichmentTab.cs @@ -78,26 +78,12 @@ internal static void Display(ScriptableSentryUnityOptions options) EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), Color.gray); EditorGUILayout.Space(); - { - options.AttachScreenshot = EditorGUILayout.BeginToggleGroup( - new GUIContent("Attach Screenshot", "Try to attach current screenshot on events.\n" + - "This is an early-access feature and may not work on all platforms (it is explicitly disabled on WebGL).\n" + - "Additionally, the screenshot is captured mid-frame, when an event happens, so it may be incomplete.\n" + - "A screenshot might not be able to be attached, for example when the error happens on a background thread."), - options.AttachScreenshot); - options.ScreenshotMaxWidth = EditorGUILayout.IntField( - new GUIContent("Max Width", "Maximum width of the screenshot or 0 to keep the original size. " + - "If the application window is larger, the screenshot will be resized proportionally."), - options.ScreenshotMaxWidth); - options.ScreenshotMaxHeight = EditorGUILayout.IntField( - new GUIContent("Max Height", "Maximum height of the screenshot or 0 to keep the original size. " + - "If the application window is larger, the screenshot will be resized proportionally."), - options.ScreenshotMaxHeight); - options.ScreenshotQuality = EditorGUILayout.IntSlider( - new GUIContent("JPG quality", "Quality of the JPG screenshot: 0 - 100, where 100 is the best quality and highest size."), - options.ScreenshotQuality, 0, 100); - EditorGUILayout.EndToggleGroup(); - } + options.AttachScreenshot = EditorGUILayout.Toggle( + new GUIContent("Attach Screenshot", "Try to attach current screenshot on events.\n" + + "This is an early-access feature and may not work on all platforms (it is explicitly disabled on WebGL).\n" + + "Additionally, the screenshot is captured mid-frame, when an event happens, so it may be incomplete.\n" + + "A screenshot might not be able to be attached, for example when the error happens on a background thread."), + options.AttachScreenshot); } } } diff --git a/src/Sentry.Unity.Editor/ScriptableSentryUnityOptionsEditor.cs b/src/Sentry.Unity.Editor/ScriptableSentryUnityOptionsEditor.cs index e6e69da42..eb0dd7238 100644 --- a/src/Sentry.Unity.Editor/ScriptableSentryUnityOptionsEditor.cs +++ b/src/Sentry.Unity.Editor/ScriptableSentryUnityOptionsEditor.cs @@ -30,9 +30,6 @@ public override void OnInspectorGUI() EditorGUILayout.TextField("Environment Override", options.EnvironmentOverride); EditorGUILayout.Toggle("Attach Stacktrace", options.AttachStacktrace); EditorGUILayout.Toggle("Attach Screenshot", options.AttachScreenshot); - EditorGUILayout.IntField("Screenshot Max Height", options.ScreenshotMaxHeight); - EditorGUILayout.IntField("Screenshot Max Width", options.ScreenshotMaxWidth); - EditorGUILayout.IntField("Screenshot Quality", options.ScreenshotQuality); EditorGUILayout.IntField("Max Breadcrumbs", options.MaxBreadcrumbs); EditorGUILayout.EnumPopup("Report Assemblies Mode", options.ReportAssembliesMode); EditorGUILayout.Toggle("Send Default Pii", options.SendDefaultPii); diff --git a/src/Sentry.Unity/ScreenshotAttachment.cs b/src/Sentry.Unity/ScreenshotAttachment.cs index 2ab9fb068..41097bfb9 100644 --- a/src/Sentry.Unity/ScreenshotAttachment.cs +++ b/src/Sentry.Unity/ScreenshotAttachment.cs @@ -1,10 +1,8 @@ using System; using System.IO; -using Sentry; using Sentry.Extensibility; using Sentry.Unity.Integrations; using UnityEngine; -using UnityEngine.Rendering; namespace Sentry.Unity { @@ -16,6 +14,9 @@ public ScreenshotAttachment(IAttachmentContent content) internal class ScreenshotAttachmentContent : IAttachmentContent { + private const int Quality = 75; + private const int MaxSize = 1920; + private readonly SentryMonoBehaviour _behaviour; private readonly SentryUnityOptions _options; @@ -42,17 +43,17 @@ public Stream GetStream() private byte[] CaptureScreenshot() { - // Calculate the desired size by calculating the ratio between the desired height/width and the actual one, - // and than resizing based on the smaller of the two ratios. + // Make sure the screenshot size does not exceed MaxSize by scaling the image while conserving the + // original ratio based on which, width or height, is the smaller var width = Screen.width; var height = Screen.height; - var ratioW = _options.ScreenshotMaxWidth <= 0 ? 1.0f : (float)_options.ScreenshotMaxWidth / (float)width; - var ratioH = _options.ScreenshotMaxHeight <= 0 ? 1.0f : (float)_options.ScreenshotMaxHeight / (float)height; + var ratioW = width <= MaxSize ? 1.0f : MaxSize / (float)width; + var ratioH = height <= MaxSize ? 1.0f : MaxSize / (float)height; var ratio = Mathf.Min(ratioH, ratioW); - if (ratio > 0.0f && ratio < 1.0f) + if (ratio is > 0.0f and < 1.0f) { - width = Mathf.FloorToInt((float)width * ratio); - height = Mathf.FloorToInt((float)height * ratio); + width = Mathf.FloorToInt(width * ratio); + height = Mathf.FloorToInt(height * ratio); } // Captures the current screenshot synchronously. @@ -71,11 +72,9 @@ private byte[] CaptureScreenshot() Graphics.Blit(rtFull, rtResized, new Vector2(1, -1), new Vector2(0, 1)); } RenderTexture.ReleaseTemporary(rtFull); - // Remember the previous render target and change it to our target texture. var previousRT = RenderTexture.active; RenderTexture.active = rtResized; - try { // actually copy from the current render target a texture & read data from the active RenderTexture @@ -88,7 +87,7 @@ private byte[] CaptureScreenshot() RenderTexture.active = previousRT; } - var bytes = screenshot.EncodeToJPG(_options.ScreenshotQuality); + var bytes = screenshot.EncodeToJPG(Quality); _options.DiagnosticLogger?.Log(SentryLevel.Debug, "Screenshot captured at {0}x{1}: {0} bytes", null, width, height, bytes.Length); return bytes; diff --git a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs index 3efe10bc7..498127580 100644 --- a/src/Sentry.Unity/ScriptableSentryUnityOptions.cs +++ b/src/Sentry.Unity/ScriptableSentryUnityOptions.cs @@ -39,9 +39,6 @@ public static string GetConfigPath(string? notDefaultConfigName = null) [field: SerializeField] public string EnvironmentOverride { get; set; } = string.Empty; [field: SerializeField] public bool AttachStacktrace { get; set; } [field: SerializeField] public bool AttachScreenshot { get; set; } - [field: SerializeField] public int ScreenshotMaxWidth { get; set; } - [field: SerializeField] public int ScreenshotMaxHeight { get; set; } - [field: SerializeField] public int ScreenshotQuality { get; set; } = 75; [field: SerializeField] public int MaxBreadcrumbs { get; set; } = Constants.DefaultMaxBreadcrumbs; [field: SerializeField] public ReportAssembliesMode ReportAssembliesMode { get; set; } = ReportAssembliesMode.Version; @@ -104,9 +101,6 @@ internal SentryUnityOptions ToSentryUnityOptions(bool isBuilding, ISentryUnityIn AutoSessionTrackingInterval = TimeSpan.FromMilliseconds(AutoSessionTrackingInterval), AttachStacktrace = AttachStacktrace, AttachScreenshot = AttachScreenshot, - ScreenshotMaxWidth = ScreenshotMaxWidth, - ScreenshotMaxHeight = ScreenshotMaxHeight, - ScreenshotQuality = ScreenshotQuality, MaxBreadcrumbs = MaxBreadcrumbs, ReportAssembliesMode = ReportAssembliesMode, SendDefaultPii = SendDefaultPii, diff --git a/src/Sentry.Unity/SentryUnityOptions.cs b/src/Sentry.Unity/SentryUnityOptions.cs index 95f6a6284..cb6db275e 100644 --- a/src/Sentry.Unity/SentryUnityOptions.cs +++ b/src/Sentry.Unity/SentryUnityOptions.cs @@ -71,23 +71,6 @@ public sealed class SentryUnityOptions : SentryOptions /// public bool AttachScreenshot { get; set; } = false; - /// - /// Maximum width of the screenshot or 0 to keep the original size. - /// If the application window is larger, the screenshot will be resized proportionally. - /// - public int ScreenshotMaxWidth { get; set; } = 0; - - /// - /// Maximum height of the screenshot or 0 to keep the original size. - /// If the application window is larger, the screenshot will be resized proportionally. - /// - public int ScreenshotMaxHeight { get; set; } = 0; - - /// - /// Quality of the JPG screenshot: 0 - 100, where 100 is the best quality and highest size. - /// - public int ScreenshotQuality { get; set; } = 75; - /// /// Whether the SDK should add native support for iOS /// diff --git a/test/Sentry.Unity.Editor.Tests/ScriptableSentryUnityOptionsTests.cs b/test/Sentry.Unity.Editor.Tests/ScriptableSentryUnityOptionsTests.cs index 4739b2ffd..6b3bfe23b 100644 --- a/test/Sentry.Unity.Editor.Tests/ScriptableSentryUnityOptionsTests.cs +++ b/test/Sentry.Unity.Editor.Tests/ScriptableSentryUnityOptionsTests.cs @@ -29,9 +29,6 @@ public void ScriptableSentryUnityOptions_Creation_AllPropertiesPresent() StringAssert.Contains("EnvironmentOverride", optionsAsString); StringAssert.Contains("AttachStacktrace", optionsAsString); StringAssert.Contains("AttachScreenshot", optionsAsString); - StringAssert.Contains("ScreenshotMaxWidth", optionsAsString); - StringAssert.Contains("ScreenshotMaxHeight", optionsAsString); - StringAssert.Contains("ScreenshotQuality", optionsAsString); StringAssert.Contains("MaxBreadcrumbs", optionsAsString); StringAssert.Contains("ReportAssembliesMode", optionsAsString); StringAssert.Contains("SendDefaultPii", optionsAsString); diff --git a/test/Sentry.Unity.Tests/ScriptableSentryUnityOptions.cs b/test/Sentry.Unity.Tests/ScriptableSentryUnityOptions.cs index 2663d656b..5ae431185 100644 --- a/test/Sentry.Unity.Tests/ScriptableSentryUnityOptions.cs +++ b/test/Sentry.Unity.Tests/ScriptableSentryUnityOptions.cs @@ -67,9 +67,6 @@ public void ToSentryUnityOptions_ValueMapping_AreEqual(bool isBuilding, bool ena AutoSessionTrackingInterval = TimeSpan.FromSeconds(1), AttachStacktrace = true, AttachScreenshot = true, - ScreenshotMaxWidth = 1, - ScreenshotMaxHeight = 1, - ScreenshotQuality = 1, MaxBreadcrumbs = 1, ReportAssembliesMode = ReportAssembliesMode.None, SendDefaultPii = true, @@ -96,9 +93,6 @@ public void ToSentryUnityOptions_ValueMapping_AreEqual(bool isBuilding, bool ena scriptableOptions.AutoSessionTrackingInterval = (int)expectedOptions.AutoSessionTrackingInterval.TotalMilliseconds; scriptableOptions.AttachStacktrace = expectedOptions.AttachStacktrace; scriptableOptions.AttachScreenshot = expectedOptions.AttachScreenshot; - scriptableOptions.ScreenshotMaxWidth = expectedOptions.ScreenshotMaxWidth; - scriptableOptions.ScreenshotMaxHeight = expectedOptions.ScreenshotMaxHeight; - scriptableOptions.ScreenshotQuality = expectedOptions.ScreenshotQuality; scriptableOptions.MaxBreadcrumbs = expectedOptions.MaxBreadcrumbs; scriptableOptions.ReportAssembliesMode = expectedOptions.ReportAssembliesMode; scriptableOptions.SendDefaultPii = expectedOptions.SendDefaultPii; @@ -159,9 +153,6 @@ public static void AssertOptions(SentryUnityOptions expected, SentryUnityOptions Assert.AreEqual(expected.AutoSessionTrackingInterval, actual.AutoSessionTrackingInterval); Assert.AreEqual(expected.AttachStacktrace, actual.AttachStacktrace); Assert.AreEqual(expected.AttachScreenshot, actual.AttachScreenshot); - Assert.AreEqual(expected.ScreenshotMaxWidth, actual.ScreenshotMaxWidth); - Assert.AreEqual(expected.ScreenshotMaxHeight, actual.ScreenshotMaxHeight); - Assert.AreEqual(expected.ScreenshotQuality, actual.ScreenshotQuality); Assert.AreEqual(expected.MaxBreadcrumbs, actual.MaxBreadcrumbs); Assert.AreEqual(expected.ReportAssembliesMode, actual.ReportAssembliesMode); Assert.AreEqual(expected.SendDefaultPii, actual.SendDefaultPii);