fix(downloads): keep active priority menu stable

Treat the selected priority as a disabled no-op so clicking it no longer closes the context menu. Reorder packages consistently across high, normal, and low priority groups while preserving stable order within each group. Add regression coverage for all priority transitions and the active menu state.
This commit is contained in:
Sucukdeluxe
2026-08-15 03:23:24 +02:00
parent f4b9bc9f12
commit 135b2e7316
4 changed files with 104 additions and 13 deletions
+14 -12
View File
@@ -5504,23 +5504,25 @@ export class DownloadManager extends EventEmitter {
const pkg = this.session.packages[packageId];
if (!pkg) return;
if (priority !== "high" && priority !== "normal" && priority !== "low") return;
if ((pkg.priority || "normal") === priority) return;
pkg.priority = priority;
pkg.updatedAt = nowMs();
if (priority === "high") {
const order = this.session.packageOrder;
const idx = order.indexOf(packageId);
if (idx > 0) {
order.splice(idx, 1);
let insertAt = 0;
for (let i = 0; i < order.length; i++) {
const p = this.session.packages[order[i]];
if (p && p.priority === "high") {
insertAt = i + 1;
}
const order = this.session.packageOrder;
const currentIndex = order.indexOf(packageId);
if (currentIndex >= 0) {
order.splice(currentIndex, 1);
const priorityRank: Record<PackagePriority, number> = { high: 0, normal: 1, low: 2 };
let insertAt = order.length;
for (let index = 0; index < order.length; index += 1) {
const other = this.session.packages[order[index]];
const otherPriority = other?.priority || "normal";
if (priorityRank[otherPriority] > priorityRank[priority]) {
insertAt = index;
break;
}
order.splice(insertAt, 0, packageId);
}
order.splice(insertAt, 0, packageId);
}
this.persistSoon();
+1 -1
View File
@@ -6114,7 +6114,7 @@ export function App(): ReactElement {
const label = p === "high" ? "Hoch" : p === "low" ? "Niedrig" : "Standard";
const pkgIds = selectedPackageIds;
const allMatch = pkgIds.every((id) => (snapshot.session.packages[id]?.priority || "normal") === p);
return <button key={p} className={`ctx-menu-item${allMatch ? " ctx-menu-active" : ""}`} onClick={() => { for (const id of pkgIds) void window.rd.setPackagePriority(id, p).catch(() => {}); setContextMenu(null); }}>{allMatch ? `[Aktiv] ${label}` : label}</button>;
return <button key={p} className={`ctx-menu-item${allMatch ? " ctx-menu-active" : ""}`} disabled={allMatch} onClick={() => { for (const id of pkgIds) void window.rd.setPackagePriority(id, p).catch(() => {}); setContextMenu(null); }}>{allMatch ? `[Aktiv] ${label}` : label}</button>;
})}
</div>
</div>