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

Commit e1f42ce

Browse files
authored
Merge pull request #423 from github-for-unity/fixes/init-proj-view-spam
A simpler data update method to avoid spamming GitClient
2 parents cd75172 + fca75da commit e1f42ce

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class UserSettingsView : Subview
2222
[SerializeField] private string gitEmail;
2323
[SerializeField] private string newGitName;
2424
[SerializeField] private string newGitEmail;
25-
[SerializeField] private User cachedUser;
2625

2726
public override void InitializeView(IView parent)
2827
{
@@ -63,15 +62,11 @@ public override void OnGUI()
6362
{
6463
if (Repository != null)
6564
{
66-
Repository.User.Name = newGitName;
65+
Repository.User.Name = gitName = newGitName;
6766
}
6867
else
6968
{
70-
if (cachedUser == null)
71-
{
72-
cachedUser = new User();
73-
}
74-
cachedUser.Name = newGitName;
69+
gitName = newGitName;
7570
}
7671
}
7772
})
@@ -83,11 +78,11 @@ public override void OnGUI()
8378
{
8479
if (Repository != null)
8580
{
86-
Repository.User.Email = newGitEmail;
81+
Repository.User.Email = gitEmail = newGitEmail;
8782
}
8883
else
8984
{
90-
cachedUser.Email = newGitEmail;
85+
gitEmail = newGitEmail;
9186
}
9287

9388
userDataHasChanged = true;
@@ -107,43 +102,53 @@ public override void OnGUI()
107102
EditorGUI.EndDisabledGroup();
108103
}
109104

105+
public override void OnEnable()
106+
{
107+
base.OnEnable();
108+
userDataHasChanged = true;
109+
}
110+
110111
private void MaybeUpdateData()
111112
{
112-
if (Repository == null)
113+
if (userDataHasChanged)
113114
{
114-
if (!String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
115+
userDataHasChanged = false;
116+
117+
if (Repository == null)
115118
{
116-
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
117-
{
118-
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, user) => {
119-
if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email))
120-
{
121-
cachedUser = user;
122-
123-
userDataHasChanged = true;
124-
Redraw();
125-
}
126-
}).Start();
127-
}
119+
UpdateUserDataFromClient();
128120
}
129-
130-
if (userDataHasChanged)
121+
else
131122
{
132-
newGitName = gitName = cachedUser.Name;
133-
newGitEmail = gitEmail = cachedUser.Email;
134-
userDataHasChanged = false;
123+
newGitName = gitName = Repository.User.Name;
124+
newGitEmail = gitEmail = Repository.User.Email;
135125
}
136-
return;
137126
}
127+
}
138128

139-
userDataHasChanged = Repository.User.Name != gitName || Repository.User.Email != gitEmail;
129+
private void UpdateUserDataFromClient()
130+
{
131+
if (String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
132+
{
133+
return;
134+
}
140135

141-
if (!userDataHasChanged)
136+
if (GitClient == null)
137+
{
142138
return;
139+
}
140+
141+
Logger.Trace("Update user data from GitClient");
143142

144-
userDataHasChanged = false;
145-
newGitName = gitName = Repository.User.Name;
146-
newGitEmail = gitEmail = Repository.User.Email;
143+
GitClient.GetConfigUserAndEmail()
144+
.ThenInUI((success, user) => {
145+
if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email))
146+
{
147+
newGitName = gitName = user.Name;
148+
newGitEmail = gitEmail = user.Email;
149+
Redraw();
150+
}
151+
}).Start();
147152
}
148153

149154
public override bool IsBusy

0 commit comments

Comments
 (0)