fix: 修复提示框异步问题

This commit is contained in:
yaobiao
2023-11-29 10:49:52 +08:00
parent 7efb626748
commit b48f6de554
7 changed files with 45 additions and 30 deletions

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\"/>
<Folder Include="Models\" />
<AvaloniaResource Include="Resources\**" />
</ItemGroup>

View File

@@ -1,4 +1,5 @@
using DownKyi.Images;
using System.Threading.Tasks;
using DownKyi.Images;
using DownKyi.Utils;
using DownKyi.ViewModels.Dialogs;
using Prism.Services.Dialogs;
@@ -20,11 +21,11 @@ public class AlertService
/// <param name="message"></param>
/// <param name="buttonNumber"></param>
/// <returns></returns>
public ButtonResult ShowInfo(string message, int buttonNumber = 2)
public async Task<ButtonResult> ShowInfo(string message, int buttonNumber = 2)
{
VectorImage image = SystemIcon.Instance().Info;
string title = DictionaryResource.GetString("Info");
return ShowMessage(image, title, message, buttonNumber);
return await ShowMessage(image, title, message, buttonNumber);
}
/// <summary>
@@ -33,11 +34,11 @@ public class AlertService
/// <param name="message"></param>
/// <param name="buttonNumber"></param>
/// <returns></returns>
public ButtonResult ShowWarning(string message, int buttonNumber = 1)
public async Task<ButtonResult> ShowWarning(string message, int buttonNumber = 1)
{
VectorImage image = SystemIcon.Instance().Warning;
string title = DictionaryResource.GetString("Warning");
return ShowMessage(image, title, message, buttonNumber);
return await ShowMessage(image, title, message, buttonNumber);
}
/// <summary>
@@ -45,30 +46,43 @@ public class AlertService
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public ButtonResult ShowError(string message)
public async Task<ButtonResult> ShowError(string message)
{
VectorImage image = SystemIcon.Instance().Error;
string title = DictionaryResource.GetString("Error");
return ShowMessage(image, title, message, 1);
return await ShowMessage(image, title, message, 1);
}
public ButtonResult ShowMessage(VectorImage image, string type, string message, int buttonNumber)
public async Task<ButtonResult> ShowMessage(VectorImage image, string type, string message, int buttonNumber)
{
ButtonResult result = ButtonResult.None;
var result = ButtonResult.None;
if (dialogService == null)
{
return result;
}
DialogParameters param = new DialogParameters
var param = new DialogParameters
{
{ "image", image },
{ "title", type },
{ "message", message },
{ "button_number", buttonNumber }
};
var isEnd = false;
dialogService.ShowDialog(ViewAlertDialogViewModel.Tag, param,
buttonResult => { result = buttonResult.Result; });
buttonResult =>
{
result = buttonResult.Result;
isEnd = true;
});
await Task.Run(() =>
{
while (true)
{
if (isEnd) break;
}
});
return result;
}
}

View File

@@ -487,7 +487,7 @@ public abstract class DownloadService
AlertService alertService = new AlertService(dialogService);
ButtonResult result =
alertService.ShowError($"{path}{DictionaryResource.GetString("DirectoryError")}");
await alertService.ShowError($"{path}{DictionaryResource.GetString("DirectoryError")}");
return;
}

View File

@@ -1,5 +1,6 @@
using System;
using DownKyi.Images;
using DownKyi.Models;
using DownKyi.Utils;
using Prism.Commands;
using Prism.Mvvm;
@@ -15,16 +16,16 @@ public class BaseDialogViewModel : BindableBase, IDialogAware
public string Title
{
get { return title; }
set { SetProperty(ref title, value); }
get => title;
set => SetProperty(ref title, value);
}
private VectorImage closeIcon;
public VectorImage CloseIcon
{
get { return closeIcon; }
set { SetProperty(ref closeIcon, value); }
get => closeIcon;
set => SetProperty(ref closeIcon, value);
}
#endregion
@@ -33,14 +34,14 @@ public class BaseDialogViewModel : BindableBase, IDialogAware
{
#region
// Title = new AppInfo().Name;
// CloseIcon = new VectorImage
// {
// Height = SystemIcon.Instance().Close.Height,
// Width = SystemIcon.Instance().Close.Width,
// Data = SystemIcon.Instance().Close.Data,
// Fill = SystemIcon.Instance().Close.Fill
// };
Title = new AppInfo().Name;
CloseIcon = new VectorImage
{
Height = SystemIcon.Instance().Close.Height,
Width = SystemIcon.Instance().Close.Width,
Data = SystemIcon.Instance().Close.Data,
Fill = SystemIcon.Instance().Close.Fill
};
#endregion
}

View File

@@ -160,10 +160,10 @@ namespace DownKyi.ViewModels.DownloadManager
/// <summary>
/// 删除事件
/// </summary>
private void ExecuteRemoveVideoCommand()
private async void ExecuteRemoveVideoCommand()
{
AlertService alertService = new AlertService(DialogService);
ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"), 2);
ButtonResult result = await alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"), 2);
if (result != ButtonResult.OK)
{
return;

View File

@@ -111,7 +111,7 @@ namespace DownKyi.ViewModels.DownloadManager
private async void ExecuteClearAllDownloadedCommand()
{
AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
ButtonResult result = await alertService.ShowWarning(DictionaryResource.GetString("ConfirmDelete"));
if (result != ButtonResult.OK)
{
return;

View File

@@ -440,7 +440,7 @@ public class ViewNetworkViewModel : ViewModelBase
/// 下载器选择事件
/// </summary>
/// <param name="parameter"></param>
private void ExecuteSelectDownloaderCommand(string parameter)
private async void ExecuteSelectDownloaderCommand(string parameter)
{
Downloader downloader;
switch (parameter)
@@ -463,7 +463,7 @@ public class ViewNetworkViewModel : ViewModelBase
PublishTip(isSucceed);
AlertService alertService = new AlertService(dialogService);
ButtonResult result = alertService.ShowInfo(DictionaryResource.GetString("ConfirmReboot"));
ButtonResult result = await alertService.ShowInfo(DictionaryResource.GetString("ConfirmReboot"));
if (result == ButtonResult.OK)
{
(App.Current.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime).Shutdown(0);