From e075463ccfe64db0fba13be547d27c7441a83555 Mon Sep 17 00:00:00 2001 From: leiurayer <1432593898@qq.com> Date: Sat, 3 Aug 2024 16:08:13 +0800 Subject: [PATCH] =?UTF-8?q?VideoDetail=E9=A1=B5=E9=9D=A2=E5=AE=8C=E5=96=84?= =?UTF-8?q?Upper()=E5=92=8CCopyCoverUrl()=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Downkyi.UI/Services/IClipboardService.cs | 4 ++ .../ViewModels/Video/VideoDetailViewModel.cs | 49 ++++++++++++++++--- src/Downkyi/Services/ClipboardService.cs | 15 ++++++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/Downkyi.UI/Services/IClipboardService.cs b/src/Downkyi.UI/Services/IClipboardService.cs index 32c7e64..6cf9d9a 100644 --- a/src/Downkyi.UI/Services/IClipboardService.cs +++ b/src/Downkyi.UI/Services/IClipboardService.cs @@ -3,4 +3,8 @@ public interface IClipboardService { Task GetTextAsync(); + + Task SetTextAsync(string text); + + Task SetImageAsync(object obj); } \ No newline at end of file diff --git a/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs b/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs index 9dc06ab..80ddddf 100644 --- a/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs +++ b/src/Downkyi.UI/ViewModels/Video/VideoDetailViewModel.cs @@ -1,8 +1,12 @@ using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using Downkyi.Core.Log; +using Downkyi.Core.Settings; +using Downkyi.Core.Settings.Models; using Downkyi.UI.Models; using Downkyi.UI.Mvvm; using Downkyi.UI.ViewModels.DownloadManager; +using Downkyi.UI.ViewModels.User; namespace Downkyi.UI.ViewModels.Video; @@ -74,23 +78,56 @@ public partial class VideoDetailViewModel : ViewModelBase private void CopyCover() { } [RelayCommand] - private void CopyCoverUrl() { } + private async Task CopyCoverUrl() + { + // 复制封面url到剪贴板 + await ClipboardService.SetTextAsync(VideoInfoView.CoverUrl); + Log.Logger.Info("复制封面url到剪贴板"); + } - [RelayCommand] - private void Upper() { } + [RelayCommand(FlowExceptionsToTaskScheduler = true)] + private async Task Upper() + { + await NavigateToViewUserSpace(VideoInfoView.UpperMid); + } #endregion + /// + /// 导航到用户空间, + /// 如果传入的mid与本地登录的mid一致, + /// 则进入我的用户空间。 + /// + /// + private async Task NavigateToViewUserSpace(long mid) + { + Dictionary parameter = new() + { + { "key", Key }, + { "value", mid }, + }; + + UserInfoSettings userInfo = SettingsManager.GetInstance().GetUserInfo(); + if (userInfo != null && userInfo.Mid == mid) + { + await NavigationService.ForwardAsync(MySpaceViewModel.Key, parameter); + } + else + { + await NavigationService.ForwardAsync(UserSpaceViewModel.Key, parameter); + } + } + public override void OnNavigatedTo(Dictionary? parameter) { base.OnNavigatedTo(parameter); - if (parameter!.ContainsKey("value")) + if (parameter!.TryGetValue("value", out object? value)) { - _input = (string)parameter["value"]; + _input = (string)value; InputText = _input; } - + } } \ No newline at end of file diff --git a/src/Downkyi/Services/ClipboardService.cs b/src/Downkyi/Services/ClipboardService.cs index 600b3d7..519fd46 100644 --- a/src/Downkyi/Services/ClipboardService.cs +++ b/src/Downkyi/Services/ClipboardService.cs @@ -16,4 +16,19 @@ public class ClipboardService : IClipboardService return await provider.GetTextAsync() ?? string.Empty; } + + public async Task SetTextAsync(string text) + { + if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop || + desktop.MainWindow?.Clipboard is not { } provider) + throw new NullReferenceException("Missing Clipboard instance."); + + await provider.SetTextAsync(text); + } + + public Task SetImageAsync(object obj) + { + throw new NotImplementedException(); + } + } \ No newline at end of file