com.xd.sdk.common 7.0.1 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/Editor/Android/XDCommonAndroidGradleProcessor.cs +1 -3
  2. package/Editor/iOS/XDGIOSCommonProcessor.cs +7 -5
  3. package/Plugins/Android/libs/XDGCommon_7.1.0.aar +0 -0
  4. package/Plugins/Android/libs/XDGTapTapWrapperInternal_7.1.0.aar +0 -0
  5. package/Plugins/iOS/XDCommonSDK.framework/Headers/NSDictionary+XDG.h +1 -0
  6. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDCommonSDK.h +2 -0
  7. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDFacebookInfo.h +2 -0
  8. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGAnnouncementConfig.h +26 -0
  9. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGAnnouncementManager.h +28 -0
  10. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGBridgeWeb.h +5 -3
  11. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGConfig.h +2 -2
  12. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGKuaiShouShareParam.h.meta +7 -0
  13. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGLogger.h +2 -0
  14. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGWebParams.h +2 -1
  15. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDKuaiShouInfo.h.meta +7 -0
  16. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDVersion.h +3 -3
  17. package/Plugins/iOS/XDCommonSDK.framework/Info.plist +0 -0
  18. package/Plugins/iOS/XDCommonSDK.framework/XDCommonSDK +0 -0
  19. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/Headers/XDTapSDK4WrapperSDK.h +3 -3
  20. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/Info.plist +0 -0
  21. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/de.lproj/Localizable.strings.meta +7 -0
  22. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/de.lproj.meta +8 -0
  23. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/en.lproj/Localizable.strings.meta +7 -0
  24. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/en.lproj.meta +8 -0
  25. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/es.lproj/Localizable.strings.meta +7 -0
  26. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/es.lproj.meta +8 -0
  27. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/fr.lproj/Localizable.strings.meta +7 -0
  28. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/fr.lproj.meta +8 -0
  29. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/in.lproj/Localizable.strings.meta +7 -0
  30. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/in.lproj.meta +8 -0
  31. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ja.lproj/Localizable.strings.meta +7 -0
  32. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ja.lproj.meta +8 -0
  33. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ko.lproj/Localizable.strings.meta +7 -0
  34. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ko.lproj.meta +8 -0
  35. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ms.lproj/Localizable.strings.meta +7 -0
  36. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ms.lproj.meta +8 -0
  37. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/pt.lproj/Localizable.strings.meta +7 -0
  38. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/pt.lproj.meta +8 -0
  39. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ru.lproj/Localizable.strings.meta +7 -0
  40. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/ru.lproj.meta +8 -0
  41. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/th.lproj/Localizable.strings.meta +7 -0
  42. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/th.lproj.meta +8 -0
  43. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/tr.lproj/Localizable.strings.meta +7 -0
  44. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/tr.lproj.meta +8 -0
  45. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/vi.lproj/Localizable.strings.meta +7 -0
  46. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/vi.lproj.meta +8 -0
  47. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/zh-Hans.lproj/Localizable.strings.meta +7 -0
  48. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/zh-Hans.lproj.meta +8 -0
  49. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/zh-Hant.lproj/Localizable.strings.meta +7 -0
  50. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle/zh-Hant.lproj.meta +8 -0
  51. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/TapSupportResource.bundle.meta +8 -0
  52. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/XDTapSDK4WrapperSDK +0 -0
  53. package/Resources/Prefabs/XDSDKUI.prefab +1 -1
  54. package/Resources/Prefabs/XDWebBridgeView.prefab +1 -1
  55. package/Runtime/Internal/Mobile/Bridge/BridgeConstants.cs +7 -0
  56. package/Runtime/Internal/Mobile/CommonFeaturesImpl.cs +1 -0
  57. package/Runtime/Internal/Standalone/CommonFeaturesImpl.cs +12 -7
  58. package/Runtime/Internal/Standalone/Config/AppConfig.cs +3 -1
  59. package/Runtime/Internal/Standalone/Config/Config.cs +3 -1
  60. package/Runtime/Internal/Standalone/Config/ConfigModule.cs +8 -4
  61. package/Runtime/Internal/Standalone/Utils/SteamWrapper.cs +77 -32
  62. package/Runtime/Internal/Standalone/Web/Function/BackgroundColorWebFunction.cs +1 -1
  63. package/Runtime/Internal/Standalone/Web/Function/CloseVisibleWebFunction.cs +1 -2
  64. package/Runtime/Internal/Standalone/Web/Function/CloseWebFunction.cs +2 -5
  65. package/Runtime/Internal/Standalone/Web/Function/GameMessageWebFunction.cs +1 -1
  66. package/Runtime/Internal/Standalone/Web/Function/NavigationWebFunction.cs +1 -1
  67. package/Runtime/Internal/Standalone/Web/PreloadWebTransmit.cs +1 -0
  68. package/Runtime/Internal/Standalone/Web/PreloadWebTransmit.cs.meta +3 -0
  69. package/Runtime/Internal/Standalone/Web/WebBridgeController.cs +34 -27
  70. package/Runtime/Internal/Standalone/Web/WebRequest.cs +62 -13
  71. package/Runtime/Internal/Standalone/Web/XDWebBridgeView.cs +18 -37
  72. package/package.json +2 -2
  73. package/Plugins/Android/libs/XDGCommon_7.0.1.aar +0 -0
  74. package/Plugins/Android/libs/XDGTapTapWrapperInternal_7.0.1.aar +0 -0
  75. /package/Plugins/Android/libs/{XDGBridgeCommon_v7_7.0.1.aar → XDGBridgeCommon_v7_7.1.0.aar} +0 -0
  76. /package/Plugins/Android/libs/{XDGBridgeCommon_v7_7.0.1.aar.meta → XDGBridgeCommon_v7_7.1.0.aar.meta} +0 -0
  77. /package/Plugins/Android/libs/{XDGCommon_7.0.1.aar.meta → XDGCommon_7.1.0.aar.meta} +0 -0
  78. /package/Plugins/Android/libs/{XDGTapTapWrapperInternal_7.0.1.aar.meta → XDGTapTapWrapperInternal_7.1.0.aar.meta} +0 -0
  79. /package/Plugins/Android/libs/{XDTapTapWrapper_7.0.1.aar → XDTapTapWrapper_7.1.0.aar} +0 -0
  80. /package/Plugins/Android/libs/{XDTapTapWrapper_7.0.1.aar.meta → XDTapTapWrapper_7.1.0.aar.meta} +0 -0
@@ -42,7 +42,7 @@ namespace XD.SDK.Common.Internal.Standalone
42
42
  [JsonProperty("anit")] public AntiConfig Anti { get; internal set; }
43
43
 
44
44
  [JsonProperty("customer_disable")] public bool CustomerDisable { get; internal set; }
45
-
45
+
46
46
  [JsonIgnore] public string Region { get; internal set; }
47
47
 
48
48
  [JsonIgnore] public List<BindEntryConfig> BindEntryConfigs { get; internal set; }
@@ -53,6 +53,7 @@ namespace XD.SDK.Common.Internal.Standalone
53
53
 
54
54
  [JsonIgnore] public bool DisableAutoLogin2Tap { get; set; }
55
55
 
56
+ [JsonIgnore] public bool DisableWebPreload { get; set; }
56
57
 
57
58
  /// <summary>
58
59
  /// 判断是否为海外
@@ -63,6 +64,7 @@ namespace XD.SDK.Common.Internal.Standalone
63
64
  {
64
65
  #if UNITY_STANDALONE_WIN
65
66
  // win 环境 + packageType 为 tapPC + clientPublicKey 不为空
67
+ XDGLogger.Debug($"UsingTapPC:{IsGlobal} pacakgeType:{PackageType} TapConfig:{TapConfig != null} !clientPublicKey:{!string.IsNullOrEmpty(TapConfig?.ClientPublicKey)}");
66
68
  return !IsGlobal && string.Equals(PackageType, XDGPackageType.PackageTypePCTapTap) && TapConfig != null && !string.IsNullOrEmpty(TapConfig.ClientPublicKey);
67
69
  #endif
68
70
  return false;
@@ -22,8 +22,10 @@ namespace XD.SDK.Common.Internal.Standalone
22
22
  [JsonProperty("webWhiteList")] public List<string> WebWhiteList { get; private set; }
23
23
 
24
24
  [JsonProperty("disableAutoLogin2Tap")] public bool DisableAutoLogin2Tap { get; private set; }
25
-
25
+
26
26
  [JsonProperty("anti")] public AntiConfig Anti { get; private set; }
27
+
28
+ [JsonProperty("disableWebPreload")] public bool DisableWebPreload { get; private set; }
27
29
  }
28
30
  }
29
31
  #endif
@@ -34,11 +34,11 @@ namespace XD.SDK.Common.Internal.Standalone
34
34
 
35
35
  private static string LoadConfigText()
36
36
  {
37
- #if UNITY_EDITOR
38
- var xdConfigFilePath = GetXDConfigPath(ConfigFile);
39
- #else
37
+ // #if UNITY_EDITOR
38
+ // var xdConfigFilePath = GetXDConfigPath(ConfigFile);
39
+ // #else
40
40
  var xdConfigFilePath = Path.Combine(Application.streamingAssetsPath, $"{ConfigFile}.json");
41
- #endif
41
+ // #endif
42
42
  return File.ReadAllText(xdConfigFilePath);
43
43
  }
44
44
 
@@ -199,6 +199,8 @@ namespace XD.SDK.Common.Internal.Standalone
199
199
  }
200
200
  }
201
201
 
202
+ _appConfig.DisableWebPreload = config.DisableWebPreload;
203
+
202
204
  _appConfig.DisableAutoLogin2Tap = config.DisableAutoLogin2Tap;
203
205
  }
204
206
 
@@ -249,6 +251,8 @@ namespace XD.SDK.Common.Internal.Standalone
249
251
  public static string CancelUrl => _appConfig.CancelUrl;
250
252
 
251
253
  public static bool CustomerDisable => _appConfig.CustomerDisable;
254
+
255
+ public static bool DisableWebPreload => _appConfig.DisableWebPreload;
252
256
  }
253
257
  }
254
258
  #endif
@@ -2,60 +2,93 @@
2
2
  using System;
3
3
  using System.Collections.Generic;
4
4
  using System.Collections.Concurrent;
5
+ using System.Linq;
6
+ using System.Reflection;
5
7
  using System.Threading.Tasks;
6
8
  using Steamworks;
7
9
  using Newtonsoft.Json;
8
10
 
9
- namespace XD.SDK.Common.Internal.Standalone {
10
- public class SteamWrapper : ISteamSDKWrapper {
11
+ namespace XD.SDK.Common.Internal.Standalone
12
+ {
13
+ public class SteamWrapper : ISteamSDKWrapper
14
+ {
11
15
  private readonly Callback<GetAuthSessionTicketResponse_t> getAuthSessionTicketResponseCallback;
12
16
  private readonly ConcurrentDictionary<HAuthTicket, Tuple<TaskCompletionSource<string>, string>> tickTasks;
13
17
 
14
18
  private readonly Callback<MicroTxnAuthorizationResponse_t> mircoTxnAuthorizationCallback;
15
19
  private readonly ConcurrentDictionary<ulong, TaskCompletionSource<string>> microTxnTasks;
20
+ private readonly Type _steamManagerType;
16
21
 
17
- public SteamWrapper() {
22
+ public SteamWrapper()
23
+ {
18
24
  tickTasks = new ConcurrentDictionary<HAuthTicket, Tuple<TaskCompletionSource<string>, string>>();
19
25
 
20
- getAuthSessionTicketResponseCallback = Callback<GetAuthSessionTicketResponse_t>.Create((GetAuthSessionTicketResponse_t pCallback) => {
26
+ getAuthSessionTicketResponseCallback = Callback<GetAuthSessionTicketResponse_t>.Create((GetAuthSessionTicketResponse_t pCallback) =>
27
+ {
21
28
  HAuthTicket authTicket = pCallback.m_hAuthTicket;
22
- if (tickTasks.TryRemove(authTicket, out Tuple<TaskCompletionSource<string>, string> callback)) {
29
+ if (tickTasks.TryRemove(authTicket, out Tuple<TaskCompletionSource<string>, string> callback))
30
+ {
23
31
  callback.Item1.TrySetResult(callback.Item2);
24
32
  }
25
33
  });
26
34
 
27
35
  microTxnTasks = new ConcurrentDictionary<ulong, TaskCompletionSource<string>>();
28
36
 
29
- mircoTxnAuthorizationCallback = Callback<MicroTxnAuthorizationResponse_t>.Create((MicroTxnAuthorizationResponse_t pCallback) => {
37
+ mircoTxnAuthorizationCallback = Callback<MicroTxnAuthorizationResponse_t>.Create((MicroTxnAuthorizationResponse_t pCallback) =>
38
+ {
30
39
  // 根据 pCallback.m_ulOrderID 查找对应的回调
31
40
  ulong orderId = pCallback.m_ulOrderID;
32
41
  UnityEngine.Debug.Log($"recv order id: {orderId}");
33
- if (microTxnTasks.TryGetValue(orderId, out TaskCompletionSource<string> tcs)) {
34
- if (pCallback.m_bAuthorized == 1) {
35
- Dictionary<string, object> data = new Dictionary<string, object> {
42
+ if (microTxnTasks.TryGetValue(orderId, out TaskCompletionSource<string> tcs))
43
+ {
44
+ if (pCallback.m_bAuthorized == 1)
45
+ {
46
+ Dictionary<string, object> data = new Dictionary<string, object>
47
+ {
36
48
  { "appId", pCallback.m_unAppID },
37
49
  { "orderId", pCallback.m_ulOrderID },
38
50
  { "authorized", pCallback.m_bAuthorized }
39
51
  };
40
52
  tcs.TrySetResult(JsonConvert.SerializeObject(data));
41
- } else {
53
+ }
54
+ else
55
+ {
42
56
  tcs.TrySetException(new XDGError(ResponseCode.Common.Failed, "Steam authorization failure"));
43
57
  }
44
58
  }
45
59
  });
60
+
61
+ _steamManagerType = AppDomain.CurrentDomain.GetAssemblies()
62
+ .SelectMany(a => a.GetTypes())
63
+ .FirstOrDefault(t => t.Name == "SteamManager");
64
+ }
65
+
66
+ private bool Initialized()
67
+ {
68
+ var initialized = false;
69
+ if (_steamManagerType == null) return false;
70
+ var prop = _steamManagerType.GetProperty("Initialized", BindingFlags.Public | BindingFlags.Static);
71
+ if (prop != null)
72
+ {
73
+ initialized = (bool)prop.GetValue(null);
74
+ }
75
+ return initialized;
46
76
  }
77
+
78
+ public Task<string> GetAuthTicket()
79
+ {
80
+ if (!Initialized())
81
+ {
82
+ throw new Exception("Steam did not initialize.");
83
+ }
47
84
 
48
- public Task<string> GetAuthTicket() {
49
- // if (!SteamManager.Initialized) {
50
- // throw new Exception("Steam did not initialize.");
51
- // }
52
85
 
53
86
  TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
54
87
 
55
88
  byte[] data = new byte[1024];
56
89
  HAuthTicket hTicket = SteamUser.GetAuthSessionTicket(data, 1024, out uint ticketLength);
57
90
  string ticket = BitConverter.ToString(data, 0, (int)ticketLength)
58
- .Replace("-", string.Empty);
91
+ .Replace("-", string.Empty);
59
92
  tickTasks.TryAdd(hTicket, new Tuple<TaskCompletionSource<string>, string>(tcs, ticket));
60
93
 
61
94
  return tcs.Task;
@@ -66,20 +99,26 @@ namespace XD.SDK.Common.Internal.Standalone {
66
99
  /// </summary>
67
100
  /// <param name="orderId"></param>
68
101
  /// <returns></returns>
69
- public Task<string> GetMicroTxn(ulong orderId) {
70
- // if (!SteamManager.Initialized) {
71
- // throw new Exception("Steam did not initialize.");
72
- // }
102
+ public Task<string> GetMicroTxn(ulong orderId)
103
+ {
104
+ if (!Initialized())
105
+ {
106
+ throw new Exception("Steam did not initialize.");
107
+ }
108
+
73
109
 
74
110
  TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
75
111
  microTxnTasks.TryAdd(orderId, tcs);
76
112
  return tcs.Task;
77
113
  }
78
114
 
79
- public string GetSteamId() {
80
- // if (!SteamManager.Initialized) {
81
- // throw new Exception("Steam did not initialize.");
82
- // }
115
+ public string GetSteamId()
116
+ {
117
+ if (!Initialized())
118
+ {
119
+ throw new Exception("Steam did not initialize.");
120
+ }
121
+
83
122
 
84
123
  try
85
124
  {
@@ -93,18 +132,24 @@ namespace XD.SDK.Common.Internal.Standalone {
93
132
  }
94
133
  }
95
134
 
96
- public string GetSteamLanguage() {
97
- // if (!SteamManager.Initialized) {
98
- // throw new Exception("Steam did not initialize.");
99
- // }
100
-
135
+ public string GetSteamLanguage()
136
+ {
137
+ if (!Initialized())
138
+ {
139
+ throw new Exception("Steam did not initialize.");
140
+ }
141
+
142
+
101
143
  return SteamApps.GetCurrentGameLanguage();
102
144
  }
103
145
 
104
- public string GetSteamCountry() {
105
- // if (!SteamManager.Initialized) {
106
- // throw new Exception("Steam did not initialize.");
107
- // }
146
+ public string GetSteamCountry()
147
+ {
148
+ if (!Initialized())
149
+ {
150
+ throw new Exception("Steam did not initialize.");
151
+ }
152
+
108
153
 
109
154
  try
110
155
  {
@@ -17,7 +17,7 @@ namespace XD.SDK.Common.Internal.Standalone
17
17
  public void Handler(IBridgeWebView webView, string data, Action<object> callbackFunction)
18
18
  {
19
19
  XDGLogger.Debug($"message from javascript by:{GetName()} with data:{data}");
20
- webView.ProviderWebTrans().Transparent(GetName(), data);
20
+ webView.ProviderWebTrans()?.Transparent(GetName(), data);
21
21
  }
22
22
  }
23
23
  }
@@ -15,8 +15,7 @@ namespace XD.SDK.Common.Internal.Standalone
15
15
 
16
16
  public void Handler(IBridgeWebView webView, string data, Action<object> callbackFunction)
17
17
  {
18
- XDGLogger.Debug($"message from javascript by:{GetName()} with data:{data}");
19
- webView.ProviderWebTrans().Transparent(Tag, data);
18
+ webView.ProviderWebTrans()?.Transparent(Tag, data);
20
19
  }
21
20
  }
22
21
  }
@@ -16,12 +16,9 @@ namespace XD.SDK.Common.Internal.Standalone
16
16
  {
17
17
  XDGLogger.Debug($"message from javascript by:{GetName()} with data:{data}");
18
18
  var dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);
19
- dic.TryGetValue("extra", out var extra);
20
- callbackFunction?.Invoke(new WebBridgeResponse.Success
21
- {
22
- Data = extra
23
- });
19
+ webView.ProviderWebTrans()?.TransObserver(WebActionEnum.CLOSE, dic);
24
20
  UIManager.Dismiss();
21
+ webView.Release();
25
22
  }
26
23
  }
27
24
  }
@@ -16,7 +16,7 @@ namespace XD.SDK.Common.Internal.Standalone
16
16
  {
17
17
  XDGLogger.Debug("GameMessageWebFunction.Handler()");
18
18
  var dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(data);
19
- webView.ProviderWebTrans().TransObserver(WebActionEnum.MESSAGE, dic);
19
+ webView.ProviderWebTrans()?.TransObserver(WebActionEnum.MESSAGE, dic);
20
20
  }
21
21
  }
22
22
  }
@@ -16,7 +16,7 @@ namespace XD.SDK.Common.Internal.Standalone
16
16
  public void Handler(IBridgeWebView webView, string data, Action<object> callbackFunction)
17
17
  {
18
18
  XDGLogger.Debug($"message from javascript by:{GetName()} with data:{data}");
19
- webView.ProviderWebTrans().Transparent(GetName(), data);
19
+ webView.ProviderWebTrans()?.Transparent(GetName(), data);
20
20
  }
21
21
  }
22
22
  }
@@ -0,0 +1 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
  public class PreloadWebTransmit : IWebTransmit
1
3
  {
2
4
  private readonly Action<WebActionEnum, Dictionary<string, object>> callback;
3
5
  private readonly Action dispose;
4
6
  public PreloadWebTransmit(Action<WebActionEnum, Dictionary<string, object>> callback, Action dispose)
5
7
  {
6
8
  this.dispose = dispose;
7
9
  this.callback = callback;
8
10
  }
9
11
  public void Transparent(string functionName, string data)
10
12
  {
11
13
  }
12
14
  public void TransObserver(WebActionEnum type, Dictionary<string, object> dict)
13
15
  {
14
16
  callback?.Invoke(type, dict);
15
17
  dispose?.Invoke();
16
18
  }
17
19
  }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 66be7c98de7f4406876c3e1d534fb3f6
3
+ timeCreated: 1759997344
@@ -34,39 +34,46 @@ namespace XD.SDK.Common.Internal.Standalone
34
34
 
35
35
  private void OnMessageEmitted()
36
36
  {
37
- webView.MessageEmitted += (_, args) =>
37
+ try
38
38
  {
39
- try
39
+ webView.MessageEmitted += (_, args) =>
40
40
  {
41
- if (!IsWhiteList())
42
- {
43
- XDGLogger.Debug($"WebBridgeController OnMessageEmitted 白名单校验失败");
44
- return;
45
- }
46
-
47
- var content = DecodeBase64String(args.Value);
48
- var dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
49
- if (dic == null)
41
+ try
50
42
  {
51
- XDGLogger.Debug($"WebBridgeController OnMessageEmitted 解析 jsBridge 参数失败");
52
- return;
43
+ if (!IsWhiteList())
44
+ {
45
+ XDGLogger.Debug($"WebBridgeController OnMessageEmitted 白名单校验失败");
46
+ return;
47
+ }
48
+
49
+ var content = DecodeBase64String(args.Value);
50
+ var dic = JsonConvert.DeserializeObject<Dictionary<string, object>>(content);
51
+ if (dic == null)
52
+ {
53
+ XDGLogger.Debug($"WebBridgeController OnMessageEmitted 解析 jsBridge 参数失败");
54
+ return;
55
+ }
56
+
57
+ if (dic.TryGetValue("responseId", out var responseId))
58
+ {
59
+ DispatchResponse(responseId as string, dic["responseData"]);
60
+ return;
61
+ }
62
+
63
+ dic.TryGetValue("handlerName", out var handlerName);
64
+ dic.TryGetValue("callbackId", out var callbackId);
65
+ DispatchHandler(handlerName as string, callbackId as string, dic["data"]);
53
66
  }
54
-
55
- if (dic.TryGetValue("responseId", out var responseId))
67
+ catch (Exception e)
56
68
  {
57
- DispatchResponse(responseId as string, dic["responseData"]);
58
- return;
69
+ XDGLogger.Debug(e.Message);
59
70
  }
60
-
61
- dic.TryGetValue("handlerName", out var handlerName);
62
- dic.TryGetValue("callbackId", out var callbackId);
63
- DispatchHandler(handlerName as string, callbackId as string, dic["data"]);
64
- }
65
- catch (Exception e)
66
- {
67
- XDGLogger.Debug(e.Message);
68
- }
69
- };
71
+ };
72
+ }
73
+ catch (Exception e)
74
+ {
75
+ XDGLogger.Debug(e.Message);
76
+ }
70
77
  }
71
78
 
72
79
  public void RegisterHandler(IWebFunction handler)
@@ -2,9 +2,10 @@
2
2
 
3
3
  using System;
4
4
  using System.Collections.Generic;
5
+ using System.Linq;
6
+ using System.Threading.Tasks;
5
7
  using Newtonsoft.Json;
6
8
  using Vuplex.WebView;
7
- using Task = System.Threading.Tasks.Task;
8
9
 
9
10
  namespace XD.SDK.Common.Internal.Standalone
10
11
  {
@@ -18,27 +19,75 @@ namespace XD.SDK.Common.Internal.Standalone
18
19
  return;
19
20
  }
20
21
 
22
+ {
23
+ var queryParams = ParseQueryString(url);
24
+ var noUI = GetValueOrDefault(queryParams, "xdNoUI", "0") == "1";
25
+ if (noUI)
26
+ {
27
+ PreloadWithCallback(url, callback, true);
28
+ return;
29
+ }
30
+ }
31
+
32
+ XDGLogger.Debug("===> OpenWebPage " + url);
33
+
21
34
  UIManager.ShowUI<XDWebBridgeView>("XDWebBridgeView", new Dictionary<string, object>
22
35
  {
23
36
  { "url", url },
24
37
  { "alpha", 0f },
25
38
  { "interceptor", functions }
26
- }, (code, data) =>
39
+ }, (code, data) => { callback?.Invoke((WebActionEnum)code, JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(data))); });
40
+ }
41
+
42
+ public static void Preload(string url)
43
+ {
44
+ PreloadWithCallback(url, null);
45
+ }
46
+
47
+ private static async void PreloadWithCallback(string url, Action<WebActionEnum, Dictionary<string, object>> callback, bool noUI = false)
48
+ {
49
+ XDGLogger.Debug("===> Preload " + url);
50
+
51
+ try
27
52
  {
28
- callback?.Invoke((WebActionEnum)code,
29
- JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(data)));
30
- });
53
+ var webView = Web.CreateWebView();
54
+ await webView.Init(1, 1);
55
+ var controller = new WebBridgeController(webView, new PreloadWebTransmit(callback, () => webView.Dispose()));
56
+ webView.LoadUrl(url);
57
+ await webView.WaitForNextPageLoadToFinish();
58
+ if (noUI) return;
59
+ await Task.Delay(15 * 1000);
60
+ controller.Release();
61
+ }
62
+ catch (Exception)
63
+ {
64
+ // ignored
65
+ }
66
+ }
67
+
68
+ internal static Dictionary<string, string> ParseQueryString(string url)
69
+ {
70
+ var uri = new Uri(url);
71
+ if (string.IsNullOrWhiteSpace(uri.Query))
72
+ {
73
+ return new Dictionary<string, string>();
74
+ }
75
+
76
+ var dic = uri.Query.Substring(1)
77
+ .Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
78
+ .Select(param => param.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries))
79
+ .GroupBy(part => part[0], part => part.Length > 1 ? part[1] : string.Empty)
80
+ .ToDictionary(group => group.Key, group => string.Join(",", group));
81
+ return dic;
31
82
  }
32
83
 
33
- public static async void Preload(string url)
84
+ internal static TValue GetValueOrDefault<TKey, TValue>(
85
+ Dictionary<TKey, TValue> dictionary,
86
+ TKey key,
87
+ TValue defaultValue)
34
88
  {
35
- var webView = Web.CreateWebView();
36
- await webView.Init(1, 1);
37
- var controller = new WebBridgeController(webView, null);
38
- webView.LoadUrl(url);
39
- await webView.WaitForNextPageLoadToFinish();
40
- await Task.Delay(60 * 1000);
41
- controller.Release();
89
+ if (dictionary == null) return defaultValue;
90
+ return dictionary.TryGetValue(key, out var obj) ? obj : defaultValue;
42
91
  }
43
92
  }
44
93
  }
@@ -73,23 +73,29 @@ namespace XD.SDK.Common.Internal.Standalone
73
73
  canvasWebViewPrefab.WebView.UrlChanged += OnUrlChanged;
74
74
  canvasWebViewPrefab.WebView.PageLoadFailed += OnPageLoadFailed;
75
75
  webBridgeController = new WebBridgeController(canvasWebViewPrefab.WebView, this);
76
- if (extra["interceptor"] != null)
76
+ if (extra != null && extra.TryGetValue("interceptor", out var value))
77
77
  {
78
- List<IWebFunction> interceptorFunctions = extra["interceptor"] as List<IWebFunction>;
78
+ List<IWebFunction> interceptorFunctions = value as List<IWebFunction>;
79
79
  if (interceptorFunctions != null)
80
80
  foreach (var interceptorFunction in interceptorFunctions)
81
81
  {
82
82
  webBridgeController.RegisterHandler(interceptorFunction);
83
83
  }
84
84
  }
85
-
86
85
  Reload();
87
86
  }
88
87
 
89
88
  private void OnDestroy()
90
89
  {
91
- canvasWebViewPrefab.Destroy();
92
- webBridgeController.Release();
90
+ try
91
+ {
92
+ webBridgeController?.Release();
93
+ canvasWebViewPrefab?.Destroy();
94
+ }
95
+ catch (Exception e)
96
+ {
97
+ XDGLogger.Warn(e.Message);
98
+ }
93
99
  }
94
100
 
95
101
  private async void OnBackButtonClicked()
@@ -144,12 +150,12 @@ namespace XD.SDK.Common.Internal.Standalone
144
150
 
145
151
  private void ParseUriToInitWebView(string url)
146
152
  {
147
- var queryParams = ParseQueryString(url);
148
- var bgColor = GetValueOrDefault(queryParams, "xdBgColor", WebBridgeConstants.DefaultBgColor);
149
- var close = GetValueOrDefault(queryParams, "xdClose", "1") == "1";
150
- var loading = GetValueOrDefault(queryParams, "xdLoading", "1") == "1";
151
- var nav = GetValueOrDefault(queryParams, "xdNav", "1") == "1";
152
- var title = Uri.UnescapeDataString(GetValueOrDefault(queryParams, "xdTitle", ""));
153
+ var queryParams = WebRequest.ParseQueryString(url);
154
+ var bgColor = WebRequest.GetValueOrDefault(queryParams, "xdBgColor", WebBridgeConstants.DefaultBgColor);
155
+ var close = WebRequest.GetValueOrDefault(queryParams, "xdClose", "1") == "1";
156
+ var loading = WebRequest.GetValueOrDefault(queryParams, "xdLoading", "1") == "1";
157
+ var nav = WebRequest.GetValueOrDefault(queryParams, "xdNav", "1") == "1";
158
+ var title = Uri.UnescapeDataString(WebRequest.GetValueOrDefault(queryParams, "xdTitle", ""));
153
159
 
154
160
  HandlerCloseButtonVisible(new WebCloseButtonBean
155
161
  {
@@ -167,7 +173,7 @@ namespace XD.SDK.Common.Internal.Standalone
167
173
 
168
174
  if (loading)
169
175
  {
170
- UIManager.ShowLoading();
176
+ UIManager.ShowLoading(false, 5);
171
177
  }
172
178
  }
173
179
 
@@ -271,31 +277,6 @@ namespace XD.SDK.Common.Internal.Standalone
271
277
  ColorUtility.TryParseHtmlString(color, out var c);
272
278
  return c;
273
279
  }
274
-
275
- private static Dictionary<string, string> ParseQueryString(string url)
276
- {
277
- var uri = new Uri(url);
278
- if (string.IsNullOrWhiteSpace(uri.Query))
279
- {
280
- return new Dictionary<string, string>();
281
- }
282
-
283
- var dic = uri.Query.Substring(1)
284
- .Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries)
285
- .Select(param => param.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries))
286
- .GroupBy(part => part[0], part => part.Length > 1 ? part[1] : string.Empty)
287
- .ToDictionary(group => group.Key, group => string.Join(",", group));
288
- return dic;
289
- }
290
-
291
- private static TValue GetValueOrDefault<TKey, TValue>(
292
- IReadOnlyDictionary<TKey, TValue> dictionary,
293
- TKey key,
294
- TValue defaultValue)
295
- {
296
- if (dictionary == null) return defaultValue;
297
- return dictionary.TryGetValue(key, out var obj) ? obj : defaultValue;
298
- }
299
280
  }
300
281
  }
301
282
  #endif
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "com.xd.sdk.common",
3
3
  "displayName": "XDGSDK Common",
4
- "version": "7.0.1",
4
+ "version": "7.1.0",
5
5
  "description": "XDGSDK",
6
6
  "unity": "2019.3",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "com.xd.sdk.foundation": "7.0.1"
9
+ "com.xd.sdk.foundation": "7.1.0"
10
10
  }
11
11
  }