Skip to content

Commit 14aa040

Browse files
authored
Merge pull request #273 from immutable/feat/domain-reloading
[DX-3076] feat: support domain reloading
2 parents 7cee73b + 8a2c2db commit 14aa040

File tree

1 file changed

+75
-21
lines changed
  • src/Packages/Passport/Runtime/Scripts/Public

1 file changed

+75
-21
lines changed

src/Packages/Passport/Runtime/Scripts/Public/Passport.cs

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
using Immutable.Passport.Core;
1414
using Cysharp.Threading.Tasks;
1515
using UnityEngine;
16+
#if UNITY_EDITOR
17+
using UnityEditor;
18+
#endif
1619

1720
namespace Immutable.Passport
1821
{
@@ -52,6 +55,10 @@ private Passport()
5255
OnDeepLinkActivated(Application.absoluteURL);
5356
}
5457
#endif
58+
59+
#if UNITY_EDITOR
60+
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
61+
#endif
5562
}
5663

5764
/// <summary>
@@ -65,18 +72,13 @@ private Passport()
6572
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
6673
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
6774
public static UniTask<Passport> Init(
68-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
69-
string clientId,
70-
string environment,
71-
string redirectUri = null,
72-
string logoutRedirectUri = null,
73-
int engineStartupTimeoutMs = 30000,
74-
IWindowsWebBrowserClient windowsWebBrowserClient = null
75-
#else
7675
string clientId,
7776
string environment,
7877
string redirectUri = null,
7978
string logoutRedirectUri = null
79+
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
80+
, int engineStartupTimeoutMs = 30000,
81+
IWindowsWebBrowserClient windowsWebBrowserClient = null
8082
#endif
8183
)
8284
{
@@ -178,19 +180,6 @@ private async UniTask Initialise(
178180
}
179181
}
180182

181-
182-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
183-
/// <summary>
184-
/// Handles clean-up when the application quits.
185-
/// </summary>
186-
private void OnQuit()
187-
{
188-
Debug.Log($"{TAG} Quitting the Player");
189-
webBrowserClient.Dispose();
190-
Instance = null;
191-
}
192-
#endif
193-
194183
/// <summary>
195184
/// Sets the timeout time for waiting for each call to respond (in milliseconds).
196185
/// This only applies to functions that use the browser communications manager.
@@ -502,5 +491,70 @@ private void OnPassportAuthEvent(PassportAuthEvent authEvent)
502491
OnAuthEvent.Invoke(authEvent);
503492
}
504493
}
494+
495+
/// <summary>
496+
/// Handles clean-up when the application quits
497+
/// </summary>
498+
private void OnQuit()
499+
{
500+
Debug.Log($"{TAG} Quitting the Player");
501+
502+
#if UNITY_EDITOR
503+
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
504+
#endif
505+
506+
DisposeAll();
507+
}
508+
509+
#if UNITY_EDITOR
510+
/// <summary>
511+
/// Handles play mode state changes in the editor
512+
/// </summary>
513+
/// <param name="state">The current play mode state</param>
514+
private void OnPlayModeStateChanged(PlayModeStateChange state)
515+
{
516+
// Dispose of all resources when exiting play mode
517+
if (state == PlayModeStateChange.ExitingPlayMode)
518+
{
519+
DisposeAll();
520+
}
521+
}
522+
#endif
523+
524+
/// <summary>
525+
/// Disposes of all resources and unsubscribes from events
526+
/// </summary>
527+
private void DisposeAll()
528+
{
529+
// Dispose of the web browser client for Windows only
530+
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
531+
if (webBrowserClient != null)
532+
{
533+
webBrowserClient.Dispose();
534+
webBrowserClient = null;
535+
}
536+
#endif
537+
538+
// Unsubscribe from Passport authentication events
539+
// and dispose of the Passport implementation
540+
if (passportImpl != null)
541+
{
542+
passportImpl.OnAuthEvent -= OnPassportAuthEvent;
543+
passportImpl = null;
544+
}
545+
546+
// Unsubscribe from application quitting event
547+
Application.quitting -= OnQuit;
548+
549+
#if UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
550+
// Unsubscribe from deep link activation events on iOS and macOS
551+
Application.deepLinkActivated -= OnDeepLinkActivated;
552+
#endif
553+
554+
// Reset static fields
555+
Instance = null;
556+
deeplink = null;
557+
readySignalReceived = false;
558+
}
505559
}
506560
}

0 commit comments

Comments
 (0)