Skip to content

Commit

Permalink
fix: newer packages version not updating unless restarting editor
Browse files Browse the repository at this point in the history
close #121
  • Loading branch information
mob-sakai committed Jun 18, 2022
1 parent b46e7ef commit 0c7179d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Editor/Coffee.UpmGitExtension/GitPackageDataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ public static void ClearCache()
WatchResultJson();
}

public static void ResetCacheTime()
{
isPaused = true;
var resultDir = Path.GetFullPath(_resultsDir);
foreach (var file in Directory.GetFiles(resultDir, "*.json"))
{
File.SetLastWriteTime(file, DateTime.Now.AddMinutes(-10));
Debug.Log($"ResetCacheTime: {file}");
}
isPaused = false;
}

public static IEnumerable<UpmPackageVersionEx> GetAvailablePackageVersions(string packageId = null, string repoUrl = null, bool preRelease = false)
{
return _resultCaches
Expand All @@ -174,6 +186,7 @@ public static IEnumerable<UpmPackageVersionEx> GetAvailablePackageVersions(strin
private static string _serializeVersion => "2.0.0";
private static string _resultsDir => _workingDirectory + "/Results-" + _serializeVersion;
private static FileSystemWatcher _watcher;
private static bool isPaused;
private static readonly HashSet<FetchResult> _resultCaches = new HashSet<FetchResult>();
private static PackageManagerProjectSettings _settings => ScriptableSingleton<PackageManagerProjectSettings>.instance;
#if UNITY_2020_2_OR_NEWER
Expand Down Expand Up @@ -256,7 +269,7 @@ private static void UpdateGitPackageVersions()

private static void OnResultFileCreated(string file)
{
if (string.IsNullOrEmpty(file) || Path.GetExtension(file) != ".json" || !File.Exists(file))
if (isPaused || string.IsNullOrEmpty(file) || Path.GetExtension(file) != ".json" || !File.Exists(file))
return;

try
Expand Down
2 changes: 2 additions & 0 deletions Editor/Coffee.UpmGitExtension/UpmGitExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ private void Initialize()
// Setup toolbar menus
OnPackageManagerToolbarSetup(root.Q<PackageManagerToolbar>());
#endif
var refleshButton = root.Q<VisualElement>("refreshButton").Get("m_Clickable") as Clickable;
refleshButton.clicked += GitPackageDatabase.ResetCacheTime;
}
}
}

0 comments on commit 0c7179d

Please sign in to comment.