refactor: extract enablePackage core from handleEnable
This commit is contained in:
+22
-13
@@ -714,20 +714,16 @@ async function runManagerEnable(payload) {
|
|||||||
await waitForQueue();
|
await waitForQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable a disabled package, optionally under a temporary trial. A permanent
|
// Shared enable core used by the Workflow tab and the mirror search palette.
|
||||||
// enable clears any existing trial row so the package is never auto-disabled.
|
// Performs the Manager enable + trial bookkeeping + success toast.
|
||||||
async function handleEnable(pkg, temporary, dialog) {
|
// Returns true on success, false if Manager was busy. Throws on failure.
|
||||||
const entry = _lastWorkflowScan.disabled.find((d) => d.pkg === pkg);
|
// Caller owns its own busy UI and restart affordance.
|
||||||
const info = entry && entry.info;
|
async function enablePackage(pkg, info, temporary) {
|
||||||
if (!info) return;
|
if (!info) throw new Error("no enable info for " + pkg);
|
||||||
|
|
||||||
if (await managerIsBusy()) {
|
if (await managerIsBusy()) {
|
||||||
notify("ComfyUI Manager is busy. Please try again in a moment.", "warn");
|
notify("ComfyUI Manager is busy. Please try again in a moment.", "warn");
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setWorkflowButtonsBusy(dialog, true);
|
|
||||||
try {
|
|
||||||
await runManagerEnable(enablePayload(pkg, info));
|
await runManagerEnable(enablePayload(pkg, info));
|
||||||
const route = temporary ? "/nodes-stats/trials/start" : "/nodes-stats/trials/stop";
|
const route = temporary ? "/nodes-stats/trials/start" : "/nodes-stats/trials/stop";
|
||||||
await fetch(route, {
|
await fetch(route, {
|
||||||
@@ -735,9 +731,22 @@ async function handleEnable(pkg, temporary, dialog) {
|
|||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ package: pkg }),
|
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");
|
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 clears any existing trial row so the package is never auto-disabled.
|
||||||
|
async function handleEnable(pkg, temporary, dialog) {
|
||||||
|
const entry = _lastWorkflowScan.disabled.find((d) => d.pkg === pkg);
|
||||||
|
const info = entry && entry.info;
|
||||||
|
if (!info) return;
|
||||||
|
setWorkflowButtonsBusy(dialog, true);
|
||||||
|
try {
|
||||||
|
if (await enablePackage(pkg, info, temporary)) {
|
||||||
|
entry.info.state = "enabled";
|
||||||
|
showRestartBanner(dialog);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify("Failed to enable: " + e.message, "error");
|
notify("Failed to enable: " + e.message, "error");
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user