Skip to content

Commit

Permalink
refactor: clear code
Browse files Browse the repository at this point in the history
  • Loading branch information
K12f committed Aug 24, 2024
1 parent 873a7b4 commit 3c90ce3
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 37 deletions.
5 changes: 0 additions & 5 deletions src/BlueCatKoKo.Ui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@

using Wpf.Ui;

using HomeViewModel = BlueCatKoKo.Ui.ViewModels.Pages.HomeViewModel;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;

namespace BlueCatKoKo.Ui
{
using HomeViewModel = ViewModels.Pages.HomeViewModel;

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
Expand Down
31 changes: 14 additions & 17 deletions src/BlueCatKoKo.Ui/ViewModels/Pages/HomeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations;
using System.Configuration;
using System.IO;

using BlueCatKoKo.Ui.Constants;
Expand All @@ -25,17 +24,23 @@ namespace BlueCatKoKo.Ui.ViewModels.Pages
[ObservableRecipient]
public partial class HomeViewModel : ViewModelBase
{
private readonly DouyinDownloaderService _douyinDownloaderService;
private readonly IOptions<AppConfig> _appConfig;
private readonly DouyinDownloaderService _douyinDownloaderService;
private readonly ILogger _logger;

// 解析出的视频数据
[ObservableProperty] private HomePageModel _data;

// 下载进度
[ObservableProperty] private double _downloadProcess;

// 下载链接
[ObservableProperty] [Required(ErrorMessage = "缺少分享链接")]
private string _downloadUrlText;

// 是否已经下载
[ObservableProperty] private string _isDownload;

// 是否下载音频,默认false
[ObservableProperty] private bool _isDownloadAudio;

Expand All @@ -49,12 +54,6 @@ [ObservableProperty] [Required(ErrorMessage = "缺少分享链接")]
// 视频是否已解析
[ObservableProperty] private bool _isParsing;

// 是否已经下载
[ObservableProperty] private string _isDownload;

// 下载进度
[ObservableProperty] private double _downloadProcess;


public HomeViewModel(IMessenger messenger, ILogger logger, DouyinDownloaderService douyinDownloaderService,
IOptions<AppConfig> appConfig)
Expand Down Expand Up @@ -177,21 +176,19 @@ private async Task DownloadAll()
throw new InvalidDataException("无效的下载链接");
}

var filename = _appConfig.Value.DownloadPath + Data.VideoId + ".mp4";
string filename = _appConfig.Value.DownloadPath + Data.VideoId + ".mp4";
await _douyinDownloaderService.Download(Data.VideoUrl, _appConfig.Value.DownloadPath,
Data.VideoId + ".mp4",
onProgressChanged: (
(sender, e) =>
{
Console.WriteLine($"Progress: {e.ProgressPercentage}%");
DownloadProcess = e.ProgressPercentage;
}), onProgressCompleted: ((sender, e) =>
(sender, e) =>
{
DownloadProcess = e.ProgressPercentage;
}, (sender, e) =>
{
DownloadProcess = 100;
IsDownload = "hidden";
message = filename+"下载成功~";
message = filename + "下载成功~";
_logger.Error($"Download completed! Status: {e.Error}");
}));
});
}
catch (Exception ex)
{
Expand Down
6 changes: 0 additions & 6 deletions src/BlueCatKoKo.Ui/ViewModels/Pages/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Windows.Forms;

using BlueCatKoKo.Ui.Models;
using BlueCatKoKo.Ui.Services;

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;

using LibVLCSharp.Shared;

using Microsoft.Extensions.Options;

using Serilog;
Expand Down
1 change: 0 additions & 1 deletion src/BlueCatKoKo.Ui/Views/Pages/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Windows.Controls;

using BlueCatKoKo.Ui.ViewModels;
using BlueCatKoKo.Ui.ViewModels.Pages;

namespace BlueCatKoKo.Ui.Views.Pages
Expand Down
9 changes: 3 additions & 6 deletions src/BlueCatKoKo.Ui/Views/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.Windows.Controls;

using BlueCatKoKo.Ui.ViewModels;
using BlueCatKoKo.Ui.ViewModels.Pages;


using HomeViewModel = BlueCatKoKo.Ui.ViewModels.Pages.HomeViewModel;
using Pages_HomeViewModel = BlueCatKoKo.Ui.ViewModels.Pages.HomeViewModel;

namespace BlueCatKoKo.Ui.Views.Pages
{
public partial class HomePage : Page
{
public Pages_HomeViewModel ViewModel { get; }
public HomeViewModel ViewModel { get; }

public HomePage(Pages_HomeViewModel viewModel)
public HomePage(HomeViewModel viewModel)
{
InitializeComponent();
ViewModel = viewModel;
Expand Down
1 change: 0 additions & 1 deletion src/BlueCatKoKo.Ui/Views/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Windows.Controls;

using BlueCatKoKo.Ui.ViewModels;
using BlueCatKoKo.Ui.ViewModels.Pages;

namespace BlueCatKoKo.Ui.Views.Pages
Expand Down
1 change: 0 additions & 1 deletion src/BlueCatKoKo.Ui/Views/Pages/VideoPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Windows.Controls;

using BlueCatKoKo.Ui.ViewModels;
using BlueCatKoKo.Ui.ViewModels.Pages;

namespace BlueCatKoKo.Ui.Views.Pages
Expand Down

0 comments on commit 3c90ce3

Please sign in to comment.