mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
Fix #31
This commit is contained in:
@@ -5,6 +5,7 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.Windows.AppLifecycle;
|
||||
using Snap.Hutao.Core.LifeCycle;
|
||||
using Snap.Hutao.Core.Logging;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -6,7 +6,6 @@ using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
using Snap.Hutao.Control.Behavior;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using Snap.Hutao.Extension;
|
||||
|
||||
namespace Snap.Hutao.Control.Extension;
|
||||
|
||||
@@ -33,20 +32,15 @@ internal static class ContentDialogExtensions
|
||||
/// 阻止用户交互
|
||||
/// </summary>
|
||||
/// <param name="contentDialog">对话框</param>
|
||||
/// <param name="switchToMainThread">切换到主线程</param>
|
||||
/// <returns>用于恢复用户交互</returns>
|
||||
public static async ValueTask<IDisposable> BlockAsync(this ContentDialog contentDialog, bool switchToMainThread = false)
|
||||
public static async ValueTask<IAsyncDisposable> BlockAsync(this ContentDialog contentDialog)
|
||||
{
|
||||
if (switchToMainThread)
|
||||
{
|
||||
await ThreadHelper.SwitchToMainThreadAsync();
|
||||
}
|
||||
|
||||
await ThreadHelper.SwitchToMainThreadAsync();
|
||||
contentDialog.ShowAsync().AsTask().SafeForget();
|
||||
return new ContentDialogHider(contentDialog);
|
||||
}
|
||||
|
||||
private struct ContentDialogHider : IDisposable
|
||||
private struct ContentDialogHider : IAsyncDisposable
|
||||
{
|
||||
private readonly ContentDialog contentDialog;
|
||||
|
||||
@@ -55,8 +49,11 @@ internal static class ContentDialogExtensions
|
||||
this.contentDialog = contentDialog;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await ThreadHelper.SwitchToMainThreadAsync();
|
||||
|
||||
// Hide() must be called on main thread.
|
||||
contentDialog.Hide();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Snap.Hutao.Context.Database;
|
||||
using Snap.Hutao.Context.FileSystem;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
using Snap.Hutao.Core.Logging;
|
||||
|
||||
namespace Snap.Hutao.Extension;
|
||||
namespace Snap.Hutao.Core.Threading;
|
||||
|
||||
/// <summary>
|
||||
/// 任务扩展
|
||||
@@ -22,8 +22,9 @@ public static class TaskExtensions
|
||||
{
|
||||
await task;
|
||||
}
|
||||
catch
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@ public static class TaskExtensions
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
logger?.LogError(EventIds.TaskException, e, "{caller}:\r\n{exception}", nameof(SafeForget), e.GetBaseException());
|
||||
}
|
||||
@@ -54,7 +55,7 @@ public static class TaskExtensions
|
||||
/// <param name="task">任务</param>
|
||||
/// <param name="logger">日志器</param>
|
||||
/// <param name="onException">发生异常时调用</param>
|
||||
public static async void SafeForget(this Task task, ILogger? logger = null, Action<Exception>? onException = null)
|
||||
public static async void SafeForget(this Task task, ILogger? logger = null, Action<System.Exception>? onException = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -64,7 +65,7 @@ public static class TaskExtensions
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
logger?.LogError(EventIds.TaskException, e, "{caller}:\r\n{exception}", nameof(SafeForget), e.GetBaseException());
|
||||
onException?.Invoke(e);
|
||||
@@ -78,7 +79,7 @@ public static class TaskExtensions
|
||||
/// <param name="logger">日志器</param>
|
||||
/// <param name="onCanceled">任务取消时调用</param>
|
||||
/// <param name="onException">发生异常时调用</param>
|
||||
public static async void SafeForget(this Task task, ILogger? logger = null, Action? onCanceled = null, Action<Exception>? onException = null)
|
||||
public static async void SafeForget(this Task task, ILogger? logger = null, Action? onCanceled = null, Action<System.Exception>? onException = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -88,7 +89,7 @@ public static class TaskExtensions
|
||||
{
|
||||
onCanceled?.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
logger?.LogError(EventIds.TaskException, e, "{caller}:\r\n{exception}", nameof(SafeForget), e.GetBaseException());
|
||||
onException?.Invoke(e);
|
||||
@@ -2,7 +2,7 @@
|
||||
"profiles": {
|
||||
"Snap.Hutao (Package)": {
|
||||
"commandName": "MsixPackage",
|
||||
"nativeDebugging": false
|
||||
"nativeDebugging": true
|
||||
},
|
||||
"Snap.Hutao (Unpackaged)": {
|
||||
"commandName": "Project"
|
||||
|
||||
@@ -5,7 +5,6 @@ using Microsoft.UI.Xaml.Controls;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Core.Logging;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Snap.Hutao.View.Page;
|
||||
|
||||
@@ -5,7 +5,7 @@ using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Snap.Hutao.Core;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using Snap.Hutao.Service.Navigation;
|
||||
using Windows.System;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ using Snap.Hutao.Control;
|
||||
using Snap.Hutao.Control.Extension;
|
||||
using Snap.Hutao.Core.Threading;
|
||||
using Snap.Hutao.Core.Threading.CodeAnalysis;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Factory.Abstraction;
|
||||
using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Model.InterChange.Achievement;
|
||||
@@ -403,8 +402,8 @@ internal class AchievementViewModel
|
||||
string json;
|
||||
try
|
||||
{
|
||||
Task<string> task = Clipboard.GetContent().GetTextAsync().AsTask();
|
||||
json = await task.ConfigureAwait(false);
|
||||
await ThreadHelper.SwitchToMainThreadAsync();
|
||||
json = await Clipboard.GetContent().GetTextAsync();
|
||||
}
|
||||
catch (COMException ex)
|
||||
{
|
||||
@@ -465,7 +464,7 @@ internal class AchievementViewModel
|
||||
};
|
||||
|
||||
ImportResult result;
|
||||
using (await importingDialog.InitializeWithWindow(mainWindow).BlockAsync().ConfigureAwait(false))
|
||||
await using (await importingDialog.InitializeWithWindow(mainWindow).BlockAsync().ConfigureAwait(false))
|
||||
{
|
||||
result = await achievementService.ImportFromUIAFAsync(archive, uiaf.List, option).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ internal class GachaLogViewModel : ObservableObject, ISupportCancellation
|
||||
|
||||
private async Task RefreshByWebCacheAsync()
|
||||
{
|
||||
Statistics = await gachaLogService.RefreshAsync();
|
||||
//Statistics = await gachaLogService.RefreshAsync();
|
||||
}
|
||||
|
||||
private async Task RefreshByManualInputAsync()
|
||||
|
||||
Reference in New Issue
Block a user