Skip to content

Commit

Permalink
feat(jrt): make JRT installer cancellable
Browse files Browse the repository at this point in the history
  • Loading branch information
skjsjhb committed Jan 18, 2025
1 parent ddbbf61 commit 0febf18
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/jrt/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ type FileHint = {

type NamedFileHint = FileHint & { name: string; }

async function installRuntime(component: string, onProgress: ProgressHandler): Promise<void> {
interface JRTInstallInit {
onProgress?: ProgressHandler;
abortSignal?: AbortSignal;
}

async function installRuntime(component: string, init?: JRTInstallInit): Promise<void> {
const root = getInstallPath(component);

console.log(`Installing JRT runtime ${component} to ${root}`);
Expand All @@ -101,6 +106,8 @@ async function installRuntime(component: string, onProgress: ProgressHandler): P
let files = Object.entries(dat.files)
.map(([name, file]) => ({ name, ...(file as FileHint) } as NamedFileHint));

init?.abortSignal?.throwIfAborted();

if (conf().jrt.filterDocs) {
const prefix = getOSName() === "osx" ? "jre.bundle/Contents/Home/legal/" : "legal/";
files = files.filter(f => !f.name.startsWith(prefix));
Expand All @@ -120,7 +127,10 @@ async function installRuntime(component: string, onProgress: ProgressHandler): P
}

console.debug("Fetching files...");
await dlx.getAll(tasks, p => onProgress({ ...p, state: "jrt.download" }));
await dlx.getAll(tasks, {
onProgress: p => init?.onProgress?.({ ...p, state: "jrt.download" }),
abortSignal: init?.abortSignal
});

console.debug("Unpacking files...");
await lzma.init();
Expand All @@ -135,9 +145,11 @@ async function installRuntime(component: string, onProgress: ProgressHandler): P
await lzma.inflate(src, dst);
await fs.remove(src);
}),
p => onProgress({ ...p, state: "jrt.unpack" })
p => init?.onProgress?.({ ...p, state: "jrt.unpack" })
));

init?.abortSignal?.throwIfAborted();

console.debug("Linking files...");
// Linking can be done very fast so no progress will be reported
await Promise.all(
Expand All @@ -164,9 +176,11 @@ async function installRuntime(component: string, onProgress: ProgressHandler): P
);
}

init?.abortSignal?.throwIfAborted();

console.debug("Verifying installation...");

onProgress({
init?.onProgress?.({
state: "jrt.verify",
type: "indefinite",
value: {
Expand Down

0 comments on commit 0febf18

Please sign in to comment.