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

Commit 380ede9

Browse files
Displaying a message on the Authentication window and setting the cached username
1 parent 79507a3 commit 380ede9

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class AuthenticationView : Subview
2323
[SerializeField] private Vector2 scroll;
2424
[SerializeField] private string username = "";
2525
[SerializeField] private string two2fa = "";
26+
[SerializeField] private string message;
2627

2728
[NonSerialized] private bool need2fa;
2829
[NonSerialized] private bool isBusy;
@@ -98,6 +99,16 @@ public override void OnGUI()
9899
GUILayout.EndScrollView();
99100
}
100101

102+
public void SetMessage(string value)
103+
{
104+
message = value;
105+
}
106+
107+
public void SetUsername(string value)
108+
{
109+
username = value;
110+
}
111+
101112
private void HandleEnterPressed()
102113
{
103114
if (Event.current.type != EventType.KeyDown)
@@ -112,6 +123,8 @@ private void OnGUILogin()
112123
{
113124
EditorGUI.BeginDisabledGroup(isBusy);
114125
{
126+
ShowMessage();
127+
115128
GUILayout.Space(3);
116129
GUILayout.BeginHorizontal();
117130
{
@@ -217,6 +230,16 @@ private void DoResult(bool success, string msg)
217230
}
218231
}
219232

233+
private void ShowMessage()
234+
{
235+
if (message != null)
236+
{
237+
GUILayout.Space(Styles.BaseSpacing + 3);
238+
GUILayout.Label(message, Styles.CenteredLabel);
239+
GUILayout.Space(Styles.BaseSpacing + 3);
240+
}
241+
}
242+
220243
private void ShowErrorMessage()
221244
{
222245
if (errorMessage != null)

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,44 @@ private void Open(PopupViewType popupViewType, Action<bool> onClose)
5959
shouldCloseOnFinish = true;
6060

6161
}, exception => {
62-
6362
Logger.Trace("User required validation opening AuthenticationView");
6463

65-
OpenInternal(PopupViewType.AuthenticationView, completedAuthentication => {
64+
string message = null;
65+
string username = null;
66+
67+
var usernameMismatchException = exception as TokenUsernameMismatchException;
68+
if (usernameMismatchException != null)
69+
{
70+
message = "Your credentials need to be refreshed";
71+
username = usernameMismatchException.CachedUsername;
72+
}
73+
74+
var keychainEmptyException = exception as KeychainEmptyException;
75+
if (keychainEmptyException != null)
76+
{
77+
message = "We need you to authenticate first";
78+
}
6679

80+
if (usernameMismatchException == null && keychainEmptyException == null)
81+
{
82+
message = "There was an error validating your account";
83+
}
84+
85+
OpenInternal(PopupViewType.AuthenticationView, completedAuthentication => {
6786
if (completedAuthentication)
6887
{
6988
Logger.Trace("User completed validation opening view: {0}", popupViewType.ToString());
7089

7190
Open(popupViewType, onClose);
7291
}
7392
});
93+
7494
shouldCloseOnFinish = false;
95+
authenticationView.SetMessage(message);
96+
if (username != null)
97+
{
98+
authenticationView.SetUsername(username);
99+
}
75100
});
76101
}
77102
else

0 commit comments

Comments
 (0)