Skip to content

draft: Hook for package installation trigger #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
64 changes: 64 additions & 0 deletions src/Sentry.Unity.Editor/SentryAssetPostProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Linq;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;

namespace Sentry.Unity.Editor
{
public class SentryAssetPostProcessor : AssetPostprocessor
{
private static ListRequest? _listRequest;

private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
string[] movedAssets, string[] movedFromAssetPaths)
{
// TODO: maybe filter for Packages/io.sentry?
var isPackageImport = importedAssets.Any(path => path.StartsWith("Packages/"));

if (isPackageImport)
{
_listRequest = Client.List(true);
EditorApplication.update += UpdateListRequest;
}
}

[MenuItem("Tools/TempPackageImport")]
static void TempPackageImport()
{
_listRequest = Client.List(true);
EditorApplication.update += UpdateListRequest;
}

private static void UpdateListRequest()
{
if (_listRequest is null)
{
EditorApplication.update -= UpdateListRequest;
return;
}

if (!_listRequest.IsCompleted)
{
return;
}

if (_listRequest.Status == StatusCode.Success)
{
foreach (var package in _listRequest.Result)
{
if (package.name == SentryPackageInfo.GetName())
{
Debug.Log("Found the Sentry package!");
// TODO: here we create the link.xml and the options and whatever else
}
}
}
else
{
}

EditorApplication.update -= UpdateListRequest;
}
}
}
4 changes: 2 additions & 2 deletions src/Sentry.Unity.Editor/SentryPackageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Sentry.Unity.Editor
{
public static class SentryPackageInfo
internal static class SentryPackageInfo
{
internal static string PackageName = "io.sentry.unity";
internal static string PackageNameDev = "io.sentry.unity.dev";

internal static string GetName()
public static string GetName()
{
var packagePath = Path.Combine("Packages", PackageName);
if (Directory.Exists(Path.Combine(packagePath)))
Expand Down