From 69c6021d3a43f4c38701cb3814e72d4c3afe5f21 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Wed, 18 May 2022 16:41:11 +0900 Subject: [PATCH] fix: Install/uninstall package via UPMClient instead of updating manifest.json directly --- .../GitPackageDataBase.cs | 30 ++++--------------- .../UI/GitPackageInstallationWindow.cs | 14 +++++++++ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/Editor/Coffee.UpmGitExtension/GitPackageDataBase.cs b/Editor/Coffee.UpmGitExtension/GitPackageDataBase.cs index 0f83289..7ebb29b 100644 --- a/Editor/Coffee.UpmGitExtension/GitPackageDataBase.cs +++ b/Editor/Coffee.UpmGitExtension/GitPackageDataBase.cs @@ -55,16 +55,15 @@ internal class GitPackageDatabase : ScriptableSingleton // public static event Action OnChangedPackages; public static void Install(string packageId) + { + _upmClient.AddByUrl(packageId); + } + + public static void Uninstall(string packageId) { var i = packageId.IndexOf('@'); var packageName = packageId.Substring(0, i); - var url = packageId.Substring(i + 1); - UpdateJson("Packages/manifest.json", jsonDic => - { - // Add to dependencies. - var dependencies = jsonDic["dependencies"] as Dictionary; - dependencies[packageName] = url; - }); + _upmClient.RemoveByName(packageName); } public static IEnumerable GetUpmPackages() @@ -193,23 +192,6 @@ public static IEnumerable GetAvailablePackageVersions(strin private static bool _enablePreReleasePackages => _settings.enablePreviewPackages; #endif - private static void UpdateJson(string path, Action> action) - { - if (!File.Exists(path)) return; - - try - { - var jsonDic = Json.Deserialize(File.ReadAllText(path)) as Dictionary; - action?.Invoke(jsonDic); - File.WriteAllText(path, Json.Serialize(jsonDic, true)); - EditorApplication.delayCall += () => UnityEditor.PackageManager.Client.Resolve(); - } - catch (Exception e) - { - UnityEngine.Debug.LogException(e); - } - } - private static void RequestUpdateGitPackageVersions() { EditorApplication.delayCall -= UpdateGitPackageVersions; diff --git a/Editor/Coffee.UpmGitExtension/UI/GitPackageInstallationWindow.cs b/Editor/Coffee.UpmGitExtension/UI/GitPackageInstallationWindow.cs index 9edba8b..12298bc 100644 --- a/Editor/Coffee.UpmGitExtension/UI/GitPackageInstallationWindow.cs +++ b/Editor/Coffee.UpmGitExtension/UI/GitPackageInstallationWindow.cs @@ -76,10 +76,24 @@ public GitPackageInstallationWindow() root.Add(new SearchResultListView(_repoUrlText, () => GitPackageDatabase.GetCachedRepositoryUrls())); OnClick_Close(); + + // + GitPackageDatabase._upmClient.onAddOperation += op => { + _loadingSpinner.Start(); + _rootContainer.SetEnabled(false); + + op.onOperationFinalized += _ => + { + _loadingSpinner.Stop(); + _rootContainer.SetEnabled(true); + OnClick_Close(); + }; + }; } public void Open() { + _loadingSpinner.Stop(); UIUtils.SetElementDisplay(this, true); SetState(State.None);