Skip to content

Commit

Permalink
feat: add support to macOS editor play scene
Browse files Browse the repository at this point in the history
This allows devs to make use of the play scene button. Note, however,
that PKCE is not supported in this mode due to deeplinking not being
supported in the play mode.
  • Loading branch information
CassiusPacheco committed Oct 9, 2023
1 parent 787e11d commit e59b1d5
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
5 changes: 3 additions & 2 deletions sample/Assets/Scripts/UnauthenticatedScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async void Start()
#endif

passport = await Passport.Init(
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
clientId, environment, redirectUri, 10000
#else
clientId, environment, redirectUri
Expand Down Expand Up @@ -86,7 +86,8 @@ public async void Connect()
ShowOutput("Called Connect()...");
connectButton.gameObject.SetActive(false);

#if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX
// macOS editor (play scene) does not support deeplinking
#if UNITY_ANDROID || UNITY_IPHONE || (UNITY_STANDALONE_OSX && !UNITY_EDITOR_OSX)
await passport.ConnectPKCE();
#else
await passport.Connect();
Expand Down
7 changes: 4 additions & 3 deletions src/Packages/Passport/Runtime/Scripts/Public/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private Passport()
/// <param name="redirectUri">(Currently, mobile only) The URL to which auth will redirect the browser after authorisation has been granted by the user</param>
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout time for waiting for the engine to start (in milliseconds)</param>
public static UniTask<Passport> Init(
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
string clientId, string environment, string? redirectUri = null, int engineStartupTimeoutMs = 4000
#else
string clientId, string environment, string? redirectUri = null
Expand All @@ -61,10 +61,11 @@ public static UniTask<Passport> Init(
{
if (Instance == null)
{
Debug.Log($"{TAG} Initialising Passport...");
Instance = new Passport();
// Wait until we get a ready signal
return Instance.Initialise(
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
engineStartupTimeoutMs
#endif
)
Expand Down Expand Up @@ -94,7 +95,7 @@ public static UniTask<Passport> Init(
}

private async UniTask Initialise(
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
int engineStartupTimeoutMs
#endif
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class GreeBrowserClient : IWebBrowserClient
private const string TAG = "[GreeBrowserClient]";
private const string ANDROID_DATA_DIRECTORY = "android_asset";
private const string MAC_DATA_DIRECTORY = "/Resources/Data";
private const string MAC_EDITOR_RESOURCES_DIRECTORY = "/../src/Packages/Passport/Runtime/Resources";
private readonly WebViewObject webViewObject;
public event OnUnityPostMessageDelegate OnUnityPostMessage;
public event OnUnityPostMessageDelegate OnAuthPostMessage;
Expand All @@ -25,7 +26,9 @@ public GreeBrowserClient()
);
#if UNITY_ANDROID
string filePath = Constants.SCHEME_FILE + ANDROID_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#elif UNITY_EDITOR_OSX
string filePath = Constants.SCHEME_FILE + Path.GetDirectoryName(Application.dataPath) + MAC_EDITOR_RESOURCES_DIRECTORY + Constants.PASSPORT_HTML_FILE_NAME;
#elif UNITY_STANDALONE_OSX
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + MAC_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
#else
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e59b1d5

Please sign in to comment.