Skip to content

Commit 6a59c4b

Browse files
feat: add GameBridgeServer support for macOS
Expand GameBridgeServer to include macOS builds to enable viem/Fetch API compatibility. Changes: - GameBridgeServer.cs: Add UNITY_STANDALONE_OSX to compilation directives - GreeBrowserClient.cs: Use GameBridgeServer on macOS instead of file:// URLs - IWebBrowserClient.cs: Include macOS in Dispose() interface requirement - Passport.cs: Call Dispose() for macOS to cleanup GameBridgeServer Background: - viem (used in ts-immutable-sdk 2.12.4+) requires Fetch API - file:// URLs have CORS/Fetch API restrictions - GameBridgeServer serves via http://localhost:51990/ to provide proper origin - Windows already uses this approach (PR #646) - macOS now needs same solution for viem compatibility This resolves the "App stuck in Initialisation" issue on macOS.
1 parent 83bd2fa commit 6a59c4b

4 files changed

Lines changed: 32 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,8 @@ private void OnPlayModeStateChanged(PlayModeStateChange state)
675675
/// </summary>
676676
private void DisposeAll()
677677
{
678-
// Dispose of the web browser client for Windows only
679-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
678+
// Dispose of the web browser client for Windows and macOS (GameBridgeServer cleanup)
679+
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
680680
if (_webBrowserClient != null)
681681
{
682682
_webBrowserClient.Dispose();

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public class GreeBrowserClient : IWebBrowserClient
1515
public event OnUnityPostMessageDelegate OnAuthPostMessage;
1616
public event OnUnityPostMessageErrorDelegate OnPostMessageError;
1717

18+
#if UNITY_STANDALONE_OSX
19+
private GameBridgeServer? gameBridgeServer;
20+
#endif
21+
1822
public GreeBrowserClient()
1923
{
2024
#if (UNITY_ANDROID && UNITY_EDITOR_OSX) || (UNITY_IPHONE && UNITY_EDITOR_OSX)
@@ -35,7 +39,20 @@ public GreeBrowserClient()
3539
log: InvokeOnLogMessage
3640
);
3741

38-
webViewObject.LoadURL(GameBridge.GetFilePath());
42+
#if UNITY_STANDALONE_OSX
43+
// Use GameBridgeServer to serve index.html via http://localhost
44+
// This provides proper origin for viem/Fetch API compatibility
45+
PassportLogger.Info($"{TAG} Starting GameBridgeServer for macOS...");
46+
gameBridgeServer = new GameBridgeServer(GameBridge.GetFileSystemPath());
47+
string serverUrl = gameBridgeServer.Start();
48+
PassportLogger.Info($"{TAG} Loading URL: {serverUrl}");
49+
webViewObject.LoadURL(serverUrl);
50+
#else
51+
// Android, iOS, WebGL use file:// URLs
52+
string fileUrl = GameBridge.GetFilePath();
53+
PassportLogger.Info($"{TAG} Loading file URL: {fileUrl}");
54+
webViewObject.LoadURL(fileUrl);
55+
#endif
3956
}
4057

4158
private void InvokeOnPostMessageError(string id, string message)
@@ -89,6 +106,15 @@ public void ClearStorage()
89106
}
90107
#endif
91108

109+
#if UNITY_STANDALONE_OSX
110+
public void Dispose()
111+
{
112+
PassportLogger.Info($"{TAG} Disposing GreeBrowserClient...");
113+
gameBridgeServer?.Dispose();
114+
gameBridgeServer = null;
115+
}
116+
#endif
117+
92118
}
93119
}
94120

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
1+
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
22

33
using System;
44
using System.IO;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public interface IWebBrowserClient
1212
void ExecuteJs(string js);
1313
void LaunchAuthURL(string url, string redirectUri);
1414

15-
// Required for Windows browser only
16-
#if UNITY_STANDALONE_WIN || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
15+
// Required for Windows and macOS browsers (GameBridgeServer cleanup)
16+
#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || (UNITY_ANDROID && UNITY_EDITOR_WIN) || (UNITY_IPHONE && UNITY_EDITOR_WIN)
1717
void Dispose();
1818
#endif
1919

0 commit comments

Comments
 (0)