mirror of
https://github.com/yaobiao131/downkyicore.git
synced 2025-08-10 00:52:31 +00:00
fix: 修复下载列表不显示和提示框异步问题
This commit is contained in:
@@ -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<IDialogService, DialogService>();
|
||||
// pages
|
||||
containerRegistry.RegisterForNavigation<ViewIndex>(ViewIndexViewModel.Tag);
|
||||
containerRegistry.RegisterForNavigation<ViewLogin>(ViewLoginViewModel.Tag);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
58
DownKyi/Services/DialogService.cs
Normal file
58
DownKyi/Services/DialogService.cs
Normal file
@@ -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<IDialogResult> callback = null,
|
||||
string windowName = null)
|
||||
{
|
||||
return ShowDialogInternal(name, parameters, callback, true, windowName);
|
||||
}
|
||||
|
||||
private Task ShowDialogInternal(string name, IDialogParameters parameters, Action<IDialogResult>? 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
11
DownKyi/Services/IDialogService.cs
Normal file
11
DownKyi/Services/IDialogService.cs
Normal file
@@ -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<IDialogResult> callback = null,
|
||||
string windowName = null);
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -242,8 +242,8 @@
|
||||
<Image
|
||||
Width="256"
|
||||
Height="256"
|
||||
Source="/Resources/nodata02.png">
|
||||
<i:Interaction.Behaviors>
|
||||
Source="/Resources/nodata02.png" IsVisible="{Binding !DownloadedList.Count}">
|
||||
<!--<i:Interaction.Behaviors>
|
||||
<ia:DataTriggerBehavior Binding="{Binding DownloadedList}" Value="{x:Null}">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="True" />
|
||||
</ia:DataTriggerBehavior>
|
||||
@@ -254,7 +254,7 @@
|
||||
Binding="{Binding DownloadedList.Count, Converter={StaticResource CountConverter}}" Value="true">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="False" />
|
||||
</ia:DataTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
</i:Interaction.Behaviors>-->
|
||||
</Image>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -205,19 +205,9 @@
|
||||
</ControlTheme>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid RowDefinitions="*,1,50">
|
||||
<i:Interaction.Behaviors>
|
||||
<ia:DataTriggerBehavior Binding="{Binding DownloadingList}" Value="{x:Null}">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="False" />
|
||||
</ia:DataTriggerBehavior>
|
||||
<ia:DataTriggerBehavior Binding="{Binding DownloadingList.Count}" Value="0">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="False" />
|
||||
</ia:DataTriggerBehavior>
|
||||
<ia:DataTriggerBehavior
|
||||
Binding="{Binding DownloadingList.Count, Converter={StaticResource CountConverter}}" Value="">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="True" />
|
||||
</ia:DataTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
<Grid
|
||||
RowDefinitions="*,1,50"
|
||||
IsVisible="{Binding DownloadingList.Count}">
|
||||
<ListBox
|
||||
Grid.Row="0"
|
||||
BorderThickness="0"
|
||||
@@ -238,7 +228,8 @@
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<ItemsPresenter ItemsPanel="{TemplateBinding ItemsPanel}"
|
||||
Width="{TemplateBinding Width}" />
|
||||
Width="{TemplateBinding Width}"
|
||||
Height="{TemplateBinding Height}" />
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
@@ -306,19 +297,8 @@
|
||||
<Image
|
||||
Width="256"
|
||||
Height="256"
|
||||
Source="/Resources/nodata02.png">
|
||||
<i:Interaction.Behaviors>
|
||||
<ia:DataTriggerBehavior Binding="{Binding DownloadingList}" Value="{x:Null}">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="True" />
|
||||
</ia:DataTriggerBehavior>
|
||||
<ia:DataTriggerBehavior Binding="{Binding DownloadingList.Count}" Value="0">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="True" />
|
||||
</ia:DataTriggerBehavior>
|
||||
<ia:DataTriggerBehavior
|
||||
Binding="{Binding DownloadingList.Count, Converter={StaticResource CountConverter}}" Value="true">
|
||||
<ia:ChangePropertyAction PropertyName="IsVisible" Value="False" />
|
||||
</ia:DataTriggerBehavior>
|
||||
</i:Interaction.Behaviors>
|
||||
Source="/Resources/nodata02.png"
|
||||
IsVisible="{Binding !DownloadingList.Count}">
|
||||
</Image>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
Reference in New Issue
Block a user