Enhance Settings.fds management and installation checks

- Introduced functions to ensure the `IsInstalled` flag is set in `Settings.fds`, preventing the UI from displaying the /Install wizard.
- Added logic to create or patch `Settings.fds` with installation details, including the installation date and version.
- Updated the `install_swarm_comfy.py` script to call the new function, ensuring the installation state is correctly managed during backend operations.
- Added tests to verify the presence of the `IsInstalled` flag in the relevant scripts and ensure proper functionality during installation checks.
This commit is contained in:
Leonid Pershin
2026-08-21 11:27:06 +03:00
parent 241ada62cb
commit fc60fef279
3 changed files with 204 additions and 2 deletions
@@ -641,6 +641,42 @@ def settings_is_installed() -> bool | None:
return None
def ensure_settings_installed_flag() -> bool:
"""Write IsInstalled:true if missing — UI otherwise stays on /Install."""
SETTINGS.parent.mkdir(parents=True, exist_ok=True)
stamp = time.strftime("%Y-%m-%d")
if not SETTINGS.is_file():
SETTINGS.write_text(
"IsInstalled: true\n"
f"InstallDate: {stamp}\n"
"InstallVersion: gpu-rent\n"
"DefaultUser:\n"
" Theme: modern_dark\n",
encoding="utf-8",
)
print("created Settings.fds with IsInstalled=true", flush=True)
return True
try:
text = SETTINGS.read_text(encoding="utf-8", errors="replace")
except OSError as exc:
print(f"WARN Settings read: {exc}", flush=True)
return False
if re.search(r"(?im)^\s*IsInstalled:\s*true\s*$", text):
return False
if re.search(r"(?im)^\s*IsInstalled:\s*", text):
text = re.sub(r"(?im)^(\s*IsInstalled:\s*).*$", r"\1true", text, count=1)
else:
text = (
"IsInstalled: true\n"
f"InstallDate: {stamp}\n"
"InstallVersion: gpu-rent\n"
+ text
)
SETTINGS.write_text(text, encoding="utf-8")
print("patched Settings.fds IsInstalled=true", flush=True)
return True
def comfy_venv_ok() -> bool:
return COMFY_VENV.is_file() and os.access(COMFY_VENV, os.X_OK)
@@ -889,17 +925,26 @@ def main() -> int:
run_diagnostics()
return 1
if bstat in ("running", "idle", "loading", "some_loading") and comfy_venv_ok():
if ensure_settings_installed_flag():
print("IsInstalled was missing — restart swarmui to leave /Install", flush=True)
restart_swarmui_local()
print(f"recovered to {bstat} — skip InstallConfirmWS")
return 0
# Backends already registered (healthy / loading / suspended) + venv → skip.
if bstat == "idle":
if ensure_settings_installed_flag():
print("IsInstalled was missing — restart swarmui to leave /Install", flush=True)
restart_swarmui_local()
print("backends present (idle/suspended) + skip install")
return 0
# disabled = empty StartScript / not usable — must recover, not skip.
need_recover = bstat in ("empty", "disabled", "all_disabled", "unknown")
if not need_recover and bstat != "errored" and not bstat.startswith("error:"):
if comfy_venv_ok():
if ensure_settings_installed_flag():
print("IsInstalled was missing — restart swarmui to leave /Install", flush=True)
restart_swarmui_local()
print(f"backends present ({bstat}) + venv — skip install")
return 0