优化代码
This commit is contained in:
@@ -868,7 +868,7 @@ namespace Ink_Canvas
|
|||||||
LogHelper.WriteLogToFile($"App | 清理更新标记文件失败: {ex.Message}", LogHelper.LogType.Warning);
|
LogHelper.WriteLogToFile($"App | 清理更新标记文件失败: {ex.Message}", LogHelper.LogType.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1174,7 +1174,7 @@ namespace Ink_Canvas
|
|||||||
await Task.Delay(600);
|
await Task.Delay(600);
|
||||||
Dispatcher.Invoke(() => _taskbar?.ForceCreate());
|
Dispatcher.Invoke(() => _taskbar?.ForceCreate());
|
||||||
});
|
});
|
||||||
Dispatcher.BeginInvoke(new Action(() =>
|
_ = Dispatcher.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
if (_pendingLocalizedResourceSet != null)
|
if (_pendingLocalizedResourceSet != null)
|
||||||
{
|
{
|
||||||
@@ -1189,7 +1189,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"App | 处理启动URI参数: {startupUriArg}", LogHelper.LogType.Event);
|
LogHelper.WriteLogToFile($"App | 处理启动URI参数: {startupUriArg}", LogHelper.LogType.Event);
|
||||||
// 延迟一点执行,确保窗口初始化完成
|
// 延迟一点执行,确保窗口初始化完成
|
||||||
Task.Delay(1000).ContinueWith(_ =>
|
_ = Task.Delay(1000).ContinueWith(_ =>
|
||||||
{
|
{
|
||||||
mainWindow.Dispatcher.Invoke(() =>
|
mainWindow.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 异步上传文件
|
/// 异步上传文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async Task<bool> UploadFileAsync(string filePath, CancellationToken cancellationToken = default)
|
public Task<bool> UploadFileAsync(string filePath, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -528,19 +528,19 @@ namespace Ink_Canvas.Helpers
|
|||||||
// 检查是否启用
|
// 检查是否启用
|
||||||
if (!IsUploadEnabled())
|
if (!IsUploadEnabled())
|
||||||
{
|
{
|
||||||
return false;
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 基本验证
|
// 基本验证
|
||||||
if (!File.Exists(filePath))
|
if (!File.Exists(filePath))
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败:文件不存在 - {filePath}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"[{GetType().Name}] 上传失败:文件不存在 - {filePath}", LogHelper.LogType.Error);
|
||||||
return false;
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidFile(filePath))
|
if (!IsValidFile(filePath))
|
||||||
{
|
{
|
||||||
return false;
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保队列已初始化
|
// 确保队列已初始化
|
||||||
@@ -552,7 +552,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
// 加入队列
|
// 加入队列
|
||||||
EnqueueFile(filePath, 0, cancellationToken);
|
EnqueueFile(filePath, 0, cancellationToken);
|
||||||
|
|
||||||
return true;
|
return Task.FromResult(true);
|
||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
@@ -562,7 +562,7 @@ namespace Ink_Canvas.Helpers
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile($"[{GetType().Name}] 加入上传队列时出错: {ex.Message}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"[{GetType().Name}] 加入上传队列时出错: {ex.Message}", LogHelper.LogType.Error);
|
||||||
return false;
|
return Task.FromResult(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2374,7 +2374,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
_pendingStartupAutoUpdateCheck = false;
|
_pendingStartupAutoUpdateCheck = false;
|
||||||
await Task.Delay(3000);
|
await Task.Delay(3000);
|
||||||
Dispatcher.BeginInvoke(new Action(() =>
|
_ = Dispatcher.BeginInvoke(new Action(() =>
|
||||||
{
|
{
|
||||||
LogHelper.WriteLogToFile("AutoUpdate | Running deferred auto-update check at UI idle");
|
LogHelper.WriteLogToFile("AutoUpdate | Running deferred auto-update check at UI idle");
|
||||||
AutoUpdate();
|
AutoUpdate();
|
||||||
|
|||||||
@@ -272,21 +272,21 @@ namespace Ink_Canvas
|
|||||||
/// - 显示通知
|
/// - 显示通知
|
||||||
/// - 包含异常处理
|
/// - 包含异常处理
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private async Task PasteImageFromClipboard(Point? position = null)
|
private Task PasteImageFromClipboard(Point? position = null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!Clipboard.ContainsImage())
|
if (!Clipboard.ContainsImage())
|
||||||
{
|
{
|
||||||
ShowNotification("剪贴板中没有图片");
|
ShowNotification("剪贴板中没有图片");
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
var clipboardImage = Clipboard.GetImage();
|
var clipboardImage = Clipboard.GetImage();
|
||||||
if (clipboardImage == null)
|
if (clipboardImage == null)
|
||||||
{
|
{
|
||||||
ShowNotification("无法获取剪贴板图片");
|
ShowNotification("无法获取剪贴板图片");
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建Image控件
|
// 创建Image控件
|
||||||
@@ -383,6 +383,7 @@ namespace Ink_Canvas
|
|||||||
ShowNotification($"粘贴图片失败: {ex.Message}");
|
ShowNotification($"粘贴图片失败: {ex.Message}");
|
||||||
LogHelper.WriteLogToFile($"粘贴图片失败: {ex.Message}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"粘贴图片失败: {ex.Message}", LogHelper.LogType.Error);
|
||||||
}
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -496,7 +496,7 @@ namespace Ink_Canvas
|
|||||||
/// 10. 提交历史记录
|
/// 10. 提交历史记录
|
||||||
/// 11. 插入图片后切换到选择模式并刷新浮动栏高光显示
|
/// 11. 插入图片后切换到选择模式并刷新浮动栏高光显示
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private async Task InsertScreenshotToCanvas(Bitmap bitmap)
|
private Task InsertScreenshotToCanvas(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -504,7 +504,7 @@ namespace Ink_Canvas
|
|||||||
if (bitmap == null || bitmap.Width <= 0 || bitmap.Height <= 0)
|
if (bitmap == null || bitmap.Width <= 0 || bitmap.Height <= 0)
|
||||||
{
|
{
|
||||||
ShowNotification("无效的截图");
|
ShowNotification("无效的截图");
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将Bitmap转换为WPF BitmapSource
|
// 将Bitmap转换为WPF BitmapSource
|
||||||
@@ -513,7 +513,7 @@ namespace Ink_Canvas
|
|||||||
if (bitmapSource == null)
|
if (bitmapSource == null)
|
||||||
{
|
{
|
||||||
ShowNotification("转换截图失败");
|
ShowNotification("转换截图失败");
|
||||||
return;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建WPF Image控件
|
// 创建WPF Image控件
|
||||||
@@ -572,6 +572,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
bitmap?.Dispose();
|
bitmap?.Dispose();
|
||||||
}
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -591,7 +592,7 @@ namespace Ink_Canvas
|
|||||||
/// 8. 提交历史记录
|
/// 8. 提交历史记录
|
||||||
/// 9. 插入图片后切换到选择模式并刷新浮动栏高光显示
|
/// 9. 插入图片后切换到选择模式并刷新浮动栏高光显示
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private async Task InsertBitmapSourceToCanvas(BitmapSource bitmapSource, string successMessage = "截图已插入到画布", string failureMessagePrefix = "插入截图失败")
|
private Task InsertBitmapSourceToCanvas(BitmapSource bitmapSource, string successMessage = "截图已插入到画布", string failureMessagePrefix = "插入截图失败")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -647,6 +648,7 @@ namespace Ink_Canvas
|
|||||||
ShowNotification($"{failureMessagePrefix}: {ex.Message}");
|
ShowNotification($"{failureMessagePrefix}: {ex.Message}");
|
||||||
LogHelper.WriteLogToFile($"插入摄像头截图失败: {ex.Message}", LogHelper.LogType.Error);
|
LogHelper.WriteLogToFile($"插入摄像头截图失败: {ex.Message}", LogHelper.LogType.Error);
|
||||||
}
|
}
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -592,7 +592,7 @@ namespace Ink_Canvas
|
|||||||
{
|
{
|
||||||
// 先展开浮动栏,然后进入批注状态
|
// 先展开浮动栏,然后进入批注状态
|
||||||
// UnFoldFloatingBar 方法内部会根据设置自动进入批注模式
|
// UnFoldFloatingBar 方法内部会根据设置自动进入批注模式
|
||||||
UnFoldFloatingBar(null);
|
_ = UnFoldFloatingBar(null);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -657,7 +657,7 @@ namespace Ink_Canvas.Windows
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存按钮点击事件
|
/// 保存按钮点击事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private async void BtnSave_Click(object sender, RoutedEventArgs e)
|
private void BtnSave_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ namespace Ink_Canvas.Windows.SettingsViews.Pages
|
|||||||
if (mainWindow != null)
|
if (mainWindow != null)
|
||||||
{
|
{
|
||||||
mainWindow.ResetUpdateCheckRetry();
|
mainWindow.ResetUpdateCheckRetry();
|
||||||
await System.Threading.Tasks.Task.Run(async () =>
|
await System.Threading.Tasks.Task.Run(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user