import { shouldBlockAppUpdate } from "@/lib/app/appUpdateTaskGuard"; export type UpdateDownloadFlowResult = "blocked" | "downloaded" | "installed"; interface UpdateDownloadFlowOptions { getActiveTaskCount: () => number; download: () => Promise; install: () => Promise; } interface DownloadedUpdateInstallOptions { getActiveTaskCount: () => number; install: () => Promise; } export async function downloadAndInstallUpdateWhenIdle(options: UpdateDownloadFlowOptions): Promise { if (shouldBlockAppUpdate(options.getActiveTaskCount())) return "blocked"; await options.download(); if (shouldBlockAppUpdate(options.getActiveTaskCount())) return "downloaded"; await options.install(); return "installed"; } export async function installDownloadedUpdateWhenIdle(options: DownloadedUpdateInstallOptions): Promise { if (shouldBlockAppUpdate(options.getActiveTaskCount())) return false; await options.install(); return true; }