feat(update): download app updates in the background
This commit is contained in:
1 parent
d79d357924
commit
8be503bf40
18 files changed
+448
-171
No files matched your search
@@ -1,28 +1,10 @@
|
||||
import { shouldBlockAppUpdate } from "@/lib/app/appUpdateTaskGuard";
|
||||
|
||||
export type UpdateDownloadFlowResult = "blocked" | "downloaded" | "installed";
|
||||
|
||||
interface UpdateDownloadFlowOptions {
|
||||
getActiveTaskCount: () => number;
|
||||
download: () => Promise<void>;
|
||||
install: () => Promise<void>;
|
||||
}
|
||||
|
||||
interface DownloadedUpdateInstallOptions {
|
||||
getActiveTaskCount: () => number;
|
||||
install: () => Promise<void>;
|
||||
}
|
||||
|
||||
export async function downloadAndInstallUpdateWhenIdle(options: UpdateDownloadFlowOptions): Promise<UpdateDownloadFlowResult> {
|
||||
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<boolean> {
|
||||
if (shouldBlockAppUpdate(options.getActiveTaskCount())) return false;
|
||||
|
||||
|
||||
Reference in new issue
Block a user