Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Sentry.Unity.Editor/SentryAssetPostprocessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Linq;
using System.Threading;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEngine;

namespace Sentry.Unity.Editor
{
public class SentryAssetPostprocessor : AssetPostprocessor
{
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
var imported = importedAssets.Any(path => path.StartsWith("Packages/"));
var deleted = deletedAssets.Any(path => path.StartsWith("Packages/"));

if (imported || deleted)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to prompt also when asset deleted? I wonder the chance of false positive here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not a prompt but maybe we should delete the assets we create too? Like link.xml and the options file?

{
InitializeOnLoad();
}
}

/**
* Instead of hooking into AssetPostprocessing we could InitializeOnLoad
* But this gets called on domain reload (i.e. enter playmode) and could be disabled by the user.
*/
// [InitializeOnLoadMethod]
private static void InitializeOnLoad()
{
// ASYNC! Fetching all packages the current project depends on
var listRequest = Client.List(true);
while (!listRequest.IsCompleted)
{
Thread.Sleep(100);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might freeze up the editor though, right?
Can we schedule the continuation to run async too? If this was TPL it would be listRequest.ContinuesWith(p => .. but I'm not sure the type here (need to load the editor to do a proper review).

}

if (listRequest.Error != null)
{
Debug.Log("Error: " + listRequest.Error.message);
return;
}

var packages = listRequest.Result;
foreach (var package in packages)
{
if (package.name.StartsWith("io.sentry"))
{
SentryGettingStartedWindow.OpenWindow();
}
}
}
}
}
39 changes: 39 additions & 0 deletions src/Sentry.Unity.Editor/SentryGettingStartedWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using UnityEditor;
using UnityEngine;

namespace Sentry.Unity.Editor
{
public class SentryGettingStartedWindow : EditorWindow
{
private string? _dsn;

[MenuItem("Tools/Sentry/Getting Started")]
public static SentryGettingStartedWindow OpenWindow()
=> (SentryGettingStartedWindow)GetWindow(
typeof(SentryGettingStartedWindow), true, "Sentry Getting Started Window");

private void OnGUI()
{
EditorGUILayout.Space();

GUILayout.Label("All that you need to get started is to provide a DSN.");

EditorGUILayout.Space();
EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), Color.gray);
EditorGUILayout.Space();

_dsn = EditorGUILayout.TextField(
new GUIContent("DSN", "The URL to your project inside Sentry. Get yours in Sentry, Project Settings."),
_dsn);

EditorGUILayout.Space();
EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 1), Color.gray);
EditorGUILayout.Space();

if (GUILayout.Button("Enable"))
{
this.Close();
}
}
}
}