Skip to content

Commit f473e1c

Browse files
JusterZhuclaude
andcommitted
fix: address Copilot review suggestions
- Fix dialog hang when user closes window via X button (set TCS result before Close, register Closed event as fallback) - Replace hardcoded 'cancelled by user' with localized string - Add ConfigureAwait(false) in scan loop to avoid UI thread context switching on every file iteration Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent c9c48bf commit f473e1c

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

src/Services/EncryptionDetectionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public async Task<EncryptionScanResult> ScanDirectoryAsync(
102102
foreach (var filePath in files)
103103
{
104104
var relativePath = Path.GetRelativePath(directoryPath, filePath);
105-
var suspicious = await Task.Run(() => ScanFile(filePath, relativePath));
105+
var suspicious = await Task.Run(() => ScanFile(filePath, relativePath)).ConfigureAwait(false);
106106

107107
if (suspicious != null)
108108
result.SuspiciousFiles.Add(suspicious);

src/Services/LocalizationService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public string this[string key]
9191
["Patch.ScanBtnInclude"] = "仍然打包全部文件",
9292
["Patch.ScanBtnCancel"] = "取消",
9393
["Patch.ScanSkipped"] = "已跳过 {0} 个可疑文件",
94+
["Patch.ScanCancelled"] = "用户取消打包",
9495
["Ext.Title"] = "扩展包生成",
9596
["Ext.BasicInfo"] = "基本信息",
9697
["Ext.Name"] = "名称",
@@ -243,6 +244,7 @@ public string this[string key]
243244
["Patch.ScanBtnInclude"] = "Include all files anyway",
244245
["Patch.ScanBtnCancel"] = "Cancel",
245246
["Patch.ScanSkipped"] = "Skipped {0} suspicious file(s)",
247+
["Patch.ScanCancelled"] = "Packaging cancelled by user",
246248
["Ext.Title"] = "Extension Package",
247249
["Ext.BasicInfo"] = "Basic Info",
248250
["Ext.Name"] = "Name",

src/ViewModels/PatchViewModel.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ async Task Build()
114114
switch (choice)
115115
{
116116
case EncryptionDialogChoice.Cancel:
117-
L(_loc.T("Patch.Failed", "cancelled by user"));
118-
Status = _loc.T("Patch.Failed", "cancelled by user");
117+
L(_loc["Patch.ScanCancelled"]);
118+
Status = _loc["Patch.ScanCancelled"];
119119
Directory.Delete(tmp, true);
120120
return;
121121
case EncryptionDialogChoice.SkipSuspicious:
@@ -259,9 +259,13 @@ private static async Task<EncryptionDialogChoice> ShowEncryptionDialogAsync(Encr
259259
MinWidth = 70
260260
};
261261

262-
btnSkip.Click += (_, _) => { dialog.Close(); tcs.TrySetResult(EncryptionDialogChoice.SkipSuspicious); };
263-
btnInclude.Click += (_, _) => { dialog.Close(); tcs.TrySetResult(EncryptionDialogChoice.IncludeAll); };
264-
btnCancel.Click += (_, _) => { dialog.Close(); tcs.TrySetResult(EncryptionDialogChoice.Cancel); };
262+
// Set result *before* Close so the Closed handler doesn't override it
263+
btnSkip.Click += (_, _) => { tcs.TrySetResult(EncryptionDialogChoice.SkipSuspicious); dialog.Close(); };
264+
btnInclude.Click += (_, _) => { tcs.TrySetResult(EncryptionDialogChoice.IncludeAll); dialog.Close(); };
265+
btnCancel.Click += (_, _) => { tcs.TrySetResult(EncryptionDialogChoice.Cancel); dialog.Close(); };
266+
267+
// If user closes the window via X button or Alt+F4, treat as Cancel
268+
dialog.Closed += (_, _) => tcs.TrySetResult(EncryptionDialogChoice.Cancel);
265269

266270
btnPanel.Children.Add(btnSkip);
267271
btnPanel.Children.Add(btnInclude);
@@ -275,12 +279,7 @@ private static async Task<EncryptionDialogChoice> ShowEncryptionDialogAsync(Encr
275279
else
276280
dialog.Show();
277281

278-
// If user closes the window, treat as cancel
279-
await tcs.Task;
280-
if (!tcs.Task.IsCompleted)
281-
tcs.TrySetResult(EncryptionDialogChoice.Cancel);
282-
283-
return tcs.Task.Result;
282+
return await tcs.Task;
284283
}
285284

286285
private static void AddRiskGroup(Avalonia.Controls.StackPanel parent, string title,

0 commit comments

Comments
 (0)