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

Commit 80539f9

Browse files
Fixes to support initliazing the user before the project
1 parent 40baef1 commit 80539f9

File tree

3 files changed

+111
-24
lines changed

3 files changed

+111
-24
lines changed

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

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
#pragma warning disable 649
2-
31
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
62
using UnityEditor;
73
using UnityEngine;
8-
using Object = UnityEngine.Object;
94

105
namespace GitHub.Unity
116
{
@@ -16,7 +11,25 @@ class InitProjectView : Subview
1611
private const string NoRepoDescription = "Initialize a Git repository to track changes and collaborate with others.";
1712

1813
[SerializeField] private bool isBusy;
19-
[SerializeField] private bool isPublished;
14+
[SerializeField] private bool isUserDataPresent = true;
15+
16+
[NonSerialized] private bool userDataHasChanged;
17+
18+
public override void InitializeView(IView parent)
19+
{
20+
base.InitializeView(parent);
21+
22+
if (!string.IsNullOrEmpty(Environment.GitExecutablePath))
23+
{
24+
CheckForUser();
25+
}
26+
}
27+
28+
public override void OnEnable()
29+
{
30+
base.OnEnable();
31+
userDataHasChanged = Environment.GitExecutablePath != null;
32+
}
2033

2134
public override void OnDataUpdate()
2235
{
@@ -68,14 +81,33 @@ public override void OnGUI()
6881

6982
GUILayout.BeginVertical(Styles.GenericBoxStyle);
7083
{
84+
if (!isUserDataPresent)
85+
{
86+
GUILayout.FlexibleSpace();
87+
88+
EditorGUI.BeginDisabledGroup(isBusy);
89+
{
90+
if (GUILayout.Button("Finish Git Configuration", "Button"))
91+
{
92+
PopupWindow.Open(PopupWindow.PopupViewType.UserSettingsView, completed => {
93+
if (completed)
94+
{
95+
userDataHasChanged = true;
96+
}
97+
});
98+
}
99+
}
100+
EditorGUI.EndDisabledGroup();
101+
}
102+
71103
GUILayout.FlexibleSpace();
72104

73105
GUILayout.Label(NoRepoDescription, Styles.CenteredLabel);
74106

75107
GUILayout.BeginHorizontal();
76108
GUILayout.FlexibleSpace();
77109

78-
EditorGUI.BeginDisabledGroup(isBusy);
110+
EditorGUI.BeginDisabledGroup(isBusy || !isUserDataPresent);
79111
{
80112
if (GUILayout.Button(Localization.InitializeRepositoryButtonText, "Button"))
81113
{
@@ -97,7 +129,42 @@ public override void OnGUI()
97129

98130
private void MaybeUpdateData()
99131
{
100-
isPublished = Repository != null && Repository.CurrentRemote.HasValue;
132+
if (userDataHasChanged)
133+
{
134+
userDataHasChanged = false;
135+
CheckForUser();
136+
}
137+
}
138+
139+
private void CheckForUser()
140+
{
141+
isBusy = true;
142+
143+
string username = null;
144+
string email = null;
145+
146+
GitClient.GetConfig("user.name", GitConfigSource.User).Then((success, value) => {
147+
Logger.Trace("Return success:{0} user.name", success, value);
148+
if (success)
149+
{
150+
username = value;
151+
}
152+
}).Then(GitClient.GetConfig("user.email", GitConfigSource.User).Then((success, value) => {
153+
Logger.Trace("Return success:{0} user.email", success, value);
154+
if (success)
155+
{
156+
email = value;
157+
}
158+
})).FinallyInUI((success, ex) => {
159+
Logger.Trace("Return success:{0} name:{1} email:{2}", success, username, email);
160+
161+
isBusy = false;
162+
isUserDataPresent = success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email);
163+
164+
Logger.Trace("Finally: {0}", isUserDataPresent);
165+
166+
Redraw();
167+
}).Start();
101168
}
102169
}
103170
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ public enum PopupViewType
1111
{
1212
None,
1313
PublishView,
14-
AuthenticationView
14+
AuthenticationView,
15+
UserSettingsView
1516
}
1617

1718
[SerializeField] private PopupViewType activeViewType;
1819

1920
[SerializeField] private AuthenticationView authenticationView;
21+
[SerializeField] private UserSettingsView userSettingsView;
2022
[SerializeField] private PublishView publishView;
2123
[SerializeField] private LoadingView loadingView;
2224

@@ -52,10 +54,12 @@ public override void Initialize(IApplicationManager applicationManager)
5254
{
5355
base.Initialize(applicationManager);
5456

57+
userSettingsView = userSettingsView ?? new UserSettingsView();
5558
publishView = publishView ?? new PublishView();
5659
authenticationView = authenticationView ?? new AuthenticationView();
5760
loadingView = loadingView ?? new LoadingView();
5861

62+
userSettingsView.InitializeView(this);
5963
publishView.InitializeView(this);
6064
authenticationView.InitializeView(this);
6165
loadingView.InitializeView(this);
@@ -123,6 +127,8 @@ private Subview ActiveView
123127
return publishView;
124128
case PopupViewType.AuthenticationView:
125129
return authenticationView;
130+
case PopupViewType.UserSettingsView:
131+
return userSettingsView;
126132
default:
127133
return loadingView;
128134
}

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ namespace GitHub.Unity
1111
[Serializable]
1212
class UserSettingsView : Subview
1313
{
14+
private static readonly Vector2 viewSize = new Vector2(325, 125);
15+
private const string WindowTitle = "User Settings";
16+
1417
private const string GitConfigTitle = "Git Configuration";
1518
private const string GitConfigNameLabel = "Name";
1619
private const string GitConfigEmailLabel = "Email";
@@ -26,6 +29,13 @@ class UserSettingsView : Subview
2629
[SerializeField] private string newGitEmail;
2730
[SerializeField] private User cachedUser;
2831

32+
public override void InitializeView(IView parent)
33+
{
34+
base.InitializeView(parent);
35+
Title = WindowTitle;
36+
Size = viewSize;
37+
}
38+
2939
public override void OnDataUpdate()
3040
{
3141
base.OnDataUpdate();
@@ -99,6 +109,7 @@ public override void OnGUI()
99109
{
100110
isBusy = false;
101111
Redraw();
112+
Finish(true);
102113
})
103114
.Start();
104115
}
@@ -117,23 +128,26 @@ private void MaybeUpdateData()
117128
{
118129
if (Repository == null)
119130
{
120-
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
131+
if (!String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath))
121132
{
122-
var user = new User();
123-
GitClient.GetConfig("user.name", GitConfigSource.User)
124-
.Then((success, value) => user.Name = value).Then(
125-
GitClient.GetConfig("user.email", GitConfigSource.User)
126-
.Then((success, value) => user.Email = value))
127-
.FinallyInUI((success, ex) =>
133+
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
128134
{
129-
if (success && !String.IsNullOrEmpty(user.Name))
130-
{
131-
cachedUser = user;
132-
userDataHasChanged = true;
133-
Redraw();
134-
}
135-
})
136-
.Start();
135+
var user = new User();
136+
GitClient.GetConfig("user.name", GitConfigSource.User)
137+
.Then((success, value) => user.Name = value).Then(
138+
GitClient.GetConfig("user.email", GitConfigSource.User)
139+
.Then((success, value) => user.Email = value))
140+
.FinallyInUI((success, ex) =>
141+
{
142+
if (success && !String.IsNullOrEmpty(user.Name))
143+
{
144+
cachedUser = user;
145+
userDataHasChanged = true;
146+
Redraw();
147+
}
148+
})
149+
.Start();
150+
}
137151
}
138152

139153
if (userDataHasChanged)

0 commit comments

Comments
 (0)