Skip to content

Commit

Permalink
Merge 8555041 into d1035ac
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno authored Mar 8, 2024
2 parents d1035ac + 8555041 commit dcec813
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 196 deletions.
8 changes: 8 additions & 0 deletions src/StoreReview.Plugin/CrossStoreReview.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

namespace Plugin.StoreReview
{
public enum ReviewStatus
{
Succeeded,
Error,
CanceledByUser,
NetworkError,
Unknown
}
/// <summary>
/// Cross platform StoreReview implemenations
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/StoreReview.Plugin/IStoreReview.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ public interface IStoreReview
/// <summary>
/// Requests an app review.
/// </summary>
Task RequestReview(bool testMode);
Task<ReviewStatus> RequestReview(bool testMode);
}
}
6 changes: 4 additions & 2 deletions src/StoreReview.Plugin/StoreReviewImplementation.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void OpenStoreReviewPage(string appId)
/// <summary>
/// Requests an app review.
/// </summary>
public async Task RequestReview(bool testMode)
public async Task<ReviewStatus> RequestReview(bool testMode)
{
tcs?.TrySetCanceled();
tcs = new TaskCompletionSource<bool>();
Expand All @@ -99,9 +99,11 @@ public async Task RequestReview(bool testMode)
forceReturn = false;
var request = manager.RequestReviewFlow();
request.AddOnCompleteListener(this);
await tcs.Task;
var status = await tcs.Task;
manager.Dispose();
request.Dispose();

return status ? ReviewStatus.Succeeded : ReviewStatus.Error;
}

Activity Activity =>
Expand Down
8 changes: 4 additions & 4 deletions src/StoreReview.Plugin/StoreReviewImplementation.apple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void OpenStoreReviewPage(string appId)
/// <summary>
/// Requests an app review.
/// </summary>
public Task RequestReview(bool testMode)
public Task<ReviewStatus> RequestReview(bool testMode)
{
#if __IOS__
if (IsiOS103)
Expand All @@ -86,7 +86,7 @@ public Task RequestReview(bool testMode)
if (windowScene != null)
{
SKStoreReviewController.RequestReview(windowScene);
return Task.CompletedTask;
return Task.FromResult(ReviewStatus.Unknown);
}
}
SKStoreReviewController.RequestReview();
Expand All @@ -99,8 +99,8 @@ public Task RequestReview(bool testMode)
}
#endif

return Task.CompletedTask;
}
return Task.FromResult(ReviewStatus.Unknown);
}

internal static Version ParseVersion(string version)
{
Expand Down
43 changes: 39 additions & 4 deletions src/StoreReview.Plugin/StoreReviewImplementation.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Services.Store;
using Windows.ApplicationModel.Store;
using System.Collections.Generic;
using Windows.System;

namespace Plugin.StoreReview
{
Expand All @@ -27,10 +30,42 @@ public void OpenStoreListing(string appId) =>
public void OpenStoreReviewPage(string appId) =>
OpenUrl($"ms-windows-store://review/?ProductId={appId}");

/// <summary>
/// Requests an app review.
/// </summary>
public async Task RequestReview(bool testMode) => _ = await StoreRequestHelper.SendRequestAsync(StoreContext.GetDefault(), 16, string.Empty).AsTask();
#if NET6_0_OR_GREATER
public static object WindowObject { get; set; }
#endif
/// <summary>
/// Requests an app review.
/// </summary>
public async Task<ReviewStatus> RequestReview(bool testMode)
{
try
{

var context = StoreContext.GetDefault();

#if NET6_0_OR_GREATER
if(WindowObject is null)
throw new NullReferenceException("WindowObject is null. Please set the WindowObject property before calling RequestReview.");
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(WindowObject);
WinRT.Interop.InitializeWithWindow.Initialize(context, hwnd);
#endif

var result = await context.RequestRateAndReviewAppAsync();
return result.Status switch
{
StoreRateAndReviewStatus.Succeeded => ReviewStatus.Succeeded,
StoreRateAndReviewStatus.CanceledByUser => ReviewStatus.CanceledByUser,
StoreRateAndReviewStatus.Error => ReviewStatus.Error,
StoreRateAndReviewStatus.NetworkError => ReviewStatus.NetworkError,
_ => ReviewStatus.Error,
};
}
catch(Exception ex)
{
Debug.WriteLine(ex);
return ReviewStatus.Error;
}
}

void OpenUrl(string url)
{
Expand Down
Loading

0 comments on commit dcec813

Please sign in to comment.