diff --git a/Packages/io.chainsafe.web3-unity/Editor/WebGLThreadPatcherInstaller.cs b/Packages/io.chainsafe.web3-unity/Editor/WebGLThreadPatcherInstaller.cs index c9c65130e..8f1a246c5 100644 --- a/Packages/io.chainsafe.web3-unity/Editor/WebGLThreadPatcherInstaller.cs +++ b/Packages/io.chainsafe.web3-unity/Editor/WebGLThreadPatcherInstaller.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using UnityEditor; using UnityEngine; @@ -17,7 +18,7 @@ public static class WebGLThreadPatcherInstaller private const string AsyncToolPackageLink = "https://github.com/RageAgainstThePixel/com.utilities.async.git#upm"; static WebGLThreadPatcherInstaller() - { + { #if UNITY_WEBGL if (SessionState.GetBool(AsyncToolsInstalled, false)) { @@ -36,47 +37,48 @@ static WebGLThreadPatcherInstaller() [MenuItem("ChainSafe SDK/Install WebGLThreadingPatcher", priority = 0)] public static void TryInstallThreadPatcher() { - Manifest manifest = JsonConvert.DeserializeObject(File.ReadAllText(ManifestPath)); - + string json = File.ReadAllText(ManifestPath); + + Manifest manifest = JsonConvert.DeserializeObject(json); + // check if ThreadPatcher is already installed. if (manifest.Dependencies.ContainsKey(AsyncToolsPackageName)) { return; } - - if (EditorUtility.DisplayDialog("Web3.Unity", "For Web3.Unity to fully work on a WebGL build you need to install Async Utilities, this will make sure async operations can run to completion.\nInstall Async Utilities?", "Yes", "No")) + + if (EditorUtility.DisplayDialog("Web3.Unity", + "For Web3.Unity to fully work on a WebGL build you need to install Async Utilities, this will make sure async operations can run to completion.\nInstall Async Utilities?", + "Yes", "No")) { - // Add the package as a dependency. - manifest.Dependencies.Add(AsyncToolsPackageName, AsyncToolPackageLink); - - File.WriteAllText(ManifestPath, JsonConvert.SerializeObject(manifest, Formatting.Indented)); + try + { + var parsed = JObject.Parse(json); + + parsed.Merge(JObject.Parse(JsonConvert.SerializeObject(new Manifest(new Dictionary() + { + { AsyncToolsPackageName, AsyncToolPackageLink } + })))); + + File.WriteAllText(ManifestPath, parsed.ToString(Formatting.Indented)); + } + catch (Exception e) + { + Debug.LogError($"Error adding {AsyncToolsPackageName} package. {e}"); + + throw; + } } } private class Manifest { - [JsonProperty("dependencies")] + [JsonProperty("dependencies", DefaultValueHandling = DefaultValueHandling.Ignore)] public Dictionary Dependencies { get; private set; } - [JsonProperty("enableLockFile")] - public bool EnableLockFile { get; private set; } = true; - - [JsonProperty("resolutionStrategy", DefaultValueHandling = DefaultValueHandling.Ignore)] - public string ResolutionStrategy { get; private set; } - - [JsonProperty("testables", DefaultValueHandling = DefaultValueHandling.Ignore)] - public string[] Testables { get; private set; } - - [JsonProperty("scopedRegistries", DefaultValueHandling = DefaultValueHandling.Ignore)] - public ScopedRegistry[] ScopedRegistries { get; private set; } - } - - public struct ScopedRegistry - { - [JsonProperty("name")] public string Name { get; private set; } - - [JsonProperty("url")] public string Url { get; private set; } - - [JsonProperty("scopes")] public string[] Scopes { get; private set; } + public Manifest(Dictionary dependencies) + { + Dependencies = dependencies; + } } } \ No newline at end of file diff --git a/src/UnitySampleProject/Packages/manifest.json b/src/UnitySampleProject/Packages/manifest.json index f2904dc2d..f33c904e0 100644 --- a/src/UnitySampleProject/Packages/manifest.json +++ b/src/UnitySampleProject/Packages/manifest.json @@ -1,6 +1,5 @@ { "dependencies": { - "com.tools.webglthreadingpatcher": "https://github.com/VolodymyrBS/WebGLThreadingPatcher.git", "com.unity.collab-proxy": "2.4.4", "com.unity.ide.rider": "3.0.31", "com.unity.ide.visualstudio": "2.0.22", diff --git a/src/UnitySampleProject/Packages/packages-lock.json b/src/UnitySampleProject/Packages/packages-lock.json index 29aa850c5..d9ef3873e 100644 --- a/src/UnitySampleProject/Packages/packages-lock.json +++ b/src/UnitySampleProject/Packages/packages-lock.json @@ -1,14 +1,5 @@ { "dependencies": { - "com.tools.webglthreadingpatcher": { - "version": "https://github.com/VolodymyrBS/WebGLThreadingPatcher.git", - "depth": 0, - "source": "git", - "dependencies": { - "nuget.mono-cecil": "0.1.6-preview" - }, - "hash": "c2f3628a028373afc8c66e443f7ce21bcb613a47" - }, "com.unity.collab-proxy": { "version": "2.4.4", "depth": 0, @@ -228,14 +219,6 @@ "io.chainsafe.web3-unity": "2.6.0" } }, - "nuget.mono-cecil": { - "version": "1.0.0", - "depth": 1, - "source": "builtin", - "dependencies": { - "com.unity.nuget.mono-cecil": "1.10.1" - } - }, "com.unity.modules.ai": { "version": "1.0.0", "depth": 0,