Skip to content

Commit

Permalink
safer null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaina committed Nov 2, 2023
1 parent 278bb70 commit 1f67bfa
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Runtime/WebViewPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ public void LoadWebView(string loginToken = "")
#else
InitializeAndShowWebView(loginToken);
#endif
messagePanel.SetMessage(messageType);
messagePanel.SetVisible(true);
if(messagePanel)
{
messagePanel.SetMessage(messageType);
messagePanel.SetVisible(true);
}

SetScreenPadding();
}

Expand Down Expand Up @@ -93,7 +97,11 @@ public void ReloadWithLoginToken(string loginToken = "")
/// </summary>
public void SetVisible(bool visible)
{
messagePanel.SetVisible(visible);
if(messagePanel)
{
messagePanel.SetVisible(visible);
}

if (webViewObject != null)
{
webViewObject.IsVisible = visible;
Expand Down Expand Up @@ -124,7 +132,10 @@ private void SetScreenPadding()
webViewObject.SetMargins(screenPadding.left, screenPadding.top, screenPadding.right, screenPadding.bottom);
}

messagePanel.SetMargins(screenPadding.left, screenPadding.top, screenPadding.right, screenPadding.bottom);
if(messagePanel)
{
messagePanel.SetMargins(screenPadding.left, screenPadding.top, screenPadding.right, screenPadding.bottom);
}
}

// Receives message from RPM website, which contains avatar URL.
Expand All @@ -133,7 +144,8 @@ private void OnWebMessageReceived(string message)
SDKLogger.AvatarLoaderLogger.Log(TAG, $"--- WebView Message: {message}");
try
{
HandleEvents(JsonConvert.DeserializeObject<WebMessage>(message));
var jsonMessage = JsonConvert.DeserializeObject<WebMessage>(message);
HandleEvents(jsonMessage);
}
catch (Exception e)
{
Expand All @@ -146,18 +158,22 @@ private void HandleEvents(WebMessage webMessage)
switch (webMessage.eventName)
{
case WebViewEvents.AVATAR_EXPORT:
OnAvatarCreated?.Invoke(webMessage.GetAvatarUrl());
if(OnAvatarCreated != null)
OnAvatarCreated.Invoke(webMessage.GetAvatarUrl());
HideAndClearCache();
break;
case WebViewEvents.USER_SET:
OnUserSet?.Invoke(webMessage.GetUserId());
if(OnUserSet != null)
OnUserSet.Invoke(webMessage.GetUserId());

break;
case WebViewEvents.ASSET_UNLOCK:
OnAssetUnlock?.Invoke(webMessage.GetAssetRecord());
if(OnAssetUnlock != null)
OnAssetUnlock.Invoke(webMessage.GetAssetRecord());
break;
case WebViewEvents.USER_AUTHORIZED:
OnUserAuthorized?.Invoke(webMessage.GetUserId());
if(OnUserAuthorized != null)
OnUserAuthorized.Invoke(webMessage.GetUserId());
break;
}
}
Expand Down

0 comments on commit 1f67bfa

Please sign in to comment.