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

Commit 35dcc1a

Browse files
A simpler data update method to avoid spamming GitClient
1 parent 985c390 commit 35dcc1a

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

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

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -107,49 +107,57 @@ public override void OnGUI()
107107
EditorGUI.EndDisabledGroup();
108108
}
109109

110+
public override void OnEnable()
111+
{
112+
base.OnEnable();
113+
userDataHasChanged = true;
114+
}
115+
110116
private void MaybeUpdateData()
111117
{
112-
if (Repository == null)
118+
if (userDataHasChanged)
113119
{
114-
if (!String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
120+
userDataHasChanged = false;
121+
122+
if (Repository == null)
115123
{
116-
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
117-
{
118-
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
119-
var username = strings[0];
120-
var email = strings[1];
121-
122-
if (success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email))
123-
{
124-
cachedUser = new User {
125-
Name = username,
126-
Email = email
127-
};
128-
129-
userDataHasChanged = true;
130-
Redraw();
131-
}
132-
}).Start();
133-
}
124+
UpdateUserDataFromClient();
134125
}
135-
136-
if (userDataHasChanged)
126+
else
137127
{
138-
newGitName = gitName = cachedUser.Name;
139-
newGitEmail = gitEmail = cachedUser.Email;
140-
userDataHasChanged = false;
128+
newGitName = gitName = Repository.User.Name;
129+
newGitEmail = gitEmail = Repository.User.Email;
141130
}
142-
return;
143131
}
132+
}
144133

145-
userDataHasChanged = Repository.User.Name != gitName || Repository.User.Email != gitEmail;
134+
private void UpdateUserDataFromClient()
135+
{
136+
if (String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
137+
{
138+
return;
139+
}
146140

147-
if (!userDataHasChanged)
141+
if (GitClient == null)
142+
{
148143
return;
144+
}
149145

150-
userDataHasChanged = false;
151-
newGitName = gitName = Repository.User.Name;
152-
newGitEmail = gitEmail = Repository.User.Email;
146+
Logger.Trace("Update user data from GitClient");
147+
148+
GitClient.GetConfigUserAndEmail()
149+
.ThenInUI((success, strings) => {
150+
var username = strings[0];
151+
var email = strings[1];
152+
153+
if (success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email))
154+
{
155+
cachedUser = new User { Name = username, Email = email };
156+
newGitName = gitName = cachedUser.Name;
157+
newGitEmail = gitEmail = cachedUser.Email;
158+
Redraw();
159+
}
160+
}).Start();
153161
}
154162

155163
public override bool IsBusy

0 commit comments

Comments
 (0)