From 9da37a7f2853ffeb9fe09965ef908a47df77d6a1 Mon Sep 17 00:00:00 2001 From: leiurayer <1432593898@qq.com> Date: Wed, 24 May 2023 23:48:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=9C=AA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=83=BD=E6=AD=A3=E5=B8=B8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?wbi=E5=8F=A3=E4=BB=A4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DownKyi.Core/BiliApi/Users/UserInfo.cs | 3 +- src/DownKyi/ViewModels/ViewIndexViewModel.cs | 108 ++++++++++--------- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/DownKyi.Core/BiliApi/Users/UserInfo.cs b/src/DownKyi.Core/BiliApi/Users/UserInfo.cs index d6d1a21..cafdbb8 100644 --- a/src/DownKyi.Core/BiliApi/Users/UserInfo.cs +++ b/src/DownKyi.Core/BiliApi/Users/UserInfo.cs @@ -27,8 +27,7 @@ namespace DownKyi.Core.BiliApi.Users UserInfoForNavigationOrigin userInfo = JsonConvert.DeserializeObject(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) { diff --git a/src/DownKyi/ViewModels/ViewIndexViewModel.cs b/src/DownKyi/ViewModels/ViewIndexViewModel.cs index 37aff24..b78e5c5 100644 --- a/src/DownKyi/ViewModels/ViewIndexViewModel.cs +++ b/src/DownKyi/ViewModels/ViewIndexViewModel.cs @@ -229,45 +229,59 @@ namespace DownKyi.ViewModels InputText = string.Empty; } - private UserInfoForNavigation GetUserInfo() + private async Task 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; } /// /// 更新用户登录信息 /// - 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(() => + LoginPanelVisibility = Visibility.Visible; + + if (userInfo != null) { - // 获取用户信息 - var userInfo = GetUserInfo(); - - PropertyChangeAsync(new Action(() => + if (userInfo.Face != null) { - LoginPanelVisibility = Visibility.Visible; + 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; + } - 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; - } - })); - })); } catch (Exception e) { @@ -328,6 +334,8 @@ namespace DownKyi.ViewModels string parameter = navigationContext.Parameters.GetValue("Parameter"); if (parameter == null) { + // 其他情况只更新设置的用户信息,不更新UI + UpdateUserInfo(true); return; } @@ -346,10 +354,10 @@ namespace DownKyi.ViewModels { UpdateUserInfo(); } - // 其他情况只更新设置的用户信息,不更新UI else { - GetUserInfo(); + // 其他情况只更新设置的用户信息,不更新UI + UpdateUserInfo(true); } }