Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Commit

Permalink
修复断网自动退出及登录流程问题 (#1132)
Browse files Browse the repository at this point in the history
* 修复断网自动退出及登录流程问题

* 更新未登录头像

* 替换图片
  • Loading branch information
Richasy authored Apr 26, 2022
1 parent da9b32c commit 90e5107
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/App/App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@
<Content Include="Assets\Logo\Wide310x150Logo.scale-150.png" />
<Content Include="Assets\Logo\Wide310x150Logo.scale-200.png" />
<Content Include="Assets\Logo\Wide310x150Logo.scale-400.png" />
<Content Include="Assets\not_login.png" />
<Content Include="Assets\Null_rgba.png" />
<Content Include="Assets\Original_rgba_80.png" />
<Content Include="Assets\Rookie_rgba_80.png" />
Expand Down
Binary file added src/App/Assets/not_login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/App/Controls/App/CommonImageEx/CommonImageEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public sealed class CommonImageEx : Control
public static readonly DependencyProperty DecodePixelWidthProperty =
DependencyProperty.Register(nameof(DecodePixelWidth), typeof(double), typeof(CommonImageEx), new PropertyMetadata(-1));

/// <summary>
/// <see cref="PlaceholderSource"/>的依赖属性.
/// </summary>
public static readonly DependencyProperty PlaceholderSourceProperty =
DependencyProperty.Register(nameof(PlaceholderSource), typeof(ImageSource), typeof(CommonImageEx), new PropertyMetadata(default));

/// <summary>
/// Initializes a new instance of the <see cref="CommonImageEx"/> class.
/// </summary>
Expand Down Expand Up @@ -63,5 +69,14 @@ public int DecodePixelWidth
get { return (int)GetValue(DecodePixelWidthProperty); }
set { SetValue(DecodePixelWidthProperty, value); }
}

/// <summary>
/// 占位符图片.
/// </summary>
public ImageSource PlaceholderSource
{
get { return (ImageSource)GetValue(PlaceholderSourceProperty); }
set { SetValue(PlaceholderSourceProperty, value); }
}
}
}
3 changes: 2 additions & 1 deletion src/App/Controls/App/CommonImageEx/CommonImageEx.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:local="using:Richasy.Bili.App.Controls"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls">
<Style TargetType="local:CommonImageEx">
<Setter Property="PlaceholderSource" Value="/Assets/img_holder_rect.png" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:CommonImageEx">
Expand All @@ -14,7 +15,7 @@
CornerRadius="{TemplateBinding CornerRadius}"
DecodePixelWidth="{TemplateBinding DecodePixelWidth}"
EnableLazyLoading="True"
PlaceholderSource="/Assets/img_holder_rect.png"
PlaceholderSource="{TemplateBinding PlaceholderSource}"
PlaceholderStretch="Uniform"
Source="{TemplateBinding ImageUrl}"
Stretch="{TemplateBinding Stretch}" />
Expand Down
1 change: 1 addition & 0 deletions src/App/Controls/User/UserAvatar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
CornerRadius="25"
DecodePixelWidth="{x:Bind DecodeSize, Mode=OneWay}"
ImageUrl="{x:Bind Avatar, Mode=OneWay}"
PlaceholderSource="/Assets/not_login.png"
ToolTipService.ToolTip="{x:Bind UserName, Mode=OneWay}" />
</Button>
</UserControl>
9 changes: 5 additions & 4 deletions src/Controller/Controller.Uwp/BiliController.Auth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<bool> TrySignInAsync(bool isSlientOnly = false)
}
else
{
LoggedFailed?.Invoke(this, new Exception());
LoggedFailed?.Invoke(this, new OperationCanceledException());
return false;
}
}
Expand All @@ -53,15 +53,16 @@ public async Task<bool> TrySignInAsync(bool isSlientOnly = false)
/// <returns><see cref="Task"/>.</returns>
public async Task SignOutAsync()
{
this._isRequestLogout = true;
_isRequestLogout = true;
await _authorizeProvider.SignOutAsync();
}

private void OnAuthenticationStateChanged(object sender, AuthorizeStateChangedEventArgs e)
{
if (e.NewState == AuthorizeState.SignedOut && !_isRequestLogout)
{
LoggedFailed?.Invoke(this, new Exception("请求失败"));
LoggedFailed?.Invoke(this, new OperationCanceledException("请求失败"));
return;
}

switch (e.NewState)
Expand All @@ -71,7 +72,7 @@ private void OnAuthenticationStateChanged(object sender, AuthorizeStateChangedEv
break;
case AuthorizeState.SignedOut:
LoggedOut?.Invoke(this, EventArgs.Empty);
this._isRequestLogout = false;
_isRequestLogout = false;
break;
default:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ private async Task SwitchLoginTypeAsync(LoginType type)
PrimaryButtonText = string.Empty;
TipBlock.Text = resourceToolkit.GetLocaleString(LanguageNames.QRLoginTip);
SwitchActionButton.Content = resourceToolkit.GetLocaleString(LanguageNames.SwitchToPasswordLogin);
IsShowWebView = false;
await LoadQRCodeAsync();
break;
default:
Expand Down
9 changes: 8 additions & 1 deletion src/Lib/Lib.Uwp/HttpProvider/HttpProvider.Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ await Task.Run(async () =>
{
Code = 408,
Message = ServiceConstants.Messages.RequestTimedOut,
IsHttpError = true,
},
exception);
}
Expand All @@ -64,6 +65,7 @@ await Task.Run(async () =>
new ServerResponse
{
Message = ServiceConstants.Messages.UnexpectedExceptionOnSend,
IsHttpError = true,
},
exception);
}
Expand Down Expand Up @@ -155,13 +157,18 @@ private async Task ThrowIfHasExceptionAsync(HttpResponseMessage response)
{
if (response != null && response.StatusCode == HttpStatusCode.NotFound)
{
errorResponse = new ServerResponse { Message = ServiceConstants.Messages.NotFound };
errorResponse = new ServerResponse
{
Message = ServiceConstants.Messages.NotFound,
IsHttpError = true,
};
}
else
{
errorResponse = new ServerResponse
{
Message = ServiceConstants.Messages.UnexpectedExceptionResponse,
IsHttpError = true,
};
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Models.BiliBili/Others/ServerResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public class ServerResponse
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "ttl", Required = Required.Default)]
public int TTL { get; set; }

/// <summary>
/// 是否为网络请求错误,而非服务器传回的错误.
/// </summary>
public bool IsHttpError { get; set; }

/// <summary>
/// 响应结果是否为成功.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Richasy.Bili.Locator.Uwp;
using Richasy.Bili.Models.App;
using Richasy.Bili.Models.App.Constants;
using Richasy.Bili.Models.App.Other;
using Richasy.Bili.Models.BiliBili;
using Richasy.Bili.Models.Enums;

Expand Down Expand Up @@ -171,7 +172,11 @@ private async void OnLoggedFailedAsync(object sender, Exception e)
{
Reset();
Status = AccountViewModelStatus.Logout;
await _controller.SignOutAsync();

if (e is ServiceException serviceEx && (!serviceEx.Error?.IsHttpError ?? true))
{
await _controller.SignOutAsync();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task InitializeRequestAsync()

internal async Task DeltaRequestAsync()
{
if (!IsDeltaLoading && !_isLoadCompleted)
if (!IsDeltaLoading && !_isLoadCompleted && AccountViewModel.Instance.Status == AccountViewModelStatus.Login)
{
IsDeltaLoading = true;
await RequestAsync();
Expand Down

0 comments on commit 90e5107

Please sign in to comment.