Skip to content

Commit 2f1647f

Browse files
committed
feat: windows webview
1 parent 3d7e9ae commit 2f1647f

File tree

16 files changed

+166
-117
lines changed

16 files changed

+166
-117
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,4 @@ sample/AltTester.log
100100
sample/mono_crash*
101101

102102
# Vuplex
103-
src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex
104-
src/Packages/Passport/Runtime/ThirdParty/Vuplex/Vuplex.meta
103+
sample/Assets/Vuplex*

sample/Assets/Scripts/SelectAuthMethodScript.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ private async void InitialisePassport(string redirectUri = null, string logoutRe
7979
}
8080
catch (Exception ex)
8181
{
82+
Debug.Log(ex);
8283
ShowOutput($"Initialise Passport error: {ex.Message}");
8384
}
8485
}

sample/ProjectSettings/ProjectSettings.asset

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ PlayerSettings:
499499
- m_BuildTarget: iOSSupport
500500
m_APIs: 10000000
501501
m_Automatic: 1
502+
- m_BuildTarget: WindowsStandaloneSupport
503+
m_APIs: 02000000
504+
m_Automatic: 1
502505
m_BuildTargetVRSettings: []
503506
m_DefaultShaderChunkSizeInMB: 16
504507
m_DefaultShaderChunkCount: 0
@@ -766,14 +769,14 @@ PlayerSettings:
766769
webGLDecompressionFallback: 0
767770
webGLPowerPreference: 2
768771
scriptingDefineSymbols:
769-
Standalone:
772+
Standalone: VUPLEX_STANDALONE
770773
additionalCompilerArguments:
771774
Standalone:
772775
- -nullable+
773776
platformArchitecture: {}
774777
scriptingBackend:
775778
Android: 1
776-
Standalone: 1
779+
Standalone: 0
777780
il2cppCompilerConfiguration: {}
778781
managedStrippingLevel:
779782
EmbeddedLinux: 1
@@ -794,7 +797,7 @@ PlayerSettings:
794797
allowUnsafeCode: 0
795798
useDeterministicCompilation: 1
796799
enableRoslynAnalyzers: 1
797-
selectedPlatform: 2
800+
selectedPlatform: 0
798801
additionalIl2CppArgs:
799802
scriptingRuntimeVersion: 1
800803
gcIncremental: 1

src/Packages/Passport/Runtime/Resources/index.html

Lines changed: 19 additions & 19 deletions
Large diffs are not rendered by default.

src/Packages/Passport/Runtime/Scripts/Private/Core/BrowserCommunicationsManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ namespace Immutable.Passport.Core
1919

2020
public interface IBrowserCommunicationsManager
2121
{
22+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
2223
event OnUnityPostMessageDelegate OnAuthPostMessage;
2324
event OnUnityPostMessageErrorDelegate OnPostMessageError;
25+
#endif
2426
void SetCallTimeout(int ms);
2527
void LaunchAuthURL(string url, string redirectUri);
2628
UniTask<string> Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable<long> timeoutMs = null);
@@ -60,8 +62,10 @@ public BrowserCommunicationsManager(IWebBrowserClient webBrowserClient)
6062
{
6163
this.webBrowserClient = webBrowserClient;
6264
this.webBrowserClient.OnUnityPostMessage += InvokeOnUnityPostMessage;
65+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
6366
this.webBrowserClient.OnAuthPostMessage += InvokeOnAuthPostMessage;
6467
this.webBrowserClient.OnPostMessageError += InvokeOnPostMessageError;
68+
#endif
6569
}
6670

6771
#region Unity to Browser

src/Packages/Passport/Runtime/Scripts/Private/PassportImpl.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ public async UniTask Init(string clientId, string environment, string redirectUr
5454
{
5555
this.redirectUri = redirectUri;
5656
this.logoutRedirectUri = logoutRedirectUri;
57+
58+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
5759
this.communicationsManager.OnAuthPostMessage += OnDeepLinkActivated;
5860
this.communicationsManager.OnPostMessageError += OnPostMessageError;
61+
#endif
5962

6063
var versionInfo = new VersionInfo
6164
{

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

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,69 +20,86 @@ public class Passport
2020
private const string TAG = "[Passport]";
2121

2222
public static Passport Instance { get; private set; }
23+
private PassportImpl passportImpl = null;
2324

24-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
25-
private readonly IWebBrowserClient webBrowserClient = new WebBrowserClient();
26-
#else
27-
private readonly IWebBrowserClient webBrowserClient = new GreeBrowserClient();
28-
#endif
25+
private IWebBrowserClient webBrowserClient;
2926

3027
// Keeps track of the latest received deeplink
3128
private static string deeplink = null;
3229
private static bool readySignalReceived = false;
33-
private PassportImpl passportImpl = null;
3430

31+
/// <summary>
32+
/// Passport auth events
33+
/// </summary>
34+
/// <seealso cref="Immutable.Passport.Event.PassportAuthEvent" />
3535
public event OnAuthEventDelegate OnAuthEvent;
3636

3737
private Passport()
3838
{
39+
// Handle clean-up tasks when the application is quitting
3940
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
4041
Application.quitting += OnQuit;
4142
#elif UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
43+
// Handle deeplinks for iOS and macOS
4244
Application.deepLinkActivated += OnDeepLinkActivated;
45+
46+
// Check if there is a deep link URL provided on application start
4347
if (!string.IsNullOrEmpty(Application.absoluteURL))
4448
{
45-
// Cold start and Application.absoluteURL not null so process Deep Link.
49+
// Handle the deep link if provided during a cold start
4650
OnDeepLinkActivated(Application.absoluteURL);
4751
}
4852
#endif
4953
}
5054

5155
/// <summary>
52-
/// Initialises Passport
56+
/// Initialises Passport with the specified parameters.
57+
/// This sets up the Passport instance, configures the web browser, and waits for the ready signal.
5358
/// </summary>
5459
/// <param name="clientId">The client ID</param>
5560
/// <param name="environment">The environment to connect to</param>
56-
/// <param name="redirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after authorisation has been granted by the user</param>
57-
/// <param name="logoutRedirectUri">(Android, iOS and macOS only) The URL to which auth will redirect the browser after log out is complete</param>
58-
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout time for waiting for the engine to start (in milliseconds)</param>
61+
/// <param name="redirectUri">(Android, iOS, and macOS only) The URL where the browser will redirect after successful authentication.</param>
62+
/// <param name="logoutRedirectUri">(Android, iOS, and macOS only) The URL where the browser will redirect after logout is complete.</param>
63+
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
64+
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
5965
public static UniTask<Passport> Init(
6066
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
61-
string clientId, string environment, string redirectUri = null, string logoutRedirectUri = null, int engineStartupTimeoutMs = 30000
67+
string clientId,
68+
string environment,
69+
string redirectUri = null,
70+
string logoutRedirectUri = null,
71+
int engineStartupTimeoutMs = 30000,
72+
WindowsWebBrowserClient webBrowserClient = null
6273
#else
63-
string clientId, string environment, string redirectUri = null, string logoutRedirectUri = null
74+
string clientId,
75+
string environment,
76+
string redirectUri = null,
77+
string logoutRedirectUri = null
6478
#endif
6579
)
6680
{
6781
if (Instance == null)
6882
{
6983
Debug.Log($"{TAG} Initialising Passport...");
7084
Instance = new Passport();
71-
// Wait until we get a ready signal
85+
86+
// Start initialisation process
7287
return Instance.Initialise(
7388
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
74-
engineStartupTimeoutMs
89+
engineStartupTimeoutMs, webBrowserClient
7590
#endif
7691
)
7792
.ContinueWith(async () =>
7893
{
94+
// Wait for the ready signal
7995
Debug.Log($"{TAG} Waiting for ready signal...");
8096
await UniTask.WaitUntil(() => readySignalReceived == true);
8197
})
8298
.ContinueWith(async () =>
8399
{
84100
if (readySignalReceived == true)
85101
{
102+
// Initialise Passport with provided parameters
86103
await Instance.GetPassportImpl().Init(clientId, environment, redirectUri, logoutRedirectUri, deeplink);
87104
return Instance;
88105
}
@@ -95,43 +112,72 @@ public static UniTask<Passport> Init(
95112
}
96113
else
97114
{
115+
// Return the existing instance if already initialised
98116
readySignalReceived = true;
99117
return UniTask.FromResult(Instance);
100118
}
101119
}
102120

121+
/// <summary>
122+
/// Initialises the appropriate web browser and sets up browser communication.
123+
/// </summary>
124+
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
125+
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
103126
private async UniTask Initialise(
104127
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
105-
int engineStartupTimeoutMs
128+
int engineStartupTimeoutMs, WindowsWebBrowserClient webBrowserClient
106129
#endif
107130
)
108131
{
109132
try
110133
{
111-
BrowserCommunicationsManager communicationsManager = new BrowserCommunicationsManager(webBrowserClient);
112-
communicationsManager.OnReady += () => readySignalReceived = true;
134+
// Initialise the web browser client
113135
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
114-
await ((WebBrowserClient)webBrowserClient).Init(engineStartupTimeoutMs);
136+
if (webBrowserClient != null)
137+
{
138+
// Use the provided custom Windows browser client
139+
this.webBrowserClient = webBrowserClient;
140+
await ((WindowsWebBrowserClient)this.webBrowserClient).Init();
141+
}
142+
else
143+
{
144+
// Initialise with default Windows browser client
145+
this.webBrowserClient = new WebBrowserClient();
146+
await ((WebBrowserClient)this.webBrowserClient).Init(engineStartupTimeoutMs);
147+
}
148+
#else
149+
// Initialise default browser client for Android, iOS, and macOS
150+
webBrowserClient = new GreeBrowserClient();
115151
#endif
152+
153+
// Set up browser communication
154+
BrowserCommunicationsManager communicationsManager = new BrowserCommunicationsManager(webBrowserClient);
155+
// Mark ready when browser is initialised and game bridge file is loaded
156+
communicationsManager.OnReady += () => readySignalReceived = true;
157+
158+
// Set up Passport implementation
116159
passportImpl = new PassportImpl(communicationsManager);
160+
// Subscribe to Passport authentication events
117161
passportImpl.OnAuthEvent += OnPassportAuthEvent;
118162
}
119163
catch (Exception ex)
120164
{
121-
// Reset values
165+
// Reset everything on error
122166
readySignalReceived = false;
123167
Instance = null;
124168
throw ex;
125169
}
126170
}
127171

172+
128173
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
174+
/// <summary>
175+
/// Handles clean-up when the application quits.
176+
/// </summary>
129177
private void OnQuit()
130178
{
131-
// Need to clean up UWB resources when quitting the game in the editor
132-
// as the child engine process would still be alive
133179
Debug.Log($"{TAG} Quitting the Player");
134-
((WebBrowserClient)webBrowserClient).Dispose();
180+
webBrowserClient.Dispose();
135181
Instance = null;
136182
}
137183
#endif

src/Packages/Passport/Runtime/ThirdParty/Gree/Assets/Plugins/GreeBrowserClient.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
2+
13
using Immutable.Browser.Core;
24
using UnityEngine;
35
using System.IO;
@@ -96,4 +98,6 @@ public void ClearStorage()
9698
#endif
9799

98100
}
99-
}
101+
}
102+
103+
#endif

src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/IWebBrowserClient.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@ namespace Immutable.Browser.Core
33
public interface IWebBrowserClient
44
{
55
event OnUnityPostMessageDelegate OnUnityPostMessage;
6+
7+
// Required for Gree browser only
8+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
69
event OnUnityPostMessageDelegate OnAuthPostMessage;
710
event OnUnityPostMessageErrorDelegate OnPostMessageError;
8-
11+
#endif
912
void ExecuteJs(string js);
10-
1113
void LaunchAuthURL(string url, string redirectUri);
14+
15+
// Required for Windows browser only
16+
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
17+
void Dispose();
18+
#endif
19+
20+
// Only available for mobile devices
1221
#if (UNITY_IPHONE && !UNITY_EDITOR) || (UNITY_ANDROID && !UNITY_EDITOR)
1322
void ClearCache(bool includeDiskFiles);
1423
void ClearStorage();

src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/Immutable.Browser.Core.asmdef

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"name": "Immutable.Browser.Core",
33
"rootNamespace": "Immutable.Browser.Core",
4-
"references": [],
4+
"references": [
5+
"GUID:f51ebe6a0ceec4240a699833d6309b23"
6+
],
57
"includePlatforms": [],
68
"excludePlatforms": [],
79
"allowUnsafeCode": false,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.IO;
2+
using UnityEngine;
3+
using Immutable.Browser.Core;
4+
using Cysharp.Threading.Tasks;
5+
6+
namespace Immutable.Browser.Core
7+
{
8+
public abstract class WindowsWebBrowserClient : IWebBrowserClient
9+
{
10+
public event OnUnityPostMessageDelegate OnUnityPostMessage;
11+
12+
public abstract UniTask Init();
13+
14+
public abstract void ExecuteJs(string js);
15+
16+
protected void PostMessage(string message)
17+
{
18+
OnUnityPostMessage?.Invoke(message);
19+
}
20+
21+
public void LaunchAuthURL(string url, string? redirectUri)
22+
{
23+
Application.OpenURL(url);
24+
}
25+
26+
public abstract void Dispose();
27+
28+
protected string GetBridgeFilePath()
29+
{
30+
string filePath = "";
31+
#if UNITY_EDITOR
32+
filePath = Constants.SCHEME_FILE + Path.GetFullPath($"{Constants.PASSPORT_PACKAGE_RESOURCES_DIRECTORY}{Constants.PASSPORT_HTML_FILE_NAME}");
33+
#elif UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
34+
filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
35+
#endif
36+
return filePath;
37+
}
38+
}
39+
}

src/Packages/Passport/Runtime/ThirdParty/Vuplex/VuplexWebView.cs.meta renamed to src/Packages/Passport/Runtime/ThirdParty/ImmutableBrowserCore/WindowsWebBrowserClient.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Packages/Passport/Runtime/ThirdParty/UnityWebBrowser/Runtime/Core/WebBrowserClient.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,6 @@ internal void InvokeLoadProgressChange(double progress)
609609
/// Invoked when the browser goes in or out of fullscreen
610610
/// </summary>
611611
public event OnFullscreenChange OnFullscreen;
612-
public event OnUnityPostMessageDelegate OnAuthPostMessage;
613-
public event OnUnityPostMessageErrorDelegate OnPostMessageError;
614612

615613
internal void InvokeFullscreen(bool fullscreen)
616614
{

src/Packages/Passport/Runtime/ThirdParty/Vuplex.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)