diff --git a/DownKyi/App.axaml.cs b/DownKyi/App.axaml.cs index ab25c94..b966394 100644 --- a/DownKyi/App.axaml.cs +++ b/DownKyi/App.axaml.cs @@ -10,6 +10,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Avalonia.Threading; using DownKyi.Core.Settings; +using DownKyi.Services; using DownKyi.Services.Download; using DownKyi.ViewModels; using DownKyi.ViewModels.Dialogs; @@ -27,7 +28,6 @@ using DownKyi.Views.Toolbox; using DownKyi.Views.UserSpace; using Prism.DryIoc; using Prism.Ioc; -using Prism.Services.Dialogs; using ViewSeasonsSeries = DownKyi.Views.ViewSeasonsSeries; using ViewSeasonsSeriesViewModel = DownKyi.ViewModels.ViewSeasonsSeriesViewModel; @@ -60,6 +60,7 @@ public partial class App : PrismApplication protected override void RegisterTypes(IContainerRegistry containerRegistry) { + containerRegistry.RegisterSingleton(); // pages containerRegistry.RegisterForNavigation(ViewIndexViewModel.Tag); containerRegistry.RegisterForNavigation(ViewLoginViewModel.Tag); diff --git a/DownKyi/Converter/CountConverter.cs b/DownKyi/Converter/CountConverter.cs index e0bcc1d..005cffe 100644 --- a/DownKyi/Converter/CountConverter.cs +++ b/DownKyi/Converter/CountConverter.cs @@ -10,6 +10,7 @@ namespace DownKyi.Converter public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { + var i = ((int)value) > Count; return ((int)value) > Count; } diff --git a/DownKyi/Services/AlertService.cs b/DownKyi/Services/AlertService.cs index ae9f564..f3c08ee 100644 --- a/DownKyi/Services/AlertService.cs +++ b/DownKyi/Services/AlertService.cs @@ -69,20 +69,11 @@ public class AlertService { "button_number", buttonNumber } }; - var isEnd = false; - dialogService.ShowDialog(ViewAlertDialogViewModel.Tag, param, + await dialogService.ShowDialogAsync(ViewAlertDialogViewModel.Tag, param, buttonResult => { result = buttonResult.Result; - isEnd = true; }); - await Task.Run(() => - { - while (true) - { - if (isEnd) break; - } - }); return result; } } \ No newline at end of file diff --git a/DownKyi/Services/DialogService.cs b/DownKyi/Services/DialogService.cs new file mode 100644 index 0000000..6b576e3 --- /dev/null +++ b/DownKyi/Services/DialogService.cs @@ -0,0 +1,58 @@ +using System; +using System.Threading.Tasks; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; +using Prism.Ioc; +using Prism.Services.Dialogs; + +namespace DownKyi.Services; + +public class DialogService : Prism.Services.Dialogs.DialogService, IDialogService +{ + public DialogService(IContainerExtension containerExtension) : base(containerExtension) + { + } + + public Task ShowDialogAsync(string name, IDialogParameters parameters, Action callback = null, + string windowName = null) + { + return ShowDialogInternal(name, parameters, callback, true, windowName); + } + + private Task ShowDialogInternal(string name, IDialogParameters parameters, Action? callback, + bool isModal, string windowName = null, Window parentWindow = null) + { + if (parameters == null) + parameters = new DialogParameters(); + + IDialogWindow dialogWindow = CreateDialogWindow(windowName); + ConfigureDialogWindowEvents(dialogWindow, callback); + ConfigureDialogWindowContent(name, dialogWindow, parameters); + + return ShowDialogWindow(dialogWindow, isModal, parentWindow); + } + + protected virtual Task ShowDialogWindow(IDialogWindow dialogWindow, bool isModal, Window owner = null) + { + if (isModal && + Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime deskLifetime) + { + // Ref: + // - https://docs.avaloniaui.net/docs/controls/window#show-a-window-as-a-dialog + // - https://github.com/AvaloniaUI/Avalonia/discussions/7924 + // (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime) + + if (owner != null) + return dialogWindow.ShowDialog(owner); + else + return dialogWindow.ShowDialog(deskLifetime.MainWindow); + } + else + { + dialogWindow.Show(); + } + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/DownKyi/Services/Download/AddToDownloadService.cs b/DownKyi/Services/Download/AddToDownloadService.cs index 1fb94cd..a3b2e56 100644 --- a/DownKyi/Services/Download/AddToDownloadService.cs +++ b/DownKyi/Services/Download/AddToDownloadService.cs @@ -189,7 +189,7 @@ public class AddToDownloadService { bool run = true; // 打开文件夹选择器 - dialogService.ShowDialog(ViewDownloadSetterViewModel.Tag, null, result => + await dialogService.ShowDialogAsync(ViewDownloadSetterViewModel.Tag, null, result => { if (result.Result == ButtonResult.OK) { @@ -206,13 +206,14 @@ public class AddToDownloadService run = false; }); - await Task.Run(() => - { - while (true) - { - if (!run) break; - } - }); + // await Task.Run(() => + // { + // while (true) + // { + // if (!run) break; + // Thread.Sleep(100); + // } + // }); } if (directory == String.Empty) @@ -224,7 +225,7 @@ public class AddToDownloadService if (!Directory.Exists(Directory.GetDirectoryRoot(directory))) { var alert = new AlertService(dialogService); - alert.ShowError(DictionaryResource.GetString("DriveNotFound")); + await alert.ShowError(DictionaryResource.GetString("DriveNotFound")); directory = string.Empty; } diff --git a/DownKyi/Services/IDialogService.cs b/DownKyi/Services/IDialogService.cs new file mode 100644 index 0000000..46241b5 --- /dev/null +++ b/DownKyi/Services/IDialogService.cs @@ -0,0 +1,11 @@ +using System; +using System.Threading.Tasks; +using Prism.Services.Dialogs; + +namespace DownKyi.Services; + +public interface IDialogService : Prism.Services.Dialogs.IDialogService +{ + public Task ShowDialogAsync(string name, IDialogParameters parameters, Action callback = null, + string windowName = null); +} \ No newline at end of file diff --git a/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs index 1ef395b..c1f6d7f 100644 --- a/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs +++ b/DownKyi/ViewModels/DownloadManager/DownloadBaseItem.cs @@ -1,11 +1,10 @@ -using DownKyi.Core.BiliApi.BiliUtils; +using Avalonia.Media; +using DownKyi.Core.BiliApi.BiliUtils; using DownKyi.Core.BiliApi.Zone; using DownKyi.Models; -using Prism.Mvvm; -using Prism.Services.Dialogs; -using Avalonia; -using Avalonia.Media; +using DownKyi.Services; using DownKyi.Utils; +using Prism.Mvvm; namespace DownKyi.ViewModels.DownloadManager { diff --git a/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs index 3421810..df6c229 100644 --- a/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs +++ b/DownKyi/ViewModels/DownloadManager/DownloadedItem.cs @@ -6,6 +6,7 @@ using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels.DownloadManager { diff --git a/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs b/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs index 3fdf072..3932d53 100644 --- a/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs +++ b/DownKyi/ViewModels/DownloadManager/DownloadingItem.cs @@ -5,6 +5,7 @@ using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels.DownloadManager { diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs index d9f104d..37f5d3a 100644 --- a/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs +++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadFinishedViewModel.cs @@ -13,6 +13,7 @@ using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; using Console = DownKyi.Core.Utils.Debugging.Console; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels.DownloadManager { diff --git a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs index 07946d6..b9cf421 100644 --- a/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs +++ b/DownKyi/ViewModels/DownloadManager/ViewDownloadingViewModel.cs @@ -13,6 +13,7 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using System.Threading.Tasks; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels.DownloadManager { @@ -37,13 +38,13 @@ namespace DownKyi.ViewModels.DownloadManager { // 初始化DownloadingList DownloadingList = App.DownloadingList; - DownloadingList.CollectionChanged += new NotifyCollectionChangedEventHandler((sender, e) => + DownloadingList.CollectionChanged += (sender, e) => { if (e.Action == NotifyCollectionChangedAction.Add) { SetDialogService(); } - }); + }; SetDialogService(); } diff --git a/DownKyi/ViewModels/Settings/ViewAboutViewModel.cs b/DownKyi/ViewModels/Settings/ViewAboutViewModel.cs index 7e22040..2a2ef88 100644 --- a/DownKyi/ViewModels/Settings/ViewAboutViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewAboutViewModel.cs @@ -1,11 +1,11 @@ using DownKyi.Core.Settings; using DownKyi.Events; using DownKyi.Models; +using DownKyi.Services; using DownKyi.Utils; using Prism.Commands; using Prism.Events; using Prism.Regions; -using Prism.Services.Dialogs; namespace DownKyi.ViewModels.Settings; diff --git a/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs b/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs index c7161af..8f97df6 100644 --- a/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs +++ b/DownKyi/ViewModels/Settings/ViewNetworkViewModel.cs @@ -11,6 +11,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels.Settings; diff --git a/DownKyi/ViewModels/ViewModelBase.cs b/DownKyi/ViewModels/ViewModelBase.cs index e7d9158..a04736c 100644 --- a/DownKyi/ViewModels/ViewModelBase.cs +++ b/DownKyi/ViewModels/ViewModelBase.cs @@ -1,11 +1,9 @@ using System; -using System.ComponentModel; -using Avalonia; using Avalonia.Threading; +using DownKyi.Services; using Prism.Events; using Prism.Mvvm; using Prism.Regions; -using Prism.Services.Dialogs; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs b/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs index a79bae6..e9cb67a 100644 --- a/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs +++ b/DownKyi/ViewModels/ViewMyBangumiFollowViewModel.cs @@ -20,6 +20,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs b/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs index adc2ecc..8b10d50 100644 --- a/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs +++ b/DownKyi/ViewModels/ViewMyFavoritesViewModel.cs @@ -18,6 +18,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewMyHistoryViewModel.cs b/DownKyi/ViewModels/ViewMyHistoryViewModel.cs index e84274d..d8a1ee2 100644 --- a/DownKyi/ViewModels/ViewMyHistoryViewModel.cs +++ b/DownKyi/ViewModels/ViewMyHistoryViewModel.cs @@ -19,6 +19,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewMyToViewVideoViewModel.cs b/DownKyi/ViewModels/ViewMyToViewVideoViewModel.cs index 70da174..f04c7ba 100644 --- a/DownKyi/ViewModels/ViewMyToViewVideoViewModel.cs +++ b/DownKyi/ViewModels/ViewMyToViewVideoViewModel.cs @@ -18,6 +18,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs b/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs index f7c4ea2..8820451 100644 --- a/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs +++ b/DownKyi/ViewModels/ViewPublicFavoritesViewModel.cs @@ -17,6 +17,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewPublicationViewModel.cs b/DownKyi/ViewModels/ViewPublicationViewModel.cs index 54d6e9f..f84760c 100644 --- a/DownKyi/ViewModels/ViewPublicationViewModel.cs +++ b/DownKyi/ViewModels/ViewPublicationViewModel.cs @@ -20,7 +20,6 @@ using DownKyi.ViewModels.UserSpace; using Prism.Commands; using Prism.Events; using Prism.Regions; -using Prism.Services.Dialogs; #nullable disable namespace DownKyi.ViewModels diff --git a/DownKyi/ViewModels/ViewSeasonsSeriesViewModel.cs b/DownKyi/ViewModels/ViewSeasonsSeriesViewModel.cs index f6b8317..0e46420 100644 --- a/DownKyi/ViewModels/ViewSeasonsSeriesViewModel.cs +++ b/DownKyi/ViewModels/ViewSeasonsSeriesViewModel.cs @@ -20,6 +20,7 @@ using Prism.Commands; using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; diff --git a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs index 6584920..1231e45 100644 --- a/DownKyi/ViewModels/ViewVideoDetailViewModel.cs +++ b/DownKyi/ViewModels/ViewVideoDetailViewModel.cs @@ -22,6 +22,7 @@ using Prism.Events; using Prism.Regions; using Prism.Services.Dialogs; using Console = DownKyi.Core.Utils.Debugging.Console; +using IDialogService = DownKyi.Services.IDialogService; namespace DownKyi.ViewModels; @@ -489,7 +490,7 @@ public class ViewVideoDetailViewModel : ViewModelBase if (parseScope == ParseScope.NONE) { //打开解析选择器 - DialogService.ShowDialog(ViewParsingSelectorViewModel.Tag, null, async result => + await DialogService?.ShowDialogAsync(ViewParsingSelectorViewModel.Tag, null, async result => { if (result.Result == ButtonResult.OK) { diff --git a/DownKyi/Views/DownloadManager/ViewDownloadFinished.axaml b/DownKyi/Views/DownloadManager/ViewDownloadFinished.axaml index c3c2b73..ea112d8 100644 --- a/DownKyi/Views/DownloadManager/ViewDownloadFinished.axaml +++ b/DownKyi/Views/DownloadManager/ViewDownloadFinished.axaml @@ -242,8 +242,8 @@ - + Source="/Resources/nodata02.png" IsVisible="{Binding !DownloadedList.Count}"> + \ No newline at end of file diff --git a/DownKyi/Views/DownloadManager/ViewDownloading.axaml b/DownKyi/Views/DownloadManager/ViewDownloading.axaml index 07d3f0e..bc66023 100644 --- a/DownKyi/Views/DownloadManager/ViewDownloading.axaml +++ b/DownKyi/Views/DownloadManager/ViewDownloading.axaml @@ -205,19 +205,9 @@ - - - - - - - - - - - - + + Width="{TemplateBinding Width}" + Height="{TemplateBinding Height}" /> @@ -306,19 +297,8 @@ - - - - - - - - - - - + Source="/Resources/nodata02.png" + IsVisible="{Binding !DownloadingList.Count}"> \ No newline at end of file