修正未登录时不能正常获取wbi口令的问题

pull/896/head
leiurayer 1 year ago
parent 35ca6a3442
commit 9da37a7f28

@ -27,8 +27,7 @@ namespace DownKyi.Core.BiliApi.Users
UserInfoForNavigationOrigin userInfo = JsonConvert.DeserializeObject<UserInfoForNavigationOrigin>(response);
if (userInfo == null || userInfo.Data == null) { return null; }
if (userInfo.Data.IsLogin) { return userInfo.Data; }
else { return null; }
return userInfo.Data;
}
catch (Exception e)
{

@ -229,45 +229,59 @@ namespace DownKyi.ViewModels
InputText = string.Empty;
}
private UserInfoForNavigation GetUserInfo()
private async Task<UserInfoForNavigation> GetUserInfo()
{
// 获取用户信息
var userInfo = UserInfo.GetUserInfoForNavigation();
if (userInfo != null)
UserInfoForNavigation userInfo = null;
await Task.Run(new Action(() =>
{
SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings
// 获取用户信息
userInfo = UserInfo.GetUserInfoForNavigation();
if (userInfo != null)
{
Mid = userInfo.Mid,
Name = userInfo.Name,
IsLogin = userInfo.IsLogin,
IsVip = userInfo.VipStatus == 1,
ImgKey = userInfo.Wbi.ImgUrl.Split('/').ToList().Last().Split('.')[0],
SubKey = userInfo.Wbi.SubUrl.Split('/').ToList().Last().Split('.')[0],
});
}
else
{
SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings
SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings
{
Mid = userInfo.Mid,
Name = userInfo.Name,
IsLogin = userInfo.IsLogin,
IsVip = userInfo.VipStatus == 1,
ImgKey = userInfo.Wbi.ImgUrl.Split('/').ToList().Last().Split('.')[0],
SubKey = userInfo.Wbi.SubUrl.Split('/').ToList().Last().Split('.')[0],
});
}
else
{
Mid = -1,
Name = "",
IsLogin = false,
IsVip = false,
});
}
SettingsManager.GetInstance().SetUserInfo(new UserInfoSettings
{
Mid = -1,
Name = "",
IsLogin = false,
IsVip = false,
});
}
}));
return userInfo;
}
/// <summary>
/// 更新用户登录信息
/// </summary>
private async void UpdateUserInfo()
private async void UpdateUserInfo(bool isBackgroud = false)
{
try
{
if (isBackgroud)
{
// 获取用户信息
await GetUserInfo();
return;
}
LoginPanelVisibility = Visibility.Hidden;
// 获取用户信息
var userInfo = await GetUserInfo();
// 检查本地是否存在login文件没有则说明未登录
if (!File.Exists(StorageManager.GetLogin()))
{
@ -277,34 +291,26 @@ namespace DownKyi.ViewModels
return;
}
await Task.Run(new Action(() =>
{
// 获取用户信息
var userInfo = GetUserInfo();
LoginPanelVisibility = Visibility.Visible;
PropertyChangeAsync(new Action(() =>
if (userInfo != null)
{
if (userInfo.Face != null)
{
Header = new StorageHeader().GetHeaderThumbnail(userInfo.Mid, userInfo.Name, userInfo.Face, 36, 36);
}
else
{
LoginPanelVisibility = Visibility.Visible;
if (userInfo != null)
{
if (userInfo.Face != null)
{
Header = new StorageHeader().GetHeaderThumbnail(userInfo.Mid, userInfo.Name, userInfo.Face, 36, 36);
}
else
{
Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg"));
}
UserName = userInfo.Name;
}
else
{
Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg"));
UserName = null;
}
}));
}));
Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg"));
}
UserName = userInfo.Name;
}
else
{
Header = new BitmapImage(new Uri("pack://application:,,,/Resources/default_header.jpg"));
UserName = null;
}
}
catch (Exception e)
{
@ -328,6 +334,8 @@ namespace DownKyi.ViewModels
string parameter = navigationContext.Parameters.GetValue<string>("Parameter");
if (parameter == null)
{
// 其他情况只更新设置的用户信息不更新UI
UpdateUserInfo(true);
return;
}
@ -346,10 +354,10 @@ namespace DownKyi.ViewModels
{
UpdateUserInfo();
}
// 其他情况只更新设置的用户信息不更新UI
else
{
GetUserInfo();
// 其他情况只更新设置的用户信息不更新UI
UpdateUserInfo(true);
}
}

Loading…
Cancel
Save