Skip to content
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

SDK-145 chore: added timeout #70

Merged
merged 1 commit into from
May 5, 2023
Merged
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
13 changes: 11 additions & 2 deletions Editor/Module Management/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using UnityEditor.Compilation;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEngine;
using PackageInfo = UnityEditor.PackageManager.PackageInfo;

namespace ReadyPlayerMe.Core.Editor
Expand All @@ -30,6 +31,8 @@ public static class ModuleInstaller
private const string ALL_MODULES_ARE_INSTALLED = "All modules are installed.";
private const string INSTALLING_MODULES = "Installing modules...";

private const float TIMEOUT_FOR_MODULE_INSTALLATION = 20f;

static ModuleInstaller()
{
Events.registeredPackages += OnRegisteredPackages;
Expand Down Expand Up @@ -102,15 +105,21 @@ private static void InstallModules()
/// <param name="identifier">The Unity package identifier of the module to be installed.</param>
public static void AddModuleRequest(string identifier)
{
var startTime = Time.realtimeSinceStartup;
AddRequest addRequest = Client.Add(identifier);
while (!addRequest.IsCompleted)
while (!addRequest.IsCompleted && Time.realtimeSinceStartup - startTime < TIMEOUT_FOR_MODULE_INSTALLATION)
Thread.Sleep(THREAD_SLEEP_TIME);


if (Time.realtimeSinceStartup - startTime >= TIMEOUT_FOR_MODULE_INSTALLATION)
{
Debug.LogError($"Package installation timed out for {identifier}. Please try again.");
}
if (addRequest.Error != null)
{
AssetDatabase.Refresh();
CompilationPipeline.RequestScriptCompilation();
SDKLogger.Log(TAG, "Error: " + addRequest.Error.message);
Debug.LogError("Error: " + addRequest.Error.message);
}
}

Expand Down