Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #423 from github-for-unity/fixes/init-proj-view-spam
Browse files Browse the repository at this point in the history
A simpler data update method to avoid spamming GitClient
  • Loading branch information
shana authored Nov 10, 2017
2 parents cd75172 + fca75da commit e1f42ce
Showing 1 changed file with 39 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class UserSettingsView : Subview
[SerializeField] private string gitEmail;
[SerializeField] private string newGitName;
[SerializeField] private string newGitEmail;
[SerializeField] private User cachedUser;

public override void InitializeView(IView parent)
{
Expand Down Expand Up @@ -63,15 +62,11 @@ public override void OnGUI()
{
if (Repository != null)
{
Repository.User.Name = newGitName;
Repository.User.Name = gitName = newGitName;
}
else
{
if (cachedUser == null)
{
cachedUser = new User();
}
cachedUser.Name = newGitName;
gitName = newGitName;
}
}
})
Expand All @@ -83,11 +78,11 @@ public override void OnGUI()
{
if (Repository != null)
{
Repository.User.Email = newGitEmail;
Repository.User.Email = gitEmail = newGitEmail;
}
else
{
cachedUser.Email = newGitEmail;
gitEmail = newGitEmail;
}

userDataHasChanged = true;
Expand All @@ -107,43 +102,53 @@ public override void OnGUI()
EditorGUI.EndDisabledGroup();
}

public override void OnEnable()
{
base.OnEnable();
userDataHasChanged = true;
}

private void MaybeUpdateData()
{
if (Repository == null)
if (userDataHasChanged)
{
if (!String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
userDataHasChanged = false;

if (Repository == null)
{
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
{
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, user) => {
if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email))
{
cachedUser = user;

userDataHasChanged = true;
Redraw();
}
}).Start();
}
UpdateUserDataFromClient();
}

if (userDataHasChanged)
else
{
newGitName = gitName = cachedUser.Name;
newGitEmail = gitEmail = cachedUser.Email;
userDataHasChanged = false;
newGitName = gitName = Repository.User.Name;
newGitEmail = gitEmail = Repository.User.Email;
}
return;
}
}

userDataHasChanged = Repository.User.Name != gitName || Repository.User.Email != gitEmail;
private void UpdateUserDataFromClient()
{
if (String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
{
return;
}

if (!userDataHasChanged)
if (GitClient == null)
{
return;
}

Logger.Trace("Update user data from GitClient");

userDataHasChanged = false;
newGitName = gitName = Repository.User.Name;
newGitEmail = gitEmail = Repository.User.Email;
GitClient.GetConfigUserAndEmail()
.ThenInUI((success, user) => {
if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email))
{
newGitName = gitName = user.Name;
newGitEmail = gitEmail = user.Email;
Redraw();
}
}).Start();
}

public override bool IsBusy
Expand Down

0 comments on commit e1f42ce

Please sign in to comment.