Skip to content

Commit 113f889

Browse files
Clean Up + Fixes
1 parent aea1435 commit 113f889

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed

GoogleSignIn/Future.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ internal Future(FutureAPIImpl<T> impl) {
5555
/// Gets the status.
5656
/// </summary>
5757
/// <value>The status is set when Pending == false.</value>
58-
GoogleSignInStatusCode Status { get { return apiImpl.Status; } }
58+
public GoogleSignInStatusCode Status { get { return apiImpl.Status; } }
5959

6060
/// <summary>
6161
/// Gets the result.
6262
/// </summary>
6363
/// <value>The result is set when Pending == false and there is no error.
6464
/// </value>
65-
T Result { get { return apiImpl.Result; } }
65+
public T Result { get { return apiImpl.Result; } }
6666

6767
/// <summary>
6868
/// Waits for result then completes the TaskCompleationSource.
@@ -71,6 +71,21 @@ internal Future(FutureAPIImpl<T> impl) {
7171
/// <param name="tcs">Tcs.</param>
7272
internal IEnumerator WaitForResult(TaskCompletionSource<T> tcs) {
7373
yield return new WaitUntil(() => !Pending);
74+
yield return null;
75+
if (Status == GoogleSignInStatusCode.CANCELED) {
76+
tcs.SetCanceled();
77+
} else if (Status == GoogleSignInStatusCode.SUCCESS ||
78+
Status == GoogleSignInStatusCode.SUCCESS_CACHE) {
79+
tcs.SetResult(Result);
80+
} else {
81+
tcs.SetException(new GoogleSignIn.SignInException(Status));
82+
}
83+
}
84+
85+
internal async Task WaitForResultAsync(TaskCompletionSource<T> tcs)
86+
{
87+
while (Pending) await Task.Yield();
88+
await Task.Yield();
7489
if (Status == GoogleSignInStatusCode.CANCELED) {
7590
tcs.SetCanceled();
7691
} else if (Status == GoogleSignInStatusCode.SUCCESS ||

GoogleSignIn/GoogleSignIn.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ public Task<GoogleSignInUser> SignIn() {
123123
return tcs.Task;
124124
}
125125

126+
public Task<GoogleSignInUser> SignInAsync() {
127+
var tcs = new TaskCompletionSource<GoogleSignInUser>();
128+
impl.SignIn().WaitForResultAsync(tcs);
129+
return tcs.Task;
130+
}
131+
132+
public Future<GoogleSignInUser> SignInFuture() => impl.SignIn();
133+
126134
/// <summary>Starts the silent authentication process.</summary>
127135
/// <remarks>
128136
/// The authenication process is started and will attempt to sign in without
@@ -136,6 +144,14 @@ public Task<GoogleSignInUser> SignInSilently() {
136144
return tcs.Task;
137145
}
138146

147+
public Task<GoogleSignInUser> SignInSilentlyAsync() {
148+
var tcs = new TaskCompletionSource<GoogleSignInUser>();
149+
impl.SignInSilently().WaitForResultAsync(tcs);
150+
return tcs.Task;
151+
}
152+
153+
public Future<GoogleSignInUser> SignInSilentlyFuture() => impl.SignInSilently();
154+
139155
/// <summary>
140156
/// Signs out the User.
141157
/// </summary>

GoogleSignIn/Impl/GoogleSignInImpl.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// <copyright file="GoogleSignInImpl.cs" company="Google Inc.">
1+
#if UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS
2+
// <copyright file="GoogleSignInImpl.cs" company="Google Inc.">
23
// Copyright (C) 2017 Google Inc. All Rights Reserved.
34
//
45
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -358,3 +359,4 @@ public static AndroidJavaObject ToAndroidJavaObject(in this IntPtr intPtr)
358359
}
359360
}
360361
}
362+
#endif

GoogleSignIn/Impl/GoogleSignInImplEditor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ static HttpListener BindLocalHostFirstAvailablePort()
6262
#if UNITY_EDITOR_WIN
6363
var listeners = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners();
6464
return Enumerable.Range(minPort, ushort.MaxValue - minPort).Where((i) => !listeners.Any((x) => x.Port == i)).Select((port) => {
65+
#elif UNITY_EDITOR_OSX
66+
return Enumerable.Range(minPort, ushort.MaxValue - minPort).Select((port) => {
6567
#else
6668
return Enumerable.Range(0,10).Select((i) => UnityEngine.Random.Range(minPort,ushort.MaxValue)).Select((port) => {
6769
#endif

GoogleSignIn/Impl/NativeFuture.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// <copyright file="NativeFuture.cs" company="Google Inc.">
1+
#if UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS
2+
// <copyright file="NativeFuture.cs" company="Google Inc.">
23
// Copyright (C) 2017 Google Inc. All Rights Reserved.
34
//
45
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -87,3 +88,4 @@ public GoogleSignInStatusCode Status {
8788
}
8889
}
8990
}
91+
#endif

Plugins/Android/src/main/java/com/google/googlesignin/TokenPendingResult.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.android.gms.common.api.ResultCallback;
2323
import java.util.concurrent.CountDownLatch;
2424
import java.util.concurrent.TimeUnit;
25+
import java.util.Locale;
2526

2627
/**
2728
* Pending result class for TokenResult. This allows the pending result to be returned to the
@@ -41,6 +42,12 @@ public TokenPendingResult(IListener requestHandle) {
4142
result = new TokenResult();
4243
result.setHandle(requestHandle);
4344
}
45+
46+
@Override
47+
public String toString() {
48+
return String.format(
49+
Locale.getDefault(), "Pending Result: %s", (result == null) ? "<null>" : result);
50+
}
4451

4552
@Override
4653
public TokenResult await() {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "com.google.signin",
33
"displayName": "Google Signin",
4-
"version": "0.8.0",
4+
"author": "Robert Lehmann",
5+
"version": "0.8.1",
56
"unity": "2021.3",
67
"description": "Google Signin for android, ios ,desktop",
78
"keywords": [
@@ -19,4 +20,4 @@
1920
"path": "Samples~/SignInSample"
2021
}
2122
]
22-
}
23+
}

0 commit comments

Comments
 (0)