Skip to content

Commit 250241d

Browse files
authored
Merge pull request #260 from immutable/feat/vuplex
[DX-3060] feat: support custom windows webview
2 parents 17a1213 + 0bfa1ab commit 250241d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+370
-119
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,7 @@ sample/ProjectSettings/Packages/com.unity.testtools.codecoverage/Settings.json
9797
sample/AltTester.log
9898

9999
# Crashes
100-
sample/mono_crash*
100+
sample/mono_crash*
101+
102+
# Vuplex
103+
sample/Assets/Vuplex*

sample/Assets/Scenes/SelectAuthMethod.unity

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ MonoBehaviour:
206206
m_TargetGraphic: {fileID: 416242725}
207207
m_HandleRect: {fileID: 416242724}
208208
m_Direction: 0
209-
m_Value: 1
210-
m_Size: 0.99999994
209+
m_Value: 0
210+
m_Size: 1
211211
m_NumberOfSteps: 0
212212
m_OnValueChanged:
213213
m_PersistentCalls:
@@ -1407,8 +1407,8 @@ MonoBehaviour:
14071407
m_TargetGraphic: {fileID: 167431872}
14081408
m_HandleRect: {fileID: 167431871}
14091409
m_Direction: 2
1410-
m_Value: 0
1411-
m_Size: 1
1410+
m_Value: 1
1411+
m_Size: 0.99999994
14121412
m_NumberOfSteps: 0
14131413
m_OnValueChanged:
14141414
m_PersistentCalls:

sample/ProjectSettings/ProjectSettings.asset

Lines changed: 5 additions & 2 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
@@ -773,7 +776,7 @@ PlayerSettings:
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/Scripts/Private/Core/BrowserCommunicationsManager.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
using System;
33
using Cysharp.Threading.Tasks;
44
using System.Collections.Generic;
5-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
6-
using VoltstroStudios.UnityWebBrowser.Core;
7-
#else
8-
using Immutable.Browser.Gree;
9-
#endif
105
using Immutable.Browser.Core;
116
using Immutable.Passport.Model;
127
using UnityEngine;
@@ -19,8 +14,10 @@ namespace Immutable.Passport.Core
1914

2015
public interface IBrowserCommunicationsManager
2116
{
17+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
2218
event OnUnityPostMessageDelegate OnAuthPostMessage;
2319
event OnUnityPostMessageErrorDelegate OnPostMessageError;
20+
#endif
2421
void SetCallTimeout(int ms);
2522
void LaunchAuthURL(string url, string redirectUri);
2623
UniTask<string> Call(string fxName, string data = null, bool ignoreTimeout = false, Nullable<long> timeoutMs = null);
@@ -60,8 +57,10 @@ public BrowserCommunicationsManager(IWebBrowserClient webBrowserClient)
6057
{
6158
this.webBrowserClient = webBrowserClient;
6259
this.webBrowserClient.OnUnityPostMessage += InvokeOnUnityPostMessage;
60+
#if (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
6361
this.webBrowserClient.OnAuthPostMessage += InvokeOnAuthPostMessage;
6462
this.webBrowserClient.OnPostMessageError += InvokeOnPostMessageError;
63+
#endif
6564
}
6665

6766
#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: 79 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Collections.Generic;
22
using System;
33
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
4+
#if !IMMUTABLE_CUSTOM_BROWSER
45
using VoltstroStudios.UnityWebBrowser.Core;
5-
#else
6+
#endif
7+
#elif (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
68
using Immutable.Browser.Gree;
79
#endif
810
using Immutable.Passport.Event;
@@ -20,69 +22,86 @@ public class Passport
2022
private const string TAG = "[Passport]";
2123

2224
public static Passport Instance { get; private set; }
25+
private PassportImpl passportImpl = null;
2326

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
27+
private IWebBrowserClient webBrowserClient;
2928

3029
// Keeps track of the latest received deeplink
3130
private static string deeplink = null;
3231
private static bool readySignalReceived = false;
33-
private PassportImpl passportImpl = null;
3432

33+
/// <summary>
34+
/// Passport auth events
35+
/// </summary>
36+
/// <seealso cref="Immutable.Passport.Event.PassportAuthEvent" />
3537
public event OnAuthEventDelegate OnAuthEvent;
3638

3739
private Passport()
3840
{
41+
// Handle clean-up tasks when the application is quitting
3942
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
4043
Application.quitting += OnQuit;
4144
#elif UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
45+
// Handle deeplinks for iOS and macOS
4246
Application.deepLinkActivated += OnDeepLinkActivated;
47+
48+
// Check if there is a deep link URL provided on application start
4349
if (!string.IsNullOrEmpty(Application.absoluteURL))
4450
{
45-
// Cold start and Application.absoluteURL not null so process Deep Link.
51+
// Handle the deep link if provided during a cold start
4652
OnDeepLinkActivated(Application.absoluteURL);
4753
}
4854
#endif
4955
}
5056

5157
/// <summary>
52-
/// Initialises Passport
58+
/// Initialises Passport with the specified parameters.
59+
/// This sets up the Passport instance, configures the web browser, and waits for the ready signal.
5360
/// </summary>
5461
/// <param name="clientId">The client ID</param>
5562
/// <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>
63+
/// <param name="redirectUri">(Android, iOS, and macOS only) The URL where the browser will redirect after successful authentication.</param>
64+
/// <param name="logoutRedirectUri">(Android, iOS, and macOS only) The URL where the browser will redirect after logout is complete.</param>
65+
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
66+
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
5967
public static UniTask<Passport> Init(
6068
#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
69+
string clientId,
70+
string environment,
71+
string redirectUri = null,
72+
string logoutRedirectUri = null,
73+
int engineStartupTimeoutMs = 30000,
74+
IWindowsWebBrowserClient windowsWebBrowserClient = null
6275
#else
63-
string clientId, string environment, string redirectUri = null, string logoutRedirectUri = null
76+
string clientId,
77+
string environment,
78+
string redirectUri = null,
79+
string logoutRedirectUri = null
6480
#endif
6581
)
6682
{
6783
if (Instance == null)
6884
{
6985
Debug.Log($"{TAG} Initialising Passport...");
7086
Instance = new Passport();
71-
// Wait until we get a ready signal
87+
88+
// Start initialisation process
7289
return Instance.Initialise(
7390
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
74-
engineStartupTimeoutMs
91+
engineStartupTimeoutMs, windowsWebBrowserClient
7592
#endif
7693
)
7794
.ContinueWith(async () =>
7895
{
96+
// Wait for the ready signal
7997
Debug.Log($"{TAG} Waiting for ready signal...");
8098
await UniTask.WaitUntil(() => readySignalReceived == true);
8199
})
82100
.ContinueWith(async () =>
83101
{
84102
if (readySignalReceived == true)
85103
{
104+
// Initialise Passport with provided parameters
86105
await Instance.GetPassportImpl().Init(clientId, environment, redirectUri, logoutRedirectUri, deeplink);
87106
return Instance;
88107
}
@@ -95,43 +114,79 @@ public static UniTask<Passport> Init(
95114
}
96115
else
97116
{
117+
// Return the existing instance if already initialised
98118
readySignalReceived = true;
99119
return UniTask.FromResult(Instance);
100120
}
101121
}
102122

123+
/// <summary>
124+
/// Initialises the appropriate web browser and sets up browser communication.
125+
/// </summary>
126+
/// <param name="engineStartupTimeoutMs">(Windows only) Timeout duration in milliseconds to wait for the default Windows browser engine to start.</param>
127+
/// <param name="webBrowserClient">(Windows only) Custom Windows browser to use instead of the default browser in the SDK.</param>
103128
private async UniTask Initialise(
104129
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
105-
int engineStartupTimeoutMs
130+
int engineStartupTimeoutMs, IWindowsWebBrowserClient windowsWebBrowserClient
106131
#endif
107132
)
108133
{
109134
try
110135
{
111-
BrowserCommunicationsManager communicationsManager = new BrowserCommunicationsManager(webBrowserClient);
112-
communicationsManager.OnReady += () => readySignalReceived = true;
136+
// Initialise the web browser client
113137
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
114-
await ((WebBrowserClient)webBrowserClient).Init(engineStartupTimeoutMs);
138+
if (windowsWebBrowserClient != null)
139+
{
140+
// Use the provided custom Windows browser client
141+
this.webBrowserClient = new WindowsWebBrowserClientAdapter(windowsWebBrowserClient);
142+
await ((WindowsWebBrowserClientAdapter)this.webBrowserClient).Init();
143+
}
144+
else
145+
{
146+
#if IMMUTABLE_CUSTOM_BROWSER
147+
throw new PassportException("When 'IMMUTABLE_CUSTOM_BROWSER' is defined in Scripting Define Symbols, " +
148+
" 'windowsWebBrowserClient' must not be null.");
149+
#else
150+
// Initialise with default Windows browser client
151+
this.webBrowserClient = new WebBrowserClient();
152+
await ((WebBrowserClient)this.webBrowserClient).Init(engineStartupTimeoutMs);
115153
#endif
154+
}
155+
#elif (UNITY_ANDROID && !UNITY_EDITOR_WIN) || (UNITY_IPHONE && !UNITY_EDITOR_WIN) || UNITY_STANDALONE_OSX
156+
// Initialise default browser client for Android, iOS, and macOS
157+
webBrowserClient = new GreeBrowserClient();
158+
#else
159+
throw new PassportException("Platform not supported");
160+
#endif
161+
162+
// Set up browser communication
163+
BrowserCommunicationsManager communicationsManager = new BrowserCommunicationsManager(webBrowserClient);
164+
// Mark ready when browser is initialised and game bridge file is loaded
165+
communicationsManager.OnReady += () => readySignalReceived = true;
166+
167+
// Set up Passport implementation
116168
passportImpl = new PassportImpl(communicationsManager);
169+
// Subscribe to Passport authentication events
117170
passportImpl.OnAuthEvent += OnPassportAuthEvent;
118171
}
119172
catch (Exception ex)
120173
{
121-
// Reset values
174+
// Reset everything on error
122175
readySignalReceived = false;
123176
Instance = null;
124177
throw ex;
125178
}
126179
}
127180

181+
128182
#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>
129186
private void OnQuit()
130187
{
131-
// Need to clean up UWB resources when quitting the game in the editor
132-
// as the child engine process would still be alive
133188
Debug.Log($"{TAG} Quitting the Player");
134-
((WebBrowserClient)webBrowserClient).Dispose();
189+
webBrowserClient.Dispose();
135190
Instance = null;
136191
}
137192
#endif

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

Lines changed: 8 additions & 17 deletions
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;
@@ -7,9 +9,7 @@ namespace Immutable.Browser.Gree
79
public class GreeBrowserClient : IWebBrowserClient
810
{
911
private const string TAG = "[GreeBrowserClient]";
10-
private const string ANDROID_DATA_DIRECTORY = "android_asset";
11-
private const string MAC_DATA_DIRECTORY = "/Resources/Data";
12-
private const string MAC_EDITOR_RESOURCES_DIRECTORY = "Packages/com.immutable.passport/Runtime/Resources";
12+
1313
private readonly WebViewObject webViewObject;
1414
public event OnUnityPostMessageDelegate OnUnityPostMessage;
1515
public event OnUnityPostMessageDelegate OnAuthPostMessage;
@@ -29,19 +29,8 @@ public GreeBrowserClient()
2929
auth: InvokeOnAuthPostMessage,
3030
log: InvokeOnLogMessage
3131
);
32-
#if UNITY_ANDROID && !UNITY_EDITOR
33-
string filePath = Constants.SCHEME_FILE + ANDROID_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
34-
#elif UNITY_EDITOR_OSX
35-
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(MAC_EDITOR_RESOURCES_DIRECTORY) + Constants.PASSPORT_HTML_FILE_NAME;
36-
#elif UNITY_STANDALONE_OSX
37-
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + MAC_DATA_DIRECTORY + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
38-
filePath = filePath.Replace(" ", "%20");
39-
#elif UNITY_IPHONE
40-
string filePath = Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
41-
#else
42-
string filePath = Constants.SCHEME_FILE + Path.GetFullPath(Application.dataPath) + Constants.PASSPORT_DATA_DIRECTORY_NAME + Constants.PASSPORT_HTML_FILE_NAME;
43-
#endif
44-
webViewObject.LoadURL(filePath);
32+
33+
webViewObject.LoadURL(GameBridge.GetFilePath());
4534
}
4635

4736
private void InvokeOnPostMessageError(string id, string message)
@@ -96,4 +85,6 @@ public void ClearStorage()
9685
#endif
9786

9887
}
99-
}
88+
}
89+
90+
#endif

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

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

0 commit comments

Comments
 (0)