Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DX-3076] feat: support domain reloading #273

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 75 additions & 21 deletions src/Packages/Passport/Runtime/Scripts/Public/Passport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using Immutable.Passport.Core;
using Cysharp.Threading.Tasks;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Immutable.Passport
{
Expand Down Expand Up @@ -52,6 +55,10 @@ private Passport()
OnDeepLinkActivated(Application.absoluteURL);
}
#endif

#if UNITY_EDITOR
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
#endif
}

/// <summary>
Expand All @@ -65,18 +72,13 @@ private Passport()
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
public static UniTask<Passport> Init(
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
string clientId,
string environment,
string redirectUri = null,
string logoutRedirectUri = null,
int engineStartupTimeoutMs = 30000,
IWindowsWebBrowserClient windowsWebBrowserClient = null
#else
string clientId,
string environment,
string redirectUri = null,
string logoutRedirectUri = null
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
, int engineStartupTimeoutMs = 30000,
IWindowsWebBrowserClient windowsWebBrowserClient = null
#endif
)
{
Expand Down Expand Up @@ -178,19 +180,6 @@ private async UniTask Initialise(
}
}


#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
/// <summary>
/// Handles clean-up when the application quits.
/// </summary>
private void OnQuit()
{
Debug.Log($"{TAG} Quitting the Player");
webBrowserClient.Dispose();
Instance = null;
}
#endif

/// <summary>
/// Sets the timeout time for waiting for each call to respond (in milliseconds).
/// This only applies to functions that use the browser communications manager.
Expand Down Expand Up @@ -502,5 +491,70 @@ private void OnPassportAuthEvent(PassportAuthEvent authEvent)
OnAuthEvent.Invoke(authEvent);
}
}

/// <summary>
/// Handles clean-up when the application quits
/// </summary>
private void OnQuit()
{
Debug.Log($"{TAG} Quitting the Player");

#if UNITY_EDITOR
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
#endif

DisposeAll();
}

#if UNITY_EDITOR
/// <summary>
/// Handles play mode state changes in the editor
/// </summary>
/// <param name="state">The current play mode state</param>
private void OnPlayModeStateChanged(PlayModeStateChange state)
{
// Dispose of all resources when exiting play mode
if (state == PlayModeStateChange.ExitingPlayMode)
{
DisposeAll();
}
}
#endif

/// <summary>
/// Disposes of all resources and unsubscribes from events
/// </summary>
private void DisposeAll()
{
// Dispose of the web browser client for Windows only
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
if (webBrowserClient != null)
{
webBrowserClient.Dispose();
webBrowserClient = null;
}
#endif

// Unsubscribe from Passport authentication events
// and dispose of the Passport implementation
if (passportImpl != null)
{
passportImpl.OnAuthEvent -= OnPassportAuthEvent;
passportImpl = null;
}

// Unsubscribe from application quitting event
Application.quitting -= OnQuit;

#if UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
// Unsubscribe from deep link activation events on iOS and macOS
Application.deepLinkActivated -= OnDeepLinkActivated;
#endif

// Reset static fields
Instance = null;
deeplink = null;
readySignalReceived = false;
}
}
}
Loading