diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Theme/FlyoutStyle.xaml b/src/Snap.Hutao/Snap.Hutao/Control/Theme/FlyoutStyle.xaml
index b2da9a2e..955fffba 100644
--- a/src/Snap.Hutao/Snap.Hutao/Control/Theme/FlyoutStyle.xaml
+++ b/src/Snap.Hutao/Snap.Hutao/Control/Theme/FlyoutStyle.xaml
@@ -4,7 +4,6 @@
BasedOn="{StaticResource DefaultFlyoutPresenterStyle}"
TargetType="FlyoutPresenter">
-
-
diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs
index 360e7a6a..e4123d16 100644
--- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/MiHoYoJSInterface.cs
@@ -74,12 +74,20 @@ internal class MiHoYoJSInterface
public event Action? ClosePageRequested;
+ public void Detach()
+ {
+ coreWebView2.WebMessageReceived -= webMessageReceivedEventHandler;
+ coreWebView2.DOMContentLoaded -= domContentLoadedEventHandler;
+ coreWebView2.NavigationStarting -= navigationStartingEventHandler;
+ coreWebView2 = default!;
+ }
+
///
/// 关闭
///
/// 参数
/// 响应
- public virtual async ValueTask ClosePageAsync(JsParam param)
+ protected virtual async ValueTask ClosePageAsync(JsParam param)
{
await taskContext.SwitchToMainThreadAsync();
if (coreWebView2.CanGoBack)
@@ -99,7 +107,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual IJsResult? ConfigureShare(JsParam param)
+ protected virtual IJsResult? ConfigureShare(JsParam param)
{
return null;
}
@@ -109,7 +117,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual async ValueTask GetActionTicketAsync(JsParam jsParam)
+ protected virtual async ValueTask GetActionTicketAsync(JsParam jsParam)
{
return await serviceProvider
.GetRequiredService()
@@ -122,7 +130,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual JsResult> GetCookieInfo(JsParam param)
+ protected virtual JsResult> GetCookieInfo(JsParam param)
{
ArgumentNullException.ThrowIfNull(userAndUid.User.LToken);
@@ -142,7 +150,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual async ValueTask>> GetCookieTokenAsync(JsParam param)
+ protected virtual async ValueTask>> GetCookieTokenAsync(JsParam param)
{
IUserService userService = serviceProvider.GetRequiredService();
if (param.Payload.ForceRefresh)
@@ -162,7 +170,7 @@ internal class MiHoYoJSInterface
///
/// param
/// 语言与时区
- public virtual JsResult> GetCurrentLocale(JsParam param)
+ protected virtual JsResult> GetCurrentLocale(JsParam param)
{
MetadataOptions metadataOptions = serviceProvider.GetRequiredService();
@@ -181,7 +189,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual JsResult> GetDynamicSecrectV1(JsParam param)
+ protected virtual JsResult> GetDynamicSecrectV1(JsParam param)
{
string salt = HoyolabOptions.Salts[SaltType.LK2];
long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
@@ -212,7 +220,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual JsResult> GetDynamicSecrectV2(JsParam param)
+ protected virtual JsResult> GetDynamicSecrectV2(JsParam param)
{
string salt = HoyolabOptions.Salts[SaltType.X4];
long t = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
@@ -235,13 +243,20 @@ internal class MiHoYoJSInterface
///
/// 参数
/// Http请求头
- public virtual JsResult> GetHttpRequestHeader(JsParam param)
+ protected virtual JsResult> GetHttpRequestHeader(JsParam param)
{
Dictionary headers = new()
{
+ // Skip x-rpc-device_name
+ // Skip x-rpc-device_model
+ // Skip x-rpc-sys_version
+ // Skip x-rpc-game_biz
+ // Skip x-rpc-lifecycle_id
+ { "x-rpc-app_id", "bll8iq97cem8" },
{ "x-rpc-client_type", "5" },
- { "x-rpc-device_id", HoyolabOptions.DeviceId },
- { "x-rpc-app_version", SaltConstants.CNVersion },
+ { "x-rpc-device_id", HoyolabOptions.DeviceId },
+ { "x-rpc-app_version", userAndUid.IsOversea ? SaltConstants.OSVersion : SaltConstants.CNVersion },
+ { "x-rpc-sdk_version", "2.16.0" },
};
if (!userAndUid.IsOversea)
@@ -249,18 +264,24 @@ internal class MiHoYoJSInterface
headers.Add("x-rpc-device_fp", userAndUid.User.Fingerprint ?? string.Empty);
}
+ GetHttpRequestHeaderCore(headers);
+
return new()
{
Data = headers,
};
}
+ protected virtual void GetHttpRequestHeaderCore(Dictionary headers)
+ {
+ }
+
///
/// 获取状态栏高度
///
/// 参数
/// 结果
- public virtual JsResult> GetStatusBarHeight(JsParam param)
+ protected virtual JsResult> GetStatusBarHeight(JsParam param)
{
return new() { Data = new() { ["statusBarHeight"] = 0 } };
}
@@ -270,7 +291,7 @@ internal class MiHoYoJSInterface
///
/// 参数
/// 响应
- public virtual async ValueTask>> GetUserInfoAsync(JsParam param)
+ protected virtual async ValueTask>> GetUserInfoAsync(JsParam param)
{
Response response = await serviceProvider
.GetRequiredService>()
@@ -299,7 +320,7 @@ internal class MiHoYoJSInterface
}
}
- public virtual async ValueTask PushPageAsync(JsParam param)
+ protected virtual async ValueTask PushPageAsync(JsParam param)
{
const string bbsSchema = "mihoyobbs://";
string pageUrl = param.Payload.Page;
@@ -323,7 +344,7 @@ internal class MiHoYoJSInterface
return null;
}
- public virtual IJsResult? Share(JsParam param)
+ protected virtual IJsResult? Share(JsParam param)
{
return new JsResult>()
{
@@ -334,57 +355,53 @@ internal class MiHoYoJSInterface
};
}
- public virtual ValueTask ShowAlertDialogAsync(JsParam param)
+ protected virtual ValueTask ShowAlertDialogAsync(JsParam param)
{
return ValueTask.FromException(new NotSupportedException());
}
- public virtual IJsResult? StartRealPersonValidation(JsParam param)
+ protected virtual IJsResult? StartRealPersonValidation(JsParam param)
{
throw new NotImplementedException();
}
- public virtual IJsResult? StartRealnameAuth(JsParam param)
+ protected virtual IJsResult? StartRealnameAuth(JsParam param)
{
throw new NotImplementedException();
}
- public virtual IJsResult? GenAuthKey(JsParam param)
+ protected virtual IJsResult? GenAuthKey(JsParam param)
{
throw new NotImplementedException();
}
- public virtual IJsResult? GenAppAuthKey(JsParam param)
+ protected virtual IJsResult? GenAppAuthKey(JsParam param)
{
throw new NotImplementedException();
}
- public virtual IJsResult? OpenSystemBrowser(JsParam param)
+ protected virtual IJsResult? OpenSystemBrowser(JsParam param)
{
throw new NotImplementedException();
}
- public virtual IJsResult? SaveLoginTicket(JsParam param)
+ protected virtual IJsResult? SaveLoginTicket(JsParam param)
{
throw new NotImplementedException();
}
- public virtual ValueTask GetNotificationSettingsAsync(JsParam param)
+ protected virtual ValueTask GetNotificationSettingsAsync(JsParam param)
{
throw new NotImplementedException();
}
- public virtual IJsResult? ShowToast(JsParam param)
+ protected virtual IJsResult? ShowToast(JsParam param)
{
throw new NotImplementedException();
}
- public void Detach()
+ protected virtual void DOMContentLoaded(CoreWebView2 coreWebView2)
{
- coreWebView2.WebMessageReceived -= webMessageReceivedEventHandler;
- coreWebView2.DOMContentLoaded -= domContentLoadedEventHandler;
- coreWebView2.NavigationStarting -= navigationStartingEventHandler;
- coreWebView2 = default!;
}
private async ValueTask ExecuteCallbackScriptAsync(string callback, string? payload = null)
@@ -485,6 +502,7 @@ internal class MiHoYoJSInterface
private void OnDOMContentLoaded(CoreWebView2 coreWebView2, CoreWebView2DOMContentLoadedEventArgs args)
{
+ DOMContentLoaded(coreWebView2);
coreWebView2.ExecuteScriptAsync(HideScrollBarScript).AsTask().SafeForget(logger);
}
diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterface.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterface.cs
index 52c03502..513f2f5e 100644
--- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterface.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterface.cs
@@ -20,17 +20,8 @@ internal sealed class SignInJSInterface : MiHoYoJSInterface
{
}
- ///
- public override JsResult> GetHttpRequestHeader(JsParam param)
+ protected override void GetHttpRequestHeaderCore(Dictionary headers)
{
- return new()
- {
- Data = new Dictionary()
- {
- { "x-rpc-client_type", "2" },
- { "x-rpc-device_id", HoyolabOptions.DeviceId },
- { "x-rpc-app_version", SaltConstants.CNVersion },
- },
- };
+ headers["x-rpc-client_type"] = "2";
}
}
\ No newline at end of file
diff --git a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterfaceOversea.cs b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterfaceOversea.cs
index 4321bec2..90692280 100644
--- a/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterfaceOversea.cs
+++ b/src/Snap.Hutao/Snap.Hutao/Web/Bridge/SignInJSInterfaceOversea.cs
@@ -14,6 +14,7 @@ namespace Snap.Hutao.Web.Bridge;
[HighQuality]
internal sealed class SignInJSInterfaceOversea : MiHoYoJSInterface
{
+ // 移除 请旋转手机 提示所在的HTML元素
private const string RemoveRotationWarningScript = """
let landscape = document.getElementById('mihoyo_landscape');
landscape.remove();
@@ -26,26 +27,15 @@ internal sealed class SignInJSInterfaceOversea : MiHoYoJSInterface
: base(webView, userAndUid)
{
logger = serviceProvider.GetRequiredService>();
- webView.DOMContentLoaded += OnDOMContentLoaded;
}
- ///
- public override JsResult> GetHttpRequestHeader(JsParam param)
+ protected override void GetHttpRequestHeaderCore(Dictionary headers)
{
- return new()
- {
- Data = new Dictionary()
- {
- { "x-rpc-client_type", "2" },
- { "x-rpc-device_id", HoyolabOptions.DeviceId },
- { "x-rpc-app_version", SaltConstants.OSVersion },
- },
- };
+ headers["x-rpc-client_type"] = "2";
}
- private void OnDOMContentLoaded(CoreWebView2 coreWebView2, CoreWebView2DOMContentLoadedEventArgs args)
+ protected override void DOMContentLoaded(CoreWebView2 coreWebView2)
{
- // 移除“请旋转手机”提示所在的HTML元素
coreWebView2.ExecuteScriptAsync(RemoveRotationWarningScript).AsTask().SafeForget(logger);
}
-}
+}
\ No newline at end of file