T-571 降低更新前台抢焦点

This commit is contained in:
chengma
2026-07-09 15:04:20 +08:00
parent d595e7455c
commit 5400145147
7 changed files with 403 additions and 11 deletions
+15
View File
@@ -568,6 +568,8 @@ class ApplyWorker(BaseWorker):
self._current_batch_size = None
self._batch_count = 0
self._progress_lock = threading.Lock()
self._foreground_lock = threading.Lock()
self._foregrounded_aliases = set()
self.diagnostic_log_dir = diagnostic_log_dir
self._run_id = None
@@ -890,11 +892,13 @@ class ApplyWorker(BaseWorker):
db.mark_running(task.id, "apply", path=self.db_path)
self.row_updated.emit(task.id, {"status": "running", "last_error": None})
current_step = "apply_task"
bring_to_front = self._should_bring_account_to_front(account)
result = editor.apply_task(
account,
task,
close_success_tab=self.close_success_tab,
on_step=on_step,
bring_to_front=bring_to_front,
)
committed = bool(result.get("committed")) and not result.get("error")
error = result.get("error")
@@ -974,6 +978,17 @@ class ApplyWorker(BaseWorker):
exc=exc,
)
return "failed"
def _should_bring_account_to_front(self, account):
alias = str(getattr(account, "alias", "") or "").strip()
if not alias:
return True
with self._foreground_lock:
if alias in self._foregrounded_aliases:
return False
self._foregrounded_aliases.add(alias)
return True
def _record_outcome(self, counters, total, outcome):
with self._progress_lock:
counters["done"] += 1