refactor: extract enablePackage core from handleEnable

This commit is contained in:
2026-06-21 14:25:08 +02:00
parent 8cb0e32739
commit fb3a785027
+25 -16
View File
@@ -714,30 +714,39 @@ async function runManagerEnable(payload) {
await waitForQueue(); await waitForQueue();
} }
// Shared enable core used by the Workflow tab and the mirror search palette.
// Performs the Manager enable + trial bookkeeping + success toast.
// Returns true on success, false if Manager was busy. Throws on failure.
// Caller owns its own busy UI and restart affordance.
async function enablePackage(pkg, info, temporary) {
if (!info) throw new Error("no enable info for " + pkg);
if (await managerIsBusy()) {
notify("ComfyUI Manager is busy. Please try again in a moment.", "warn");
return false;
}
await runManagerEnable(enablePayload(pkg, info));
const route = temporary ? "/nodes-stats/trials/start" : "/nodes-stats/trials/stop";
await fetch(route, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ package: pkg }),
});
notify(`Enabled ${pkg}${temporary ? " for a 7-day trial" : ""}. Restart ComfyUI to apply.`, "success");
return true;
}
// Enable a disabled package, optionally under a temporary trial. A permanent // Enable a disabled package, optionally under a temporary trial. A permanent
// enable clears any existing trial row so the package is never auto-disabled. // enable clears any existing trial row so the package is never auto-disabled.
async function handleEnable(pkg, temporary, dialog) { async function handleEnable(pkg, temporary, dialog) {
const entry = _lastWorkflowScan.disabled.find((d) => d.pkg === pkg); const entry = _lastWorkflowScan.disabled.find((d) => d.pkg === pkg);
const info = entry && entry.info; const info = entry && entry.info;
if (!info) return; if (!info) return;
if (await managerIsBusy()) {
notify("ComfyUI Manager is busy. Please try again in a moment.", "warn");
return;
}
setWorkflowButtonsBusy(dialog, true); setWorkflowButtonsBusy(dialog, true);
try { try {
await runManagerEnable(enablePayload(pkg, info)); if (await enablePackage(pkg, info, temporary)) {
const route = temporary ? "/nodes-stats/trials/start" : "/nodes-stats/trials/stop"; entry.info.state = "enabled";
await fetch(route, { showRestartBanner(dialog);
method: "POST", }
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ package: pkg }),
});
if (entry.info) entry.info.state = "enabled";
showRestartBanner(dialog);
notify(`Enabled ${pkg}${temporary ? " for a 7-day trial" : ""}. Restart ComfyUI to apply.`, "success");
} catch (e) { } catch (e) {
notify("Failed to enable: " + e.message, "error"); notify("Failed to enable: " + e.message, "error");
} finally { } finally {