Skip to content

Commit d82e9e0

Browse files
fix: android pr checks
1 parent c7a1b91 commit d82e9e0

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/Packages/Passport/Runtime/Scripts/Private/UI/AndroidVuplexWebView.cs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
1+
#nullable enable
12
using System;
23
using System.Collections.Generic;
34
using Cysharp.Threading.Tasks;
45
using UnityEngine;
56
using UnityEngine.UI;
67
using Immutable.Passport.Core.Logging;
8+
9+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
710
using Vuplex.WebView;
11+
#endif
812

913
namespace Immutable.Passport
1014
{
15+
/// <summary>
16+
/// Android implementation of IPassportWebView using Vuplex WebView
17+
/// Provides embedded WebView functionality within the Unity app (not external browser)
18+
/// This is different from AndroidPassportWebView which uses external browser for auth flows
19+
/// </summary>
1120
public class AndroidVuplexWebView : IPassportWebView
1221
{
13-
private const string TAG = "[AndroidWebView]";
14-
private CanvasWebViewPrefab _webViewPrefab;
22+
private const string TAG = "[AndroidVuplexWebView]";
23+
24+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
25+
private CanvasWebViewPrefab? _webViewPrefab;
26+
#endif
1527
private readonly Dictionary<string, Action<string>> _jsHandlers = new Dictionary<string, Action<string>>();
1628
private readonly RawImage _canvasReference;
1729
private bool _isInitialized = false;
1830

19-
public event Action<string> OnJavaScriptMessage;
20-
public event Action OnLoadFinished;
21-
public event Action OnLoadStarted;
31+
public event Action<string>? OnJavaScriptMessage;
32+
public event Action? OnLoadFinished;
33+
public event Action? OnLoadStarted;
2234

2335
// Safe access - check initialization
36+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
2437
public bool IsVisible => _webViewPrefab?.Visible ?? false;
2538
public string CurrentUrl => _webViewPrefab?.WebView?.Url ?? "";
39+
#else
40+
public bool IsVisible => false;
41+
public string CurrentUrl => "";
42+
#endif
2643

2744
public AndroidVuplexWebView(RawImage canvasReference)
2845
{
@@ -37,6 +54,7 @@ public void Initialize(PassportWebViewConfig config)
3754
return;
3855
}
3956

57+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
4058
try
4159
{
4260
PassportLogger.Info($"{TAG} Initializing Vuplex WebView...");
@@ -49,8 +67,13 @@ public void Initialize(PassportWebViewConfig config)
4967
PassportLogger.Error($"{TAG} Failed to initialize: {ex.Message}");
5068
throw;
5169
}
70+
#else
71+
PassportLogger.Warn($"{TAG} Vuplex WebView is only supported on Android builds, not in editor");
72+
_isInitialized = true;
73+
#endif
5274
}
5375

76+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
5477
private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
5578
{
5679
try
@@ -107,65 +130,80 @@ private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
107130
throw;
108131
}
109132
}
133+
#endif
110134

111135
public void LoadUrl(string url)
112136
{
137+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
113138
if (!_isInitialized || _webViewPrefab?.WebView == null)
114139
{
115140
PassportLogger.Error($"{TAG} Cannot load URL - WebView not initialized");
116141
return;
117142
}
118143

119144
_webViewPrefab.WebView.LoadUrl(url);
145+
#else
146+
PassportLogger.Warn($"{TAG} LoadUrl not supported in editor mode");
147+
#endif
120148
}
121149

122150
public void Show()
123151
{
152+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
124153
if (_webViewPrefab != null)
125154
{
126155
_webViewPrefab.Visible = true;
127156
}
157+
#endif
128158
}
129159

130160
public void Hide()
131161
{
162+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
132163
if (_webViewPrefab != null)
133164
{
134165
_webViewPrefab.Visible = false;
135166
}
167+
#endif
136168
}
137169

138170
public void ExecuteJavaScript(string js)
139171
{
172+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
140173
if (!_isInitialized || _webViewPrefab?.WebView == null)
141174
{
142175
PassportLogger.Error($"{TAG} Cannot execute JavaScript - WebView not initialized");
143176
return;
144177
}
145178

146179
_webViewPrefab.WebView.ExecuteJavaScript(js);
180+
#endif
147181
}
148182

149183
public void RegisterJavaScriptMethod(string methodName, Action<string> handler)
150184
{
151185
_jsHandlers[methodName] = handler;
152186

187+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
153188
if (_isInitialized && _webViewPrefab?.WebView != null)
154189
{
155190
ExecuteJavaScript($"window.{methodName}=d=>window.vuplex?.postMessage('{methodName}:'+(typeof d==='object'?JSON.stringify(d):d))");
156191
}
192+
#endif
157193
}
158194

159195
public void Dispose()
160196
{
197+
#if UNITY_ANDROID && !UNITY_EDITOR && VUPLEX_AVAILABLE && VUPLEX_AVAILABLE
161198
if (_webViewPrefab != null)
162199
{
163200
_webViewPrefab.Destroy();
164201
_webViewPrefab = null;
165202
}
203+
#endif
166204

167205
_jsHandlers.Clear();
168206
_isInitialized = false;
169207
}
170208
}
171-
}
209+
}

0 commit comments

Comments
 (0)