fix: keep remote heartbeat UI side effect free

This commit is contained in:
2026-09-20 23:25:46 +08:00
parent 1d5c472e88
commit 15b0477b44
3 changed files with 35 additions and 12 deletions
+15 -7
View File
@@ -85,16 +85,22 @@ public sealed class WindowsAgentBackend(AccountBindingStore bindings, ServiceOpt
? string.Equals(binding.WechatId, current.WechatId, StringComparison.OrdinalIgnoreCase)
: string.Equals(binding.Nickname, current.DisplayName, StringComparison.Ordinal);
public async Task<IReadOnlyList<AccountInfo>> AccountsAsync(CancellationToken cancellationToken)
public Task<IReadOnlyList<AccountInfo>> AccountsAsync(CancellationToken cancellationToken) =>
AccountsAsync(cancellationToken, refreshUiIdentity: true);
public async Task<IReadOnlyList<AccountInfo>> AccountsAsync(CancellationToken cancellationToken, bool refreshUiIdentity)
{
var targets = await ReadUiTargetsAsync(cancellationToken, true);
var targets = await ReadUiTargetsAsync(cancellationToken, refreshUiIdentity);
var accounts = await ReadDatabaseAccountsAsync(cancellationToken);
await AutoBindMatchesAsync(accounts, targets, cancellationToken);
if (refreshUiIdentity)
await AutoBindMatchesAsync(accounts, targets, cancellationToken);
var current = bindings.ReadAll();
var singleBoundTarget = !refreshUiIdentity && current.Count == 1 && targets.Count == 1;
var live = current.Where(binding => targets.Any(target =>
target.ProcessId == binding.ProcessId && target.WindowHandle == binding.WindowHandle &&
(string.IsNullOrWhiteSpace(target.WechatId) && string.IsNullOrWhiteSpace(target.Nickname) ||
BindingMatches(binding, new WechatAccountSnapshot(target.Nickname ?? string.Empty, target.WechatId)))))
(target.ProcessId == binding.ProcessId && target.WindowHandle == binding.WindowHandle &&
(!refreshUiIdentity || string.IsNullOrWhiteSpace(target.WechatId) && string.IsNullOrWhiteSpace(target.Nickname) ||
BindingMatches(binding, new WechatAccountSnapshot(target.Nickname ?? string.Empty, target.WechatId)))) ||
singleBoundTarget))
.Select(binding => binding.AccountId)
.ToHashSet(StringComparer.OrdinalIgnoreCase);
return accounts.Select(account =>
@@ -466,7 +472,9 @@ public sealed class WindowsAgentBackend(AccountBindingStore bindings, ServiceOpt
return Task.FromResult<object>(new
{
serviceOnline = true,
wechatAvailable = report.Errors.Count == 0,
// Process/window presence is availability; a changed control tree is a degraded UI state,
// not a stopped WeChat process.
wechatAvailable = report.Processes.Count > 0 && report.WindowFound,
sessionAvailable = report.UserInteractive && report.InputDesktopAvailable,
sessionLocked = report.Errors.Contains(WxAgentErrorCode.SessionLocked),
report.WindowFound,