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

Commit 58cb052

Browse files
committed
AuthenticationView can handle its own message logic
1 parent 8b260dd commit 58cb052

File tree

2 files changed

+21
-63
lines changed

2 files changed

+21
-63
lines changed

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

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class AuthenticationView : Subview
99
{
1010
private static readonly Vector2 viewSize = new Vector2(290, 290);
1111

12+
private const string CredentialsNeedRefreshMessage = "We've detected that your stored credentials are out of sync with your current user. This can happen if you have signed in to git outside of Unity. Sign in again to refresh your credentials.";
13+
private const string NeedAuthenticationMessage = "We need you to authenticate first";
1214
private const string WindowTitle = "Authenticate";
1315
private const string UsernameLabel = "Username";
1416
private const string PasswordLabel = "Password";
@@ -41,14 +43,25 @@ public override void InitializeView(IView parent)
4143
Size = viewSize;
4244
}
4345

44-
public override void OnEnable()
46+
public void Initialize(Exception exception)
4547
{
46-
base.OnEnable();
47-
}
48+
var usernameMismatchException = exception as TokenUsernameMismatchException;
49+
if (usernameMismatchException != null)
50+
{
51+
message = CredentialsNeedRefreshMessage;
52+
username = usernameMismatchException.CachedUsername;
53+
}
4854

49-
public override void OnDisable()
50-
{
51-
base.OnDisable();
55+
var keychainEmptyException = exception as KeychainEmptyException;
56+
if (keychainEmptyException != null)
57+
{
58+
message = NeedAuthenticationMessage;
59+
}
60+
61+
if (usernameMismatchException == null && keychainEmptyException == null)
62+
{
63+
message = exception.Message;
64+
}
5265
}
5366

5467
public override void OnGUI()
@@ -81,27 +94,7 @@ public override void OnGUI()
8194
}
8295
GUILayout.EndScrollView();
8396
}
84-
85-
public void SetMessage(string value)
86-
{
87-
message = value;
88-
}
89-
90-
public void ClearMessage()
91-
{
92-
message = null;
93-
}
94-
95-
public void SetUsername(string value)
96-
{
97-
username = value;
98-
}
99-
100-
public void ClearUsername()
101-
{
102-
username = string.Empty;
103-
}
104-
97+
10598
private void HandleEnterPressed()
10699
{
107100
if (Event.current.type != EventType.KeyDown)

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ namespace GitHub.Unity
77
[Serializable]
88
class PopupWindow : BaseWindow
99
{
10-
private const string CredentialsNeedRefreshMessage = "We've detected that your stored credentials are out of sync with your current user. This can happen if you have signed in to git outside of Unity. Sign in again to refresh your credentials.";
11-
private const string NeedAuthenticationMessage = "We need you to authenticate first";
12-
1310
public enum PopupViewType
1411
{
1512
None,
@@ -63,32 +60,8 @@ private void Open(PopupViewType popupViewType, Action<bool> onClose)
6360

6461
}, exception => {
6562
Logger.Trace("User required validation opening AuthenticationView");
66-
67-
string message = null;
68-
string username = null;
69-
70-
var usernameMismatchException = exception as TokenUsernameMismatchException;
71-
if (usernameMismatchException != null)
72-
{
73-
message = CredentialsNeedRefreshMessage;
74-
username = usernameMismatchException.CachedUsername;
75-
}
76-
77-
var keychainEmptyException = exception as KeychainEmptyException;
78-
if (keychainEmptyException != null)
79-
{
80-
message = NeedAuthenticationMessage;
81-
}
82-
83-
if (usernameMismatchException == null && keychainEmptyException == null)
84-
{
85-
message = exception.Message;
86-
}
87-
63+
authenticationView.Initialize(exception);
8864
OpenInternal(PopupViewType.AuthenticationView, completedAuthentication => {
89-
authenticationView.ClearMessage();
90-
authenticationView.ClearUsername();
91-
9265
if (completedAuthentication)
9366
{
9467
Logger.Trace("User completed validation opening view: {0}", popupViewType.ToString());
@@ -98,11 +71,6 @@ private void Open(PopupViewType popupViewType, Action<bool> onClose)
9871
});
9972

10073
shouldCloseOnFinish = false;
101-
authenticationView.SetMessage(message);
102-
if (username != null)
103-
{
104-
authenticationView.SetUsername(username);
105-
}
10674
});
10775
}
10876
else
@@ -120,10 +88,7 @@ private void OpenInternal(PopupViewType popupViewType, Action<bool> onClose)
12088
}
12189

12290
ActiveViewType = popupViewType;
123-
titleContent = new GUIContent(ActiveView.Title, Styles.SmallLogo);
124-
OnEnable();
12591
Show();
126-
Refresh();
12792
}
12893

12994
public IApiClient Client

0 commit comments

Comments
 (0)