66using UnityEngine . UI ;
77using Immutable . Passport . Core . Logging ;
88
9- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
9+ #if ( UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX ) && VUPLEX_WEBVIEW
1010using Vuplex . WebView ;
11- #endif
1211
1312namespace Immutable . Passport
1413{
@@ -21,9 +20,7 @@ public class MacOSPassportWebView : IPassportWebView
2120 {
2221 private const string TAG = "[MacOSPassportWebView]" ;
2322
24- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
2523 private CanvasWebViewPrefab ? _webViewPrefab ;
26- #endif
2724 private readonly Dictionary < string , Action < string > > _jsHandlers = new Dictionary < string , Action < string > > ( ) ;
2825 private readonly RawImage _canvasReference ;
2926 private bool _isInitialized = false ;
@@ -33,14 +30,8 @@ public class MacOSPassportWebView : IPassportWebView
3330 public event Action ? OnLoadFinished ;
3431 public event Action ? OnLoadStarted ;
3532
36- // Safe access - check initialization
37- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
3833 public bool IsVisible => _webViewPrefab ? . Visible ?? false ;
3934 public string CurrentUrl => _webViewPrefab ? . WebView ? . Url ?? "" ;
40- #else
41- public bool IsVisible => false ;
42- public string CurrentUrl => "" ;
43- #endif
4435
4536 public MacOSPassportWebView ( RawImage canvasReference )
4637 {
@@ -55,7 +46,6 @@ public void Initialize(PassportWebViewConfig config)
5546 return ;
5647 }
5748
58- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
5949 try
6050 {
6151 PassportLogger . Info ( $ "{ TAG } Initializing MacOS WebView...") ;
@@ -68,13 +58,8 @@ public void Initialize(PassportWebViewConfig config)
6858 PassportLogger . Error ( $ "{ TAG } Failed to initialize: { ex . Message } ") ;
6959 throw ;
7060 }
71- #else
72- PassportLogger . Warn ( $ "{ TAG } Vuplex WebView is only supported on MacOS builds, not in editor") ;
73- _isInitialized = true ;
74- #endif
7561 }
7662
77- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
7863 private async UniTaskVoid InitializeAsync ( PassportWebViewConfig config )
7964 {
8065 try
@@ -162,11 +147,9 @@ private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
162147 throw ;
163148 }
164149 }
165- #endif
166150
167151 public void LoadUrl ( string url )
168152 {
169- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
170153 if ( ! _isInitialized || _webViewPrefab ? . WebView == null )
171154 {
172155 PassportLogger . Info ( $ "{ TAG } WebView not ready, queueing URL: { url } ") ;
@@ -176,50 +159,35 @@ public void LoadUrl(string url)
176159
177160 PassportLogger . Info ( $ "{ TAG } Loading URL: { url } ") ;
178161 _webViewPrefab . WebView . LoadUrl ( url ) ;
179- #else
180- PassportLogger . Warn ( $ "{ TAG } LoadUrl not supported in MacOS editor mode") ;
181- #endif
182162 }
183163
184164 public void Show ( )
185165 {
186- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
187166 if ( _webViewPrefab != null )
188167 {
189168 _webViewPrefab . Visible = true ;
190169 PassportLogger . Info ( $ "{ TAG } WebView shown") ;
191170 }
192- #else
193- PassportLogger . Info ( $ "{ TAG } Show() called (editor mode)") ;
194- #endif
195171 }
196172
197173 public void Hide ( )
198174 {
199- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
200175 if ( _webViewPrefab != null )
201176 {
202177 _webViewPrefab . Visible = false ;
203178 PassportLogger . Info ( $ "{ TAG } WebView hidden") ;
204179 }
205- #else
206- PassportLogger . Info ( $ "{ TAG } Hide() called (editor mode)") ;
207- #endif
208180 }
209181
210182 public void ExecuteJavaScript ( string js )
211183 {
212- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
213184 if ( ! _isInitialized || _webViewPrefab ? . WebView == null )
214185 {
215186 PassportLogger . Error ( $ "{ TAG } Cannot execute JavaScript - MacOS WebView not initialized") ;
216187 return ;
217188 }
218189
219190 _webViewPrefab . WebView . ExecuteJavaScript ( js ) ;
220- #else
221- PassportLogger . Warn ( $ "{ TAG } ExecuteJavaScript not supported in MacOS editor mode") ;
222- #endif
223191 }
224192
225193 public void RegisterJavaScriptMethod ( string methodName , Action < string > handler )
@@ -233,17 +201,16 @@ public void RegisterJavaScriptMethod(string methodName, Action<string> handler)
233201
234202 public void Dispose ( )
235203 {
236- #if UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX
237204 if ( _webViewPrefab != null )
238205 {
239206 PassportLogger . Info ( $ "{ TAG } Disposing MacOS WebView") ;
240207 _webViewPrefab . Destroy ( ) ;
241208 _webViewPrefab = null ;
242209 }
243- #endif
244210
245211 _jsHandlers . Clear ( ) ;
246212 _isInitialized = false ;
247213 }
248214 }
249215}
216+ #endif
0 commit comments