Skip to content

Commit 8909d99

Browse files
committed
fix: add vuplex webview compilation flags for mobile webviews
1 parent a5b314f commit 8909d99

File tree

2 files changed

+4
-58
lines changed

2 files changed

+4
-58
lines changed

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

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
using UnityEngine.UI;
77
using Immutable.Passport.Core.Logging;
88

9-
#if UNITY_ANDROID && !UNITY_EDITOR
9+
#if UNITY_ANDROID && VUPLEX_WEBVIEW
1010
using Vuplex.WebView;
11-
#endif
1211

1312
namespace Immutable.Passport
1413
{
@@ -21,9 +20,7 @@ public class AndroidVuplexWebView : IPassportWebView
2120
{
2221
private const string TAG = "[AndroidVuplexWebView]";
2322

24-
#if UNITY_ANDROID && !UNITY_EDITOR
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;
@@ -32,14 +29,8 @@ public class AndroidVuplexWebView : IPassportWebView
3229
public event Action? OnLoadFinished;
3330
public event Action? OnLoadStarted;
3431

35-
// Safe access - check initialization
36-
#if UNITY_ANDROID && !UNITY_EDITOR
3732
public bool IsVisible => _webViewPrefab?.Visible ?? false;
3833
public string CurrentUrl => _webViewPrefab?.WebView?.Url ?? "";
39-
#else
40-
public bool IsVisible => false;
41-
public string CurrentUrl => "";
42-
#endif
4334

4435
public AndroidVuplexWebView(RawImage canvasReference)
4536
{
@@ -54,7 +45,6 @@ public void Initialize(PassportWebViewConfig config)
5445
return;
5546
}
5647

57-
#if UNITY_ANDROID && !UNITY_EDITOR
5848
try
5949
{
6050
PassportLogger.Info($"{TAG} Initializing Vuplex WebView...");
@@ -67,13 +57,8 @@ public void Initialize(PassportWebViewConfig config)
6757
PassportLogger.Error($"{TAG} Failed to initialize: {ex.Message}");
6858
throw;
6959
}
70-
#else
71-
PassportLogger.Warn($"{TAG} Vuplex WebView is only supported on Android builds, not in editor");
72-
_isInitialized = true;
73-
#endif
7460
}
7561

76-
#if UNITY_ANDROID && !UNITY_EDITOR
7762
private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
7863
{
7964
try
@@ -155,54 +140,43 @@ private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
155140
throw;
156141
}
157142
}
158-
#endif
159143

160144
public void LoadUrl(string url)
161145
{
162-
#if UNITY_ANDROID && !UNITY_EDITOR
163146
if (!_isInitialized || _webViewPrefab?.WebView == null)
164147
{
165148
PassportLogger.Error($"{TAG} Cannot load URL - WebView not initialized");
166149
return;
167150
}
168151

169152
_webViewPrefab.WebView.LoadUrl(url);
170-
#else
171-
PassportLogger.Warn($"{TAG} LoadUrl not supported in editor mode");
172-
#endif
173153
}
174154

175155
public void Show()
176156
{
177-
#if UNITY_ANDROID && !UNITY_EDITOR
178157
if (_webViewPrefab != null)
179158
{
180159
_webViewPrefab.Visible = true;
181160
}
182-
#endif
183161
}
184162

185163
public void Hide()
186164
{
187-
#if UNITY_ANDROID && !UNITY_EDITOR
188165
if (_webViewPrefab != null)
189166
{
190167
_webViewPrefab.Visible = false;
191168
}
192-
#endif
193169
}
194170

195171
public void ExecuteJavaScript(string js)
196172
{
197-
#if UNITY_ANDROID && !UNITY_EDITOR
198173
if (!_isInitialized || _webViewPrefab?.WebView == null)
199174
{
200175
PassportLogger.Error($"{TAG} Cannot execute JavaScript - WebView not initialized");
201176
return;
202177
}
203178

204179
_webViewPrefab.WebView.ExecuteJavaScript(js);
205-
#endif
206180
}
207181

208182
public void RegisterJavaScriptMethod(string methodName, Action<string> handler)
@@ -216,16 +190,15 @@ public void RegisterJavaScriptMethod(string methodName, Action<string> handler)
216190

217191
public void Dispose()
218192
{
219-
#if UNITY_ANDROID && !UNITY_EDITOR
220193
if (_webViewPrefab != null)
221194
{
222195
_webViewPrefab.Destroy();
223196
_webViewPrefab = null;
224197
}
225-
#endif
226198

227199
_jsHandlers.Clear();
228200
_isInitialized = false;
229201
}
230202
}
231203
}
204+
#endif

src/Packages/Passport/Runtime/Scripts/Private/UI/WebViews/iOSPassportWebView.cs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
using UnityEngine.UI;
77
using Immutable.Passport.Core.Logging;
88

9-
#if UNITY_IOS && !UNITY_EDITOR
9+
#if UNITY_IOS && VUPLEX_WEBVIEW
1010
using Vuplex.WebView;
11-
#endif
1211

1312
namespace Immutable.Passport
1413
{
@@ -21,9 +20,7 @@ public class iOSPassportWebView : IPassportWebView
2120
{
2221
private const string TAG = "[iOSPassportWebView]";
2322

24-
#if UNITY_IOS && !UNITY_EDITOR
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;
@@ -32,14 +29,8 @@ public class iOSPassportWebView : IPassportWebView
3229
public event Action? OnLoadFinished;
3330
public event Action? OnLoadStarted;
3431

35-
// Safe access - check initialization
36-
#if UNITY_IOS && !UNITY_EDITOR
3732
public bool IsVisible => _webViewPrefab?.Visible ?? false;
3833
public string CurrentUrl => _webViewPrefab?.WebView?.Url ?? "";
39-
#else
40-
public bool IsVisible => false;
41-
public string CurrentUrl => "";
42-
#endif
4334

4435
public iOSPassportWebView(RawImage canvasReference)
4536
{
@@ -54,7 +45,6 @@ public void Initialize(PassportWebViewConfig config)
5445
return;
5546
}
5647

57-
#if UNITY_IOS && !UNITY_EDITOR
5848
try
5949
{
6050
PassportLogger.Info($"{TAG} Initializing iOS WebView...");
@@ -67,13 +57,8 @@ public void Initialize(PassportWebViewConfig config)
6757
PassportLogger.Error($"{TAG} Failed to initialize: {ex.Message}");
6858
throw;
6959
}
70-
#else
71-
PassportLogger.Warn($"{TAG} Vuplex WebView is only supported on iOS builds, not in editor");
72-
_isInitialized = true;
73-
#endif
7460
}
7561

76-
#if UNITY_IOS && !UNITY_EDITOR
7762
private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
7863
{
7964
try
@@ -149,54 +134,43 @@ private async UniTaskVoid InitializeAsync(PassportWebViewConfig config)
149134
throw;
150135
}
151136
}
152-
#endif
153137

154138
public void LoadUrl(string url)
155139
{
156-
#if UNITY_IOS && !UNITY_EDITOR
157140
if (!_isInitialized || _webViewPrefab?.WebView == null)
158141
{
159142
PassportLogger.Error($"{TAG} Cannot load URL - iOS WebView not initialized");
160143
return;
161144
}
162145

163146
_webViewPrefab.WebView.LoadUrl(url);
164-
#else
165-
PassportLogger.Warn($"{TAG} LoadUrl not supported in iOS editor mode");
166-
#endif
167147
}
168148

169149
public void Show()
170150
{
171-
#if UNITY_IOS && !UNITY_EDITOR
172151
if (_webViewPrefab != null)
173152
{
174153
_webViewPrefab.Visible = true;
175154
}
176-
#endif
177155
}
178156

179157
public void Hide()
180158
{
181-
#if UNITY_IOS && !UNITY_EDITOR
182159
if (_webViewPrefab != null)
183160
{
184161
_webViewPrefab.Visible = false;
185162
}
186-
#endif
187163
}
188164

189165
public void ExecuteJavaScript(string js)
190166
{
191-
#if UNITY_IOS && !UNITY_EDITOR
192167
if (!_isInitialized || _webViewPrefab?.WebView == null)
193168
{
194169
PassportLogger.Error($"{TAG} Cannot execute JavaScript - iOS WebView not initialized");
195170
return;
196171
}
197172

198173
_webViewPrefab.WebView.ExecuteJavaScript(js);
199-
#endif
200174
}
201175

202176
public void RegisterJavaScriptMethod(string methodName, Action<string> handler)
@@ -210,16 +184,15 @@ public void RegisterJavaScriptMethod(string methodName, Action<string> handler)
210184

211185
public void Dispose()
212186
{
213-
#if UNITY_IOS && !UNITY_EDITOR
214187
if (_webViewPrefab != null)
215188
{
216189
_webViewPrefab.Destroy();
217190
_webViewPrefab = null;
218191
}
219-
#endif
220192

221193
_jsHandlers.Clear();
222194
_isInitialized = false;
223195
}
224196
}
225197
}
198+
#endif

0 commit comments

Comments
 (0)